LWJGL3 + JavaFX on OSX

Started by peterdr, August 10, 2015, 08:51:26

Previous topic - Next topic



I would like to do offscreen rendering using LWJGL3 and use the resulting image in JavaFX. If I understand correctly, offscreen rendering in LWJGL3 is accomplished by creating a hidden window, and using its context. For initializing LWJGL3 on OSX the -XstartOnFirstThread VM argument is needed. This VM argument, however, breaks JavaFX Applications.
I've looked at https://github.com/Spasi/LWJGL-FX. Here, Pbuffer objects are used, which are no longer part of LWJGL3.
Is there another way to achieve this, without needing the -XstartOnFirstThread?

Thanks in advance for any help!

Kind regards


Hey peterdr,

I have made an attempt to fix this, please try build 3.0.0b #13 when it's up. I moved the first thread check from glfwInit to glfwShowWindow and glfwPoll/WaitEvents. This means you can initialize GLFW and create an offscreen window/context, without the -XstartOnFirstThread argument. Do not call the methods mentioned (obviously you cannot use any callback either) and it should work.

Important: AWT/JavaFX must be initialized before GLFW and GLFW must be terminated before AWT/JavaFX for this to work without issues. This should be easy to handle.

Let me know if you encounter any crashes or any other issue.


Hi Spasi,

This solves the issue, thank you very much!!

If JavaFX was initialized everything goes as expected. However, if JavaFX was not initialized, it causes the VM to crash when calling glfwCreateWindow:
+[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread..


Yes, that's expected. It's part of the reason why GLFW cannot be used without -XstartOnFirstThread on OS X.

I'm glad it's working for you. One thing I forgot to mention is that LWJGL 3 has bindings to WGL/GLX/CGL pbuffer functionality. But it doesn't have a cross-platform wrapper, like in LWJGL 2, to discourage pbuffer usage.


Ok, and thank you for the quick and helpful replies, it really makes a difference!
Will the changes you made regarding this topic be maintained in later releases?


Yes, offscreen rendering must be easy to do on all 3 platforms.