How to embed LWJGL in Swing/AWT Window?

Started by honeybadger, July 29, 2010, 10:10:11

Previous topic - Next topic

honeybadger

Hi,

Does anyone have a basic template (i.e. code) for how to embed an LWJGL display in a Swing/AWT window?
I'm creating a game and would like to embed a LWJGL display in such a canvas so I can use buttons and sliders, etc.

Also, is it possible to use Swing/AWT based sounds in conjunction with LWJGL-based OpenAL sounds?

I'm using NetBeans, btw.

Thanks for helping this little newbie!
:D

Matthias

You can take a look at the TWL Theme editor code: http://hg.l33tlabs.org/twlthemeeditor/file/tip/src/de/matthiasmann/twlthemeeditor/Main.java it uses an AWT frame to create a resizable GL display.

But mixing AWT/Swing UI elements with OpenGL is not so nice - better to use a 100% OpenGL UI like TWL.

quasar

Haha Matthias, promoting TWL wherever you can :P

But seriously, honeybadger, TWL is seriously awesome. :)

honeybadger

Thanks Matthias! I checked out TWL... looked impressive. I'll definitely give it go some time (when I'm a bit better more experienced).

Right now I'm just looking for a pure LWJGL + AWT/Swing implementation. Would you by any chance have such a template?

PS: I tried downloading the "Main.java" link you posted, but I couldn't get it to work on Netbeans as it came up as an HTML file?
Any hints on how I can try out the code quickly on Netbeans? Cheers!

Evil-Devil

Have you tried the AWT Gears demo so far?

honeybadger

What's AWT Gears? Is that the one using JOGL? Do you have the URL?

Would prefer one with LWJGL though.

Cheers!  ;)

Evil-Devil

Just in the regular lwjgl archive. Inside the test package you will fonde some awt tests. For the java source you may download the lwjgl source package which contains all the code you will need.

Matthias

Quote from: honeybadger on July 30, 2010, 10:42:11
Right now I'm just looking for a pure LWJGL + AWT/Swing implementation. Would you by any chance have such a template?

PS: I tried downloading the "Main.java" link you posted, but I couldn't get it to work on Netbeans as it came up as an HTML file?
Any hints on how I can try out the code quickly on Netbeans? Cheers!
I linked you a Java source which uses Display.setParent() to get a OpenGL context in a AWT Frame. If this is not enough example for you then you are out of luck.
As this source is stored in Mercurial you can either use the "raw" link, or just clone the complete repository. But you won't be able to compile/run that class alone.

honeybadger

Thanks for the link, Matthias. I'll spend some time to go thru your code and try to understand it. I'm new to LWJGL, as you can see  ;)

Cheers for your time and patience! Greatly apppreciate it!

Krux

lets revive this topic. I've seen the AWT classes, and they are cool, but is it also possible to use swing, and not AWT?

Fool Running

Quote from: Krux on May 23, 2012, 23:13:42
...is it also possible to use swing, and not AWT?
Yes and no. Yes you can use LWJGL in Swing, but since Swing uses light-weight components, the LWJGL view will appear on top of any Swing components (like a menu that drops down over top of a LWJGL view will not show up).
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D