Odd behaviour from GLEventListener with JOGL 2

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Odd behaviour from GLEventListener with JOGL 2

Ric Wright
I recently began experimenting with JOGL 2. I do most of my Java work in Eclipse. One odd behaviour with JOGL2 is that if I create a very simple AWT view with a class that implements GLEventListener, the listener does not get called unless I effectively prime the pump by turning on an Animator (either Animator or FPSAnimator). After a few dozen calls of "display()" the window is initialized and it all works OK. But without this Animator, the init method on the GLEventListener never gets called. Code is very simple - see below. This worked without problems with JOGL 1.1.1. Am I missing something? TIA, Ric public class SimpleSceneAWT implements GLEventListener { public static void main(String[] args) { GLProfile.initSingleton(); GLProfile glp = GLProfile.getDefault(); GLCapabilities caps = new GLCapabilities(glp); GLCanvas canvas = new GLCanvas(caps); Frame frame = new Frame("AWT Window Test"); frame.setSize(300, 300); frame.add(canvas); frame.setVisible(true); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); canvas.addGLEventListener(new SimpleSceneAWT()); /* without this, in JOGL2 the init method never gets called FPSAnimator animator = new FPSAnimator(canvas, 60); animator.add(canvas); animator.start(); */ } /* other methods here */ }
Reply | Threaded
Open this post in threaded view
|

Re: Odd behaviour from GLEventListener with JOGL 2

gouessej
Administrator
What is wrong with using an animator?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Odd behaviour from GLEventListener with JOGL 2

Wade Walker
Administrator
In reply to this post by Ric Wright
This code also works instead of an animator:

try {
    Thread.sleep(1000);
}
catch (InterruptedException e1) {
}
canvas.display();

It seems like if you call canvas.display() too soon, it doesn't have any effect for some reason.
Reply | Threaded
Open this post in threaded view
|

Re: Odd behaviour from GLEventListener with JOGL 2

Ric Wright
The problem with just blindly using an Animator is that it feels a bit hackish.  If you are planning to animate stuff it might make sense, but ...

And, Wade, yes that works too.  

But both of these seem inefficient. Clearly, the underlying machinery hasn't finished initializing.  And when it does, it doesn't call init() unless one pokes it by calling display().  The question, to my mind, is how do I detect when initialization is complete?  I thought perhaps java.awt.Frame.isValid might work, but no. Ditto other event-flags.  I can implement what Wade suggests, of course, but this seems like a bug.  This worked as expected in JOGL 1.1.1 but now (in JOGL 2 as of 10 days ago) it behaves oddly.  I'll probably just stick with 1.1.1 until JOGL 2 is more stable.

If someone on the JOGL team wants me to file a bug, let me know
Reply | Threaded
Open this post in threaded view
|

Re: Odd behaviour from GLEventListener with JOGL 2

Wade Walker
Administrator
Ric Wright wrote
If someone on the JOGL team wants me to file a bug, let me know
I agree that this totally looks like a bug -- my code wasn't meant as a solution, just as a demonstration that waiting some amount of time was the critical factor, not the number of times display() was called. I'm not a JOGL team member, but it seems like the right thing to do would be to file a bug report

Just in case you hadn't seen it already, the JOGL bug report guidelines are at http://jogamp.org/wiki/index.php/Jogl_FAQ#Bugreports_.26_Testing.

So far, I've had better luck using SWT with JOGL2 instead of AWT. I did a test version of my first tutorial (http://wadeawalker.wordpress.com/2010/10/09/tutorial-a-cross-platform-workbench-program-using-java-opengl-and-eclipse/) with no animation, and it didn't show this problem or the other similar one (http://jogamp.org/bugzilla/show_bug.cgi?id=401) that AWT guys have been having.
Reply | Threaded
Open this post in threaded view
|

Re: Odd behaviour from GLEventListener with JOGL 2

Ric Wright
I agree and will log a  bug.  And I like your tutorial.  Wish I'd seen it last week.  Would have saved me a little time doping out stuff related to AWT.  I too work in Eclipse and only used the SWT bridge because it was what worked for me.  I'll try your approach.