display called before init

Hi,

I noticed that using the follwing initialization sequence, the display method of the GLEventListener is called either before the init method, or the init method is not called at all.

    GLCapabilities caps = new GLCapabilities();
    caps.setHardwareAccelerated(true);
    caps.setDoubleBuffered(true);
    //caps.setDepthBits(24);
    //caps.setStencilBits(8);
            
    GLCanvas glCanvas = GLDrawableFactory.getFactory().createGLCanvas(caps);
    glCanvas.setSize(640, 480);
  	this.getContentPane().add(glCanvas);          
  
    glCanvas.addGLEventListener(new MyGLEventListener());        
    initComponents(); // swing stuff with pack()

     versus


    initComponents(); // swing stuff with pack()
     glCanvas.addGLEventListener(new MyGLEventListener());

which works fine.

IMHO this behavior is a usage bug and should be fixed.

best regards

  • Michael

(P.S. using jogl 1.1 final on a linux box)

Thats not a bug, its a fact.

The normal way of initialisation of components is:

create Component
init Component
show Component

setVisible (show) is called after all code listed and the initialisation (create + init) sequence also doens’t change. The only thing swapped was adding the listener and the initialization of other swing componets (nothing with GLCanvas).

I tested this on my Machine WinXP SP2,JDK 1.5 Jogl 1.1 final

I don’t have that problem. Maybe a Linux problem?
Ken what do you say?

Without seeing all of the code it’s hard to say. You might try putting in a call to Thread.dumpStack() at the beginning ot your display() and init() methods to see what’s going on. In general you should add your GLEventListener immediately after constructing the GLCanvas, before adding it to the component hierarchy.

Thanks for answering Ken,

dumping the stack is a good idea, I will do that next time I get my hands on jogl. But I’m still wondering why the idiom, you mentioned:

is needed - are there any technical issues ?
If yes, these should be emphasized, because many awt and swing programmers probably are used to add/change/remove the needed event listeneres at any time.

Best regards
-Michael

You will only get your init() method called if your GLEventListener is registered before the OpenGL context is created (typically when the widget is realized). For this reason you should install your GLEventListener as early as possible in particular if you have a non-trivial init() method. There is an open bug to document this better but basically we are not going to try to keep track of which listeners had their init() methods called (or not) since the last context creation. It isn’t possible to keep track of this in the general case.

thanks again Ken, I assumed it has something todo with the gl_context.

May be offtopic but: Is there any good documentation about the gl_context and its use in JOGL ?
I’m a asking because I was used to work with DirectX and a Direct3D Device can be shared among several controls/components, but everytime the backbuffer is resized one has to reset the device. I don’t believe the init method is called after a resize so, I am wondering whether a GL_context can receive a reset and so on…

Best regards
-Michael

I’m afraid not. Your best bet would probably be to look at the JOGL source code and read the various platforms’ documentation on the APIs integrating OpenGL into their window systems.