LWJGL 3 and Swing

Started by Aisaaax, November 28, 2019, 11:36:23

Previous topic - Next topic

Aisaaax

Hello.
First, I apologize as I realize this question must be asked a lot.

In fact, I've been searching half a day today to find out how to integrate LWJGL 3 and display my scene in JFrame or Canvas... and I'm still not having a definite answer.

I found A BUNCH of threads, including from this forum that say that Swing isn't supported. Unfortunately they are mostly from 2015-2016, and I have no clue if the support was added after. At some point it seemed to be part of the plan, but I can't find the information.

I also found a bunch of threads here and on StackOverflow where people link to answers and possible solutions, but those links are also old and dead.

The closest thing to a solution I found - Is read FrameBugger from GLFW window, convert it into rasterized image and display on Canvas. But this seems to be such an inelegant solution, not to mention performance and other issues.

So I ask nice people here to please explain this to me if, and if so - how this can be done?

Thank you in advance.

Edit:
After much trial and error, I managed to come up with the solution that I posted in this thread on StackOverflow.
https://stackoverflow.com/questions/59174586/opengl-and-awt-swing-user-interface/59206923#59206923

In case anyone ever needs to make LWJGL + EGL/GLES and AWT to work.

KaiHH


Aisaaax

Thanks! Does it support ARM?

Aisaaax

Ok, I think I need help with this library.

How can I run it with OpenGL-ES instead of OpenGL? In fact, I don't have OGL libraries at all in my project - only OpenGL-ES.

Aisaaax

I've managed to get it to work on PC, under Linux where it defaults to OpenGL.
But on ARM, it just fails on the JNI call for glxChooseFBConfig. I checked and everything seems to be working up to that point - handlers are created and the attribute list is passed normally.
The thing is that it's a JNI function, so I can't really get inside of it and determine what failed. The application just gives me a "App closed with 1 exit code" error and a stack trace that leads to glxChooseFBConfig and it's subsequent JNI call.

Edit:
I managed to get it to pass glxChooseFBConfig by calling glxQueryVersion() right before it. I don't know WHY it works with that line of code but doesn't without it - probably QueryVersion initializes something internally.

But then I'm constantly getting nullPointerException inside of GLES code, when your library tries to create capabilities. And I have no idea why, because it throws the exception from a completely separate place in the code. It just jumps down some 40 lines of code to a "Catch" statement that doesn't even belong to the block of code that I am stepping through. And the line that throws the exception is "if (errorCode == 0)", which makes zero sense.

When I switch to OpenGL - everything works. But I can't get it to work with GLES.

spasi

OpenGL ES usually requires a context created via EGL, not GLX. Not sure if lwjgl3-awt supports that.

Aisaaax

Hello!
After much trial and error, I managed to come up with the solution that I posted in this thread on StackOverflow.
https://stackoverflow.com/questions/59174586/opengl-and-awt-swing-user-interface/59206923#59206923

In case anyone ever needs to make LWJGL + EGL/GLES and AWT to work.

spasi

Good job. It would be nice if you could contribute a patch for this to lwjgl3-awt.