Started by smith, May 21, 2019, 16:50:37

Previous topic - Next topic



I was wondering if there was a way yet for LWJGL + AWT/Swing to co-exist. Currently I'm using an offscreen window and glReadPixels into a BufferedImage.
It's not great performance but it does work fine on Windows at least, the problems start when you move to Linux/OSX with GLFW and AWT/Swing not playing nice.
On Linux if I try to open a JFileChooser it will crash when I close it with an X11 error.
I believe OSX has issues deadlocking but I haven't tested it as I don't have a mac.

I am only using GLFW to create the offscreen window so I'm not after any of the event handling. Is there another way to create a window that doesn't cause issues with AWT/Swing?

It is really disappointing how getting UI + OpenGL in java has been so problematic for such a long time, I guess it's just a really hard problem to solve.


That problem has little to do with java. OpenGL is not designed for UI's. There is no native support for font rendering and the way modern graphics processing works (VBO's, Shaders, etc) is in stark contrast to how GUI frameworks are traditionally build.
By the way, AWT/Swing may actually be using OpenGL in the background "under the hood" so to say. The implementation details are not strictly enforced and alternative solutions are possible. On Windows for example you can choose between either a Direct3D or OpenGL implementation. Maybe even other alternatives. So the problem is not so much in OpenGL + Java.
The real problem is finding a proper GUI framework that works well with OpenGL and is also easily integrated (or even written in) java. In my spare time I tried to developed such a framework as a hobby. It really is not easy to make good use of modern rendering techniques when building a fully functional GUI framework.

Maybe have a look at this thread: http://forum.lwjgl.org/index.php?topic=6883.msg36272

On a side note: I once worked on a project which used Qt with java and OpenGL rendering. Its not "nice" but its definitely possible.


Qt + OpenGL integration is fantastic an example of how it really should be done. I don't think OpenGL should care about UI's, the main issue is AWT/JavaFX really need a native surface widget that can be used to integrate with other libraries, not just OpenGL but Direct3D and video players etc. This has been talked about for a long time but has never made it past the discussion phase. It's really a shame because it would open up a huge space for interesting applications.

I note AWTGLCanvas doesn't support OSX, also is there any reason it isn't currently included in lwjgl?


Quote from: smith on May 21, 2019, 21:10:44
I note AWTGLCanvas doesn't support OSX, also is there any reason it isn't currently included in lwjgl?
This is a hobby project of mine, and when I started it I only cared about Windows and a little bit about Linux.
And since I do not own a Mac and no one so far contributed a working solution (though there were attempts https://github.com/LWJGLX/lwjgl3-awt/issues/1 ) Mac OS is not supported currently, sorry.
You are very welcome to contribute.