Hello Guest

LJWGL 3 (GLFW) as Javafx canvas/panel/something

  • 13 Replies
  • 16366 Views
*

Offline Lobo

  • *
  • 27
LJWGL 3 (GLFW) as Javafx canvas/panel/something
« on: November 26, 2016, 09:36:24 »
Hi,

I actually using a GLFW Window parallel to javafx panels, both are intependant.
My question is now is there a possible solution, which has not that much performance impact, to embed
a glfw window or in general lwjgl into a javafx windows. For example as canvas or panel or something.

I want to have one window mode for my application and not several floating windows.

I hope there is a possibilty to do this.

I googled a little bit about that, but doesnt found a good solution for my problem.
Found this, bit dont know if it is only with lwjgl 2.x and if there is a better solution available in lwjgl 3.1

http://www.java-gaming.org/topics/lwjgl-javafx-integration/27801/view.html

Thanks!

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Re: LJWGL 3 (GLFW) as Javafx canvas/panel/something
« Reply #1 on: November 26, 2016, 12:02:16 »
The situation has not changed, JavaFX is not friendly to 3rd party integrations (without significant overhead).

There are various hacky things you could try to avoid the perfomance hit, depending on your needs:

- Do you want the single window to be a GLFW window or a JavaFX window?
- Do you want to get JavaFX to render inside a GLFW managed context? E.g. a framebuffer object that you can later composite with the rest of your rendering.
- Do you want to render inside a JavaFX panel? Does it have to be lightweight or heavyweight?
- Do you need to support macOS?

Based on the replies to the above, the solution may range from "very difficult" to "impossible".

*

Offline Lobo

  • *
  • 27
Re: LJWGL 3 (GLFW) as Javafx canvas/panel/something
« Reply #2 on: November 26, 2016, 12:44:47 »
Hi,

thanks for the answers. Sad to read that is is always hacky and not nice to implement :-(

To your points:
- I dont have any preferences if it is a glfw window or javafx window, the easiest solution would be ok.
I dont want to add javafx components over the glfw render convas. Just want to have panels next to the renderframe
in one window thats all.

- No it is not necessary to render fx components in the same context, they can be intependant.

- Would be nice if it is possible to do this but it must not be a fx panel. As wrote in point 1 I just want to have one
window application with a render something in the center and left and/or right some fx components for properties stuff.
Like the screenshot in that thread http://www.java-gaming.org/topics/lwjgl-javafx-integration/27801/view.html but without the overlay stuff
of the render component. If it is heavy or lightweight is no important in the first step.

- No just windows support is enough.

Thanks a lot for your answer.

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Re: LJWGL 3 (GLFW) as Javafx canvas/panel/something
« Reply #3 on: November 26, 2016, 13:01:47 »
One possible solution would be to use SWT, if you combine:

JavaFX Interoperability with SWT and
lwjgl3-swt

I'm not sure what would be the performance characteristics of such a solution, but it should be easy enough to try.

Another solution would be using the OpenGL ES Prism backend on Windows. JavaFX normally uses D3D on Windows, but I have ported the GLES backend to use LWJGL3 and it works just fine. This code is not public, because the Prism backend changes often and I don't have time to maintain it. Also, I'm not sure if there are legal issues involved.

Another problem is that JavaFX details are completely abstracted away at the Prism level. This means that you don't know what JavaFX component corresponds to the thing you're rendering. There's probably a way to do it, but I haven't had the time to work on it further. If that issue was fixed, you would be able to use the JavaFX windowing system, the JavaFX event handling and the JavaFX rendering loop, while "injecting" your own rendering in one of its components (without CPU copies).

*

Offline Lobo

  • *
  • 27
Re: LJWGL 3 (GLFW) as Javafx canvas/panel/something
« Reply #4 on: November 26, 2016, 13:04:30 »
Nice thank you. I will try it out and if I'm successful I will let you know in that thread.

Thanks a lot and have a nice weekend.

*

Offline Lobo

  • *
  • 27
Re: LJWGL 3 (GLFW) as Javafx canvas/panel/something
« Reply #5 on: November 28, 2016, 17:29:12 »
Hmm tried to compile this, but where did i get the eclipse plugins for swt?
I'm using eclipse neon.1, searched into the marketplace and tried several stuff but nothing worked.

In general its really pita to make all this just for 2d and 3d in one frame. Is there no better solution for java and opengl?
For me I'm close to switch to c++, because with QT its much easier to use opengl in a nice gui.

And 2d gui components are probably not available in glfw isnt it? So it must not be javafx, but it is much nicer to implement than swing.

Afaik is next to lwjgl only jogl the only other java<->ogl solution, but I'm not sure if jogl is better and if it is still in
development.

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Re: LJWGL 3 (GLFW) as Javafx canvas/panel/something
« Reply #6 on: November 28, 2016, 18:13:17 »
Hmm tried to compile this, but where did i get the eclipse plugins for swt?
I'm using eclipse neon.1, searched into the marketplace and tried several stuff but nothing worked.

Sorry, I've never used Eclipse or SWT. Why do you need a plugin for SWT?

In general its really pita to make all this just for 2d and 3d in one frame. Is there no better solution for java and opengl?
For me I'm close to switch to c++, because with QT its much easier to use opengl in a nice gui.

And 2d gui components are probably not available in glfw isnt it? So it must not be javafx, but it is much nicer to implement than swing.

Depends on what features you need from a 2D framework. GLFW is just a windowing system + context management library, it is not comparable to Qt or JavaFX. LWJGL has other bindings for 2D graphics: NanoVG for vector graphics (Java2D-style) and Nuklear for UI components. Both can be perfectly integrated with your OpenGL rendering.

Afaik is next to lwjgl only jogl the only other java<->ogl solution, but I'm not sure if jogl is better and if it is still in
development.

The problem with Java GUI libraries has nothing to do with LWJGL or JOGL. The problem is how AWT/Swing and JavaFX are designed; they are not designed to be integrated with custom OpenGL/Direct3D rendering.

*

Kai

Re: LJWGL 3 (GLFW) as Javafx canvas/panel/something
« Reply #7 on: November 28, 2016, 18:23:22 »
... but where did i get the eclipse plugins for swt?
If you are referring to building the lwjgl3-swt repo, then that code is meant to be built with Maven.
If you do not use Maven, then just download the swt jar for your respective OS/arch here (assuming Windows x64):
https://github.com/maven-eclipse/maven-eclipse.github.io/raw/master/maven/org/eclipse/swt/org.eclipse.swt.win32.win32.x86_64/4.6.1/org.eclipse.swt.win32.win32.x86_64-4.6.1.jar

You also do not need to install any Eclipse plugin.
« Last Edit: November 28, 2016, 18:31:20 by Kai »

*

Offline Lobo

  • *
  • 27
Re: LJWGL 3 (GLFW) as Javafx canvas/panel/something
« Reply #8 on: November 28, 2016, 18:49:02 »
Thanks for your informations.

Dont know why I need a plugin, but there are many eclipse.org imports in the linked project which cannot be found.
But I will take a look at this "nuklear" gui stuff, maybe I can use it for my framework.

Thanks

*

Kai

Re: LJWGL 3 (GLFW) as Javafx canvas/panel/something
« Reply #9 on: November 28, 2016, 19:01:17 »
Dont know why I need a plugin, but there are many eclipse.org imports in the linked project which cannot be found.
You don't need any plugins. You just need to have the mentioned Eclipse SWT JAR on the classpath.
« Last Edit: November 28, 2016, 19:06:30 by Kai »

Re: LJWGL 3 (GLFW) as Javafx canvas/panel/something
« Reply #10 on: April 20, 2020, 13:22:37 »
Hello, just wondering what the latest situation is with using OpenGL within a JavaFX app?

2 ideas come to mind.

1. Is it possible to get the GL context used by JavaFX and initalise LWJGL with it and call GL from there? This uses JavaFX's scene update mechanism to trigger rendering on a control/canvas.

2. Separate rendering threads (JavaFX's own and my own). Does JavaFX allow the creation of a control driven by a separate GL thread, somewhat like what SWT GLCanvas allows?

Thanks.

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Re: LJWGL 3 (GLFW) as Javafx canvas/panel/something
« Reply #11 on: April 20, 2020, 14:55:43 »
DriftFX is the most promising and actively maintained solution atm. LWJGL has bindings for it.

*

Offline tlf30

  • **
  • 73
Re: LJWGL 3 (GLFW) as Javafx canvas/panel/something
« Reply #12 on: April 27, 2020, 17:21:32 »
Over at jMonkeyEngine we have a solution for getting JavaFX 11 running inside JME3. JME3 uses LWJGL3 GLFW.
You may want to take a look at it:https://github.com/jayfella/jme-jfx-11

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Re: LJWGL 3 (GLFW) as Javafx canvas/panel/something
« Reply #13 on: April 27, 2020, 19:16:01 »
Hey tlf30, could you provide some technical details please? How is this achieved? Does it work across all platforms?