On JFrame resize, GLCanvas resize and GLJpanel re-init.

Hello,

I don’t know the underlying techniques that makes an openGL viewport integrated into a swing component so my question is probably a really stupid question. Pardon me for that.

When I put a GLCanvas into a JFrame and the user grab a corner of the window and resize it, the init() function of the GLEventListener is not called, only its resize function is.

When I do the same with a GLJPanel, the init() function is called frequently.

I am really wondering if it have to be so many re-init in the case of the GLJPanel. I would be really happy to just handle a resize function rather than an init function.

As I said my question might be really a stupid one for the ones that know why it cannot be done. Sorry in advance :-\

The reason the GLJPanel receives frequent init() calls is that it has a backing off-screen pbuffer which needs to be destroyed and re-created every time the GLJPanel’s size increases beyond the size of the pbuffer. There is (or should be; please file a bug if this doesn’t seem to be the case) some hysteresis which prevents init() from being called during each and every resize event. As long as your GLEventListener is written in such a way that you can properly handle repeated calls to init() then your program should work correctly with either a GLCanvas or a GLJPanel.

Note also that if you’re using Mustang and the Java2D/JOGL bridge (-Dsun.java2d.opengl=true) you won’t see repeated calls to init() any more, since the GLJPanels use the Swing back buffer rather than their own pbuffer in this case.

Note also that if you're using Mustang and the Java2D/JOGL bridge (-Dsun.java2d.opengl=true) you won't see repeated calls to init() any more, since the GLJPanels use the Swing back buffer rather than their own pbuffer in this case.

nice tip. My red book examples using GLJPanel in a JFrame don’t freeze anymore when i resize. So I guess whatever data one loads on init() should only be loaded once, when the data holder is null.

I am trying with Mustang b92, with the Java2D/JOGL bridge enabled (-Dsun.java2d.opengl=True) and here is my result, while the user resize the window that contains a GLJPanel :

OpenGL pipeline enabled for default config on screen 0
init();
reshape();
display();
init();
reshape();
display();
[etc … it repeats all the time in this exact order]
init();
reshape();
display();
[here I close the window and crash !]

An unexpected error has been detected by Java Runtime Environment:

EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x693129a7, pid=3948, tid=3808

Java VM: Java HotSpot™ Client VM (1.6.0-rc-b92 mixed mode, sharing)

Problematic frame:

C [atioglxx.dll+0x3129a7]

An error report file with more information is saved as hs_err_pid3948.log

If you would like to submit a bug report, please visit:

http://java.sun.com/webapps/bugreport/crash.jsp

So the init() is still called pretty often. In fact, when the bridge is disabled the init() function is not called so frequently (i.e. there is more couples of reshape()/display() called before another init() is called).

My computer is a notebook with a ATI mobility Radeon 9600.

Yes, it is true that when the top-level window is resized in this configuration that you’re going to see calls to init(). I was assuming the use of JInternalFrames when I said that init() wouldn’t be called repeatedly during resizing.

ohh !!! So it explains everything, then !! :smiley:

That’s cool, I will try with an internal frame.

Thank you !! :slight_smile: