GLFW Wayland

Started by alduin, November 04, 2015, 00:26:22

Previous topic - Next topic

alduin

Hi, everyone!

I'd like to enable Wayland support in GLFW. In "pure" GLFW I can enabled it with the "-DGLFW_USE_WAYLAND=ON" CMake option, how can I do this in LWJGL build?

kappa

I'd assume the process is the same, just build GLFW as you would with the "-DGLFW_USE_WAYLAND=ON" CMake option and replace LWJGL's GLFW native (libglfw.so) with the one you built.

spasi

You can try kappa's suggestion but keep in mind that both Wayland and Mir backends in GLFW are incomplete.

alduin

Quote from: kappa on November 04, 2015, 08:10:08
I'd assume the process is the same, just build GLFW as you would with the "-DGLFW_USE_WAYLAND=ON" CMake option and replace LWJGL's GLFW native (libglfw.so) with the one you built.
I tried to do this but I got exception:
java.lang.ExceptionInInitializerError
	at org.lwjgl.glfw.GLFW.getInstance(GLFW.java:589)
	at org.lwjgl.glfw.GLFW.glfwSetErrorCallback(GLFW.java:745)
Caused by: java.lang.IllegalStateException: This function is not available.
	at org.lwjgl.system.Checks.checkFunctionAddress(Checks.java:66)
	at org.lwjgl.glfw.GLFW.<init>(GLFW.java:528)
	at org.lwjgl.glfw.LibGLFW.<clinit>(LibGLFW.java:37)
	... 10 more
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.lwjgl.glfw.LibGLFW
	at org.lwjgl.glfw.GLFW.getInstance(GLFW.java:589)
	at org.lwjgl.glfw.GLFW.glfwTerminate(GLFW.java:636)

spasi

You must build GLFW's master branch, which already includes new APIs for the next release (3.2).

alduin

Quote from: spasi on November 04, 2015, 11:39:22
You must build GLFW's master branch, which already includes new APIs for the next release (3.2).
I built the master branch but I got exception again
java.lang.ExceptionInInitializerError
	at org.lwjgl.glfw.GLFW.getInstance(GLFW.java:589)
	at org.lwjgl.glfw.GLFW.glfwSetErrorCallback(GLFW.java:745)
Caused by: java.lang.IllegalStateException: This function is not available.
	at org.lwjgl.system.Checks.checkFunctionAddress(Checks.java:66)
	at org.lwjgl.glfw.GLFWNativeX11.<init>(GLFWNativeX11.java:32)
	at org.lwjgl.glfw.LibGLFW.<clinit>(LibGLFW.java:41)
	... 10 more
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.lwjgl.glfw.LibGLFW
	at org.lwjgl.glfw.GLFW.getInstance(GLFW.java:589)
	at org.lwjgl.glfw.GLFW.glfwTerminate(GLFW.java:636)

spasi

I've pushed a fix for this, please try build 3.0.0b #56.

alduin

Quote from: spasi on November 04, 2015, 14:27:39
I've pushed a fix for this, please try build 3.0.0b #56.
On my code it crashed. I also tried to run ShadowMappingDemo(without glfwSetWindowPos) and it crashed too with the same SIGSEGV. I checked the glfw build on the same environment in C everything work.

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f54c59cc820, pid=24437, tid=140004062471936
#
# JRE version: Java(TM) SE Runtime Environment (8.0_60-b27) (build 1.8.0_60-b27)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.60-b23 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [libX11.so.6+0x3a820]  XQueryExtension+0x50
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /.../hs_err_pid24437.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

spasi

You're trying to use OpenGL with Wayland. That's not currently possible AFAIK. See the Wayland FAQ, under "Why does Wayland use EGL and GLES2?" for details. GLFW also uses EGL automatically when you enable the Wayland/Mir backends.

alduin

Quote from: spasi on November 04, 2015, 17:52:02
You're trying to use OpenGL with Wayland. That's not currently possible AFAIK. See the Wayland FAQ, under "Why does Wayland use EGL and GLES2?" for details. GLFW also uses EGL automatically when you enable the Wayland/Mir backends.
Maybe there is an example of using GLES with LWJGL?

spasi

It's mostly the same as normal OpenGL, except there's no fixed function rendering, you must use VBOs, VAOs, shaders, etc.

As for LWJGL, the only important thing you must do is use the GLES class instead of GL when setting up the rendering context:

// ...
glfwMakeContextCurrent(window);
GLES.createCapabilities();

alduin

Quote from: spasi on November 04, 2015, 21:45:52
As for LWJGL, the only important thing you must do is use the GLES class instead of GL when setting up the rendering context:
Thanks a lot, I missed this in the first time. And now I got another exception ;D
Caused by: java.lang.RuntimeException: Failed to dynamically load library: libGLESv2.so(error = null)
	at org.lwjgl.system.linux.LinuxLibrary.<init>(LinuxLibrary.java:23)
	at org.lwjgl.system.APIUtil.apiCreateLibrary(APIUtil.java:56)
	at org.lwjgl.LWJGLUtil.loadLibraryNative(LWJGLUtil.java:215)
	at org.lwjgl.opengles.GLES.create(GLES.java:95)
	at org.lwjgl.opengles.GLES.create(GLES.java:86)
	at org.lwjgl.opengles.GLES.<clinit>(GLES.java:65)
	... 3 more

spasi

Could you check if your system has libGLESv2.so or libGLESv2.so.2 please?

alduin

Quote from: spasi on November 04, 2015, 22:15:41
Could you check if your system has libGLESv2.so or libGLESv2.so.2 please?
Of course,
/usr/lib64/libGLESv2.so.2
/usr/lib64/libGLESv2.so.2.0.0

spasi

Does it work if you launch the JVM with:

-Dorg.lwjgl.opengles.libname=libGLESv2.so.2


You can also do it programmatically with:

Configuration.LIBRARY_NAME_OPENGLES.set("libGLESv2.so.2");