Using lwjgl3 window and SWT shell simultaneously

Started by arisona, February 19, 2016, 16:12:29

Previous topic - Next topic

arisona

Hi All

I have an app using JOGL and Swing but would like to move to LWJGL & SWT for a number of reasons.

The app basically uses "plain" OpenGL windows (for rendering) and separate GUI windows for GUI elements, i.e. no combination such as doing OpenGL rendering within the GUI window.

Now: Is it possible to have an LWJGL window and an SWT shell simultaneously, e.g. in terms of event handling etc.? Or, otherwise, once I decide to use SWT shells, I need to use SWT's GLCanvas and cannot use "native" LWJGL windows anymore?

Thanks for advice!
:)
/Stefan

Kai

You can use a GLFW window and a SWT shell side by side. No problem, because both use user-controlled explicit window message processing and don't do that internally in some kind of UI thread (gladly).
See this demo for an example: https://github.com/LWJGL/lwjgl3-demos/blob/master/src/org/lwjgl/demo/opengl/swt/SwtAndGlfwDemo.java
You can also use SWT's GLCanvas.

But beware that, should you decide to use a single thread to render to both windows, you must explicitly make each GL context current for each window.
Should you choose to render and swapbuffer in separate threads, which is perfectly good, then window message processing using SWT's Display.readAndDispatch() and GLFW's glfwPollEvents()/glfwWaitEvents() should still always happen only on the main thread.

arisona

Awesome, that's exactly what I needed to know. Thank you!

Kai

You are welcome! Happy coding with LWJGL and SWT. :)

Just one note about SWT and GLFW interaction: Calling both SWT's Display.readAndDispatch() and GLFW's glfwPollEvents(), like the demo did until now, does not work, because GLFW's glfwPollEvents() could swallow the window events for SWT. This is because processing OS window messages is application-wide and not per window or window toolkit and specifically because GLFW's glfwPollEvents() cannot call back into Java SWT event listeners, however SWT's method will also take care of GLFW handling its window messages appropriately.

So, you must actually use SWT's Display.readAndDispatch() only.

arisona

Just some feedback on this older thread. Everything worked out smoothly. Our framework is here https://github.com/arisona/ether in case someone's interested. We completed transition from JOGL/AWT to lwjgl (and some minimal SWT). Probably still a bit shaky, but happy we got rid of the beast.

Cheers again for the suggestions.