OpenGL (lwjgl) with JavaFX sharing same context
Hall Hank
hall0330 at hotmail.com
Wed May 6 10:53:26 UTC 2020
Hi everyone.
I'm pretty new to this mailing list so, i hope i write my email as you expect.
I'm working on integration between OpenGL and JavaFX, and i was not really satisfied by the different library that i found on the internet. That is why, i started my own implementation by extending NGRegion (yes, it's private ).
Here is my idea :
In the NGRegion, we are able to manage the OpenGL context created by JavaFX.
With LWJGL, it's then pretty easy to start to draw everything we want, by sharing this context. The only thing that we MUST be careful is the opengl context state. We must first save the states, draw what we want, and then restore the previous states.
In this way, JavaFX don't really know that we drew something with his own context.
This implementation is approximately the same approcah as FXGL, but without GLFW and hidden window and without creating a new OpenGL context.
I created a really small simple exemple that i would share with you. It's not production ready because i saved only the minimal states but this works really well for the hello world.
In this example, i just draw a green square, just by clearing the color. (no use of glDraw here, but of course it's possible)
I also did some advanced things with this approach, but saving/restoring a lot of states in some advanced JavaFX layout, and really it works great with very good performance.
You will find my little Main.java with few line of code to illustrate the principe. If you want to launch this example you just need the lwjgl dependencies that you can download from their website.
This example use Java 8, because i used to use it and i didn't want to have some problem due to Java 9 modules.
Now, my question is : would it be possible to include something like this in openjfx if we make it production ready ?
The interop between JavaFX & OpenGL is a recurrent question, and i think that it would be great to have a really easy solution like this directly in JavaFX.
I'm really interested about your feelings.
Thank you for reading.
Best regards.
Hank.
More information about the openjfx-dev
mailing list