Hello Guest

LWJGL3 + JavaFX on OSX

  • 5 Replies
  • 8783 Views
LWJGL3 + JavaFX on OSX
« on: August 10, 2015, 08:51:26 »
Hi,

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

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Re: LWJGL3 + JavaFX on OSX
« Reply #1 on: August 10, 2015, 11:48:43 »
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.

Re: LWJGL3 + JavaFX on OSX
« Reply #2 on: August 10, 2015, 16:29:05 »
Hi Spasi,

This solves the issue, thank you very much!!

PS:
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..

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Re: LWJGL3 + JavaFX on OSX
« Reply #3 on: August 10, 2015, 21:09:42 »
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.

Re: LWJGL3 + JavaFX on OSX
« Reply #4 on: August 11, 2015, 06:39:15 »
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?

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Re: LWJGL3 + JavaFX on OSX
« Reply #5 on: August 11, 2015, 06:53:12 »
Yes, offscreen rendering must be easy to do on all 3 platforms.