LWJGL Forum

Programming => General Java Game Development => Topic started by: honeybadger on July 29, 2010, 10:10:11

Title: How to embed LWJGL in Swing/AWT Window?
Post by: honeybadger on July 29, 2010, 10:10:11
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
Title: Re: How to embed LWJGL in Swing/AWT Window?
Post by: Matthias on July 29, 2010, 21:31:07
You can take a look at the TWL Theme editor code: http://hg.l33tlabs.org/twlthemeeditor/file/tip/src/de/matthiasmann/twlthemeeditor/Main.java (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 (http://twl.l33tlabs.org/).
Title: Re: How to embed LWJGL in Swing/AWT Window?
Post by: quasar on July 29, 2010, 21:41:12
Haha Matthias, promoting TWL wherever you can :P

But seriously, honeybadger, TWL is seriously awesome. :)
Title: Re: How to embed LWJGL in Swing/AWT Window?
Post by: honeybadger on July 30, 2010, 10:42:11
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!
Title: Re: How to embed LWJGL in Swing/AWT Window?
Post by: Evil-Devil on July 30, 2010, 11:51:27
Have you tried the AWT Gears demo so far?
Title: Re: How to embed LWJGL in Swing/AWT Window?
Post by: honeybadger on July 30, 2010, 12:06:12
What's AWT Gears? Is that the one using JOGL? Do you have the URL?

Would prefer one with LWJGL though.

Cheers!  ;)
Title: Re: How to embed LWJGL in Swing/AWT Window?
Post by: Evil-Devil on July 30, 2010, 16:49:32
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.
Title: Re: How to embed LWJGL in Swing/AWT Window?
Post by: Matthias on July 30, 2010, 16:59:59
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.
Title: Re: How to embed LWJGL in Swing/AWT Window?
Post by: honeybadger on August 03, 2010, 15:31:56
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!
Title: Re: How to embed LWJGL in Swing/AWT Window?
Post by: Krux on May 23, 2012, 23:13:42
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?
Title: Re: How to embed LWJGL in Swing/AWT Window?
Post by: Fool Running on May 24, 2012, 13:00:16
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).