LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: BatKid on November 12, 2007, 19:00:44

Title: Simple way to convert lwjgl app to using swing
Post by: BatKid on November 12, 2007, 19:00:44
Hi all,

I am the author of an educational 3d engine (env3d.sourceforge.net (http://env3d.sourceforge.net)).  It is using lwjgl's Display class for the main game window. 

My question is, is there a simple way to convert this to use swing?  I know that I could use the AWTGLCanvas (sp?) for display, but it seems like the two approaches are not very compatible and converting between them would require a major change in code structure.  Am I correct in this case?  I hope I am wrong because I would like to do minimal work on this ;)

Thanks
Title: Re: Simple way to convert lwjgl app to using swing
Post by: Matzon on November 13, 2007, 19:42:43
afaik, the AWTGLCanvas works fine, barring any heavyweight issues.
if you absolutely must use swing only components, then JOGL (http://jogl.dev.java.net) is probably the way to go
Title: Re: Simple way to convert lwjgl app to using swing
Post by: princec on November 14, 2007, 12:35:29
Kev Glass recently showed me a demo of Swing rendered into a LWJGL window at 60fps - basically Swing was being active rendered into a texture and then the whole thing was blitted every frame and it worked fantastically well, with ClearType fonts and everything. All the event handling was trapped and sent to Swing too. I was seriously impressed. Hopefully he will tidy it up and release the hackery as a library that Just Works.

Cas :)
Title: Re: Simple way to convert lwjgl app to using swing
Post by: Evil-Devil on November 14, 2007, 12:51:39
Using the AWTGLCanvas in a Swing only application is no problem. Just make sure that every component that have to be rendered on top of the glcanvas is set heavyweight.
Title: Re: Simple way to convert lwjgl app to using swing
Post by: kevglass on November 14, 2007, 18:51:06
This stuff uses the same ideas as JMEDesktop (and Xith3D, and Yazel before that). Swing is added to an invisible frame and then rendered into a buffered image. This is then updated into the texture which can then be rendered across the screen.

I've recoded this from scratch but it certainly owes so kudos to JMEDesktop, which was used as reference. This time the AWT event interaction has been simplified, as has dirty rectangle tracking. Also performance was improved by using an texture format equivalent to the BufferedImage underlying storage - this makes grabbing the contents of the buffered image faster.

In short, here's that thing Cas was talking about, it renders Swing ... to LWJGL:

http://www.cokeandcode.com/Swingle/swingle141107.zip

Kev
Title: Re: Simple way to convert lwjgl app to using swing
Post by: Fool Running on November 17, 2007, 22:42:53
QuoteIn short, here's that thing Cas was talking about, it renders Swing ... to LWJGL:
I'm definitely going to look at that. 8)