Hi all
I’ve been developing a 3D engine which currently has a LWJGL implementation. I would like to migrate to JOGL as it seems to be more Java-like, particularly with the JSR in mind.
However I was somewhat surprised by the constraints that JOGL seems to put on the architecture of my engine:
- Is a GLEventListener mandatory in a JOGL-based application?
The callback approach of GLEventListener is sweet for a simple demo but seems restrictive when you try and scale to a ‘proper’ engine.
The current design already has a ‘viewport’ interface, the JOGL implementation of this interface contains a GLCanvas instance for each viewport on the frame. The engine manages the viewports, display, devices, etc. and invokes a set of ‘lifecycle’ methods on each viewport - start a new frame, clear the buffers, set the projection/modelview matrices, and so on.
The JOGL implementation has to delegate to canvas.display(), which then has to call back somehow to the engine if I want it to follow the same generic approach (which I do!), or replicate/emulate the lifecycle within the JOGL viewport. Neither of these approaches is particularly palatable.
So - do you HAVE to use GLEventListener? Or is there another approach?
For example, can I not request a GL object from the canvas, execute the lifecycle methods described above on it, then call some method to render the canvas, without having to go through the listener to get it?
- How to pass the global GL ‘context’ around.
The LWJGL methods are all static so I followed this approach in my engine design. There are APIs and implementation interfaces for texture management, transformations, shaders, etc. These then delegate to the actual OpenGL implementation.
For JOGL however I need to get the GL object from the current canvas. The only way to do this is set a nasty ‘global’ variable to the GLDrawable passed to the init() method of the listener, or fiddle my entire design to pass around this ‘context’ variable to EVERY method supported by the engine.
Again neither of these is particularly palatable.
Is there any way to get the ‘current’ GL variable?
- When is the GL ‘context’ valid?
The other thing that surprised me was the fact that one cannot invoke most (all?) of the GL methods without having a canvas already created.
My simplest demo has the proverbial rotating textured cube. When I first developed the JOGL implementation of the engine I got loads of null-pointer exceptions because the demo loaded and created the texture before the viewport. This constraint is documented in the JavaDoc, and I’ve seen several threads on this issue.
Firstly, is my assumption correct? (I think so because when I fiddled the engine to create a window straight away it worked fine).
Secondly, is there no way to get a GL object to do stuff like creating textures without having a viewport open?
Hope this all makes some sort of sense.
Cheers for any help.
- chris


