Mixing LWJGL and AWT JPanel

Hi guys,

i know this is a problem that got often posted quite some time. But still i cant seem to find the right solution.
The problem is i want to integrate the LWJGL field as a JPanel in an already huge Java Framework.

Following example code works well if i integrate it in a JFrame like described here: http://env3d.org/beta/node/44
But when i want to add the created Canvas to an JPanel, which will be integrated in the existing framework
the program crashes all the time.

org.lwjgl.LWJGLException: X Error - disp: 0x7f112c026aa0 serial: 41 error: BadValue (integer parameter out of range for operation) request_code: 1 minor_code: 0
at org.lwjgl.opengl.LinuxDisplay.globalErrorHandler(LinuxDisplay.java:321)
at org.lwjgl.opengl.LinuxDisplay.nCreateWindow(Native Method)
at org.lwjgl.opengl.LinuxDisplay.createWindow(LinuxDisplay.java:487)
at org.lwjgl.opengl.Display.createWindow(Display.java:306)
at org.lwjgl.opengl.Display.create(Display.java:848)
at org.lwjgl.opengl.Display.create(Display.java:757)
at org.lwjgl.opengl.Display.create(Display.java:739)

Thanks guys.

regards
Mark

You’ll have much better luck if you post some example code that demonstrates the problem in the form of an MCVE.

In the past with LWJGL 2 I used the org.lwjgl.opengl.AWTGLCanvas for integrating OpenGL into AWT/Swing. It’s not pretty, but it worked. Have you tried that?
It seems you are using the Display class. Try the AWTGLCanvas. It is an implementation of java.awt.Canvas.

First of all Thanks guys, using AWTGLCanvas did the trick.
In the meantime i managed it to get it working with JOGL aswell using the GLJPanel.

Now im wondering which Library I should use, LWJGL or JOGL.
What are the advantages of using LWJGL rather than JOGL ?

Basically what i want to achieve is a simulation like in the picture shown below:

Thanks a lot.

You could use LWJGL in a native window and use a gui library like TWL.

What has your research shown you? Have you tried creating a little example project in both so you can understand the differences?

That might sound flippant, but the advantages and disadvantages are really up to you: what your personal preferences are, what you’ve coded in before, how “close to the metal” you want to be, etc. We can’t tell you which to use, just like we can’t tell you what to eat for dinner. (mashed potatoes)

In a broad sense, JOGL is a Java wrapper of OpenGL. It provides a pretty one-to-one mapping from Java functions to the underlying native functions. If you want to program in “pure” OpenGL, then this is as close as you’re going to get. LWJGL also contains a Java wrapper of OpenGL, but it also provides a bunch of other features specific for game development. It’s a little “higher level” than JOGL.

You might also consider libGDX, which is built on top of LWJGL and contains even more features for game development- including the ability to export as JavaScript or as a mobile app, the usefulness of which cannot be understated.

Having used both, as you say, you should have come to the following comparison:

LWJGL 3:

  • bindings for OpenGL/OpenAL/OpenCL
  • recently added binding for stb

JOGL:

  • JOGL is the name of the OpenGL binding
  • but there is JOCL for OpenCL and JOAL for OpenAL, too
  • features some small math library utilities, which LWJGL 3 does not have
  • supports natives for ARM architecture
  • support for Android and Solaris OS’es
  • dedicated OpenGL ES support
  • supports binding to the OpenGL Utility Library (GLU), which LWJGL 3 has not
  • has more higher-level abstractions for APIs such as the Nvidias Cg “C for Graphics” shading language
  • has support for AWT and SWT window toolkits (which LWJGL 3 has not)
  • also provides a custom GLFW (so to say) implementation, named “NEWT”

Both now have Oculus Rift support.

All in all JOGL (jogamp) is more fully-featured than LWJGL 3, but somehow feels more heavyweight in use.

Interesting. This is basically the opposite of what I normally hear. The holy wars continue, I suppose…

Don’t take me wrong: I like LWJGL for its simplicity and purity and prefer it for these reasons over JOGL. But I tried to layout the facts still above. That wasn’t meant as a flame/holy war. :wink:

Thanks a lot for the replies.
For now I have implemented some minimal examples for both JOGL and LWJGL

The Picture below shows the Framework on which i am working. the green Field in the middle is the
(in this screenshot) by JOGL rendered Panel.

I must say that implementing the minimal example was much easier ( at least for me ) by using JOGL.
And for now i think im going to stay with JOGL. Thanks guys for clearing up some things.

Which canvas do you use? There are several canvases in JOGL working with AWT and Swing:

  • AWT GLCanvas (heavyweight, very stable, fast, very reliable except in a few corner cases for example with JInternalFrame)
  • NewtCanvasAWT (the fastest option as long as you’re forced to use AWT/Swing, less reliable, not usable with OpenJFX/JavaFX)
  • GLJPanel (lightweight, stable, less fast because of its use of FBOs under the hood, reliable especially with JInternalFrame and non opaque Swing components, usable with SwingNode -> OpenJFX/JavaFX)

There is a JogAmp backend for this framework and we recently succeeded in making it work with OpenJFX/JavaFX too. The last part of your sentence is plain wrong, LibGDX has had several backends for several years, including another one based on GWT for example, it’s not built on top any particular set of bindings.

Good luck.