Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (407)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Nasty design constraints when using AWTGLCanvas  (Read 2952 times)
0 Members and 1 Guest are viewing this topic.
Offline StrideColossus

Senior Member


Medals: 3
Projects: 1



« Posted 2008-08-20 17:15:29 »

I started a topic http://www.java-gaming.org/topics/jogl-design-issues/19099/view.html in the newbies forum which pointed me towards AWTGLCanvas.  Having had a play with this canvas class I've got a couple of further questions which are probably best raised in this forum:

First a little background:  I'm designing and implementing an engine that is OpenGL agnostic, i.e. it handles the generic side of a 3D application: models, texture blending, vector maths, etc.  The engine defines a set of interfaces that a specific OpenGL library implements to handle rendering, lighting, texturing, etc.  I've got two implementations, one for JOGL (largely incomplete) and another for LWJGL (largely done Smiley).

The LWJGL implementation initially used the Display class to create the window and Keyboard/Mouse to handle input.  Once I started on the JOGL version I realised that I'd been re-inventing the wheel to some extent - it would much nicer to use standard Java APIs for creating the frame and keyboard/mouse handling, which is why I ended up looking at AWTGLCanvas.

But having altered the LWJGL library to use AWTGLCanvas I've realised that it's screwing the engine architecture and I don't like it.

Like most applications, the engine sets everything up then starts a rendering loop that redraws the scene, updates the game and swaps the buffers:
- open the display
- init the application (build the scene-graph, load models, texture images, etc)
- setup input devices handlers
- rendering loop:
    1. update context (timing, etc)
    2. render scene
    3. swap buffers
    4. update game

But this approach won't work with the AWTGLCanvas.  I (perhaps naively) expected I could just leave the engine as it is and change step 3 above to invoke repaint() on the canvas.  Oh no - null-pointers all over the place.  It appears that the LWJGL context is only created in the paint() method ( Undecided!) of the canvas, and is not valid outside of that method.  Why?  You don't need to be concerned with this context notion when using the Display approach, the GL APIs are globally available.

This forces me to sub-class the canvas, put the initialisation code in initGL() and the scene code in paintGL(), or at least call back to the engine to do it.  I can understand why this is as it is, the developer followed the AWT/SWING paradigm.  It's bad design but that's the way the AWT/SWING developers decided to do things - deal with it you might say.

But I'm not giving in just yet, so:

1. Is what I've written above correct?  i.e. the GL APIs are not available outside of this loop.

2. If so, why?  It works when you use the Display approach.

3. Is there anyway I can get access to the GL APIs outside of the painting loop such that my engine remains largely as it is?  Or am I going to have to start the rendering loop and then wait for the initialisation and painting 'callbacks' from the canvas?

4. As a small aside - should I be using AWTGLCanvas and standard Java APIs for display modes, input devices, etc. in a real-world LWJGL application anyway, or should I be using the Display/Keyboard/Mouse approach?  What is the general approach used out there?

I hope this makes some sense.  Cheers in advance for any suggestions.
Offline jezek2
« Reply #1 - Posted 2008-08-20 17:32:44 »

Hi, there is also another approach introduced in LWJGL 2.0rc1. It allows to embed Display in Canvas, see the Display.setParent method, there is also example in LWJGL sources in src/org/lwjgl/test/opengl/awt/DisplayParentTest.java. It works exactly like Display including input handling Smiley The only drawback is that you can have only one Display at once.
Offline princec
« League of Dukes »

JGO Kernel


Medals: 196
Projects: 3


Eh? Who? What? ... Me?


« Reply #2 - Posted 2008-08-20 17:42:27 »

Yep, AFAIK we're deprecating AWTGLCanvas in favour of Display.setParent().

Cas Smiley

Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline StrideColossus

Senior Member


Medals: 3
Projects: 1



« Reply #3 - Posted 2008-08-20 18:13:20 »

OK that sounds a nicer approach, I'll give it a whirl.

Ta  Grin
Online EgonOlsen
« Reply #4 - Posted 2008-08-21 12:32:40 »

Yep, AFAIK we're deprecating AWTGLCanvas in favour of Display.setParent().
But the AWTGLCanvas allows for multiple instances at a time, while Display.setParent() doesn't. That's great for editors and similar applications that offer multiple viewports. People are actually using this feature. Deprecating it isn't a good idea IMHO.

Offline princec
« League of Dukes »

JGO Kernel


Medals: 196
Projects: 3


Eh? Who? What? ... Me?


« Reply #5 - Posted 2008-08-21 13:01:01 »

Ah maybe I jumped the gun a bit there then. Forgot about that. setParent() is just so cool Smiley

Cas Smiley

Offline StrideColossus

Senior Member


Medals: 3
Projects: 1



« Reply #6 - Posted 2008-08-21 13:13:15 »

From what I've seen so far (and bear in mind I'm quite new to this - hence this thread) both have their place.  The new setParent() should make integration of a 'real-world' application/game with AWT/SWING much nicer, whereas AWTGLCanvas is ideal for demos, editors, etc. and has the benefit supporting multiple instances.
Offline StrideColossus

Senior Member


Medals: 3
Projects: 1



« Reply #7 - Posted 2008-08-22 18:44:40 »

For anyone that's interested in my conclusions...

Display.setParent() works sweet - it means that for both the 'real-world' case (using the Display approach, generally full-screen) and the AWT/SWING case (using AWTGLCanvas, windowed for editors, demos, etc) I've only had to make minimal changes to the architecture of my engine, which is nice Smiley

Cheers for all the advice.

- chris
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (88 views)
2013-05-17 21:29:12

alaslipknot (96 views)
2013-05-16 21:24:48

gouessej (128 views)
2013-05-16 00:53:38

gouessej (123 views)
2013-05-16 00:17:58

theagentd (131 views)
2013-05-15 15:01:13

theagentd (119 views)
2013-05-15 15:00:54

StreetDoggy (161 views)
2013-05-14 15:56:26

kutucuk (184 views)
2013-05-12 17:10:36

kutucuk (185 views)
2013-05-12 15:36:09

UnluckyDevil (191 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.111 seconds with 20 queries.