Hello Guest

LWJGL 3 and Swing

  • 7 Replies
  • 128 Views
LWJGL 3 and Swing
« on: November 28, 2019, 11:36:23 »
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.
« Last Edit: December 06, 2019, 05:41:25 by Aisaaax »

*

Offline KaiHH

  • ****
  • 217
Re: LWJGL 3 and Swing
« Reply #1 on: November 28, 2019, 12:11:05 »
https://github.com/LWJGLX/lwjgl3-awt
(no Mac support though at the moment)

Re: LWJGL 3 and Swing
« Reply #2 on: November 29, 2019, 03:44:20 »
Thanks! Does it support ARM?

Re: LWJGL 3 and Swing
« Reply #3 on: December 02, 2019, 04:42:33 »
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.

Re: LWJGL 3 and Swing
« Reply #4 on: December 02, 2019, 09:55:26 »
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.
« Last Edit: December 03, 2019, 11:08:07 by Aisaaax »

*

Offline spasi

  • *****
  • 2169
    • WebHotelier
Re: LWJGL 3 and Swing
« Reply #5 on: December 04, 2019, 16:50:30 »
OpenGL ES usually requires a context created via EGL, not GLX. Not sure if lwjgl3-awt supports that.

Re: LWJGL 3 and Swing
« Reply #6 on: December 06, 2019, 05:40:33 »
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.

*

Offline spasi

  • *****
  • 2169
    • WebHotelier
Re: LWJGL 3 and Swing
« Reply #7 on: December 06, 2019, 11:50:58 »
Good job. It would be nice if you could contribute a patch for this to lwjgl3-awt.