? GLJPanel and the init() method ?

I’m fairly new to JOGL so be lenient…I have started a project where I’m using the GLJPanel() for my main panel (vs the GLCanvas) because of the Swing interaction that I need. I use the init() method to load textures and to load 3DS models. Everything works great in that basic state until I resize the window…the code calls init() every time the window is resized. In some instances this just forces a reread of my textures and models and for the textures that is no problem but for the models it causes the window not to repaint at all.

I realize that on resizing the reshape() function gets called in OpenGL and I’ve coded in OpenGL where I loaded textures in my init() function (yes they were globally defined and not local copies) and everything worked fine. I could resize the OpenGL window and init() would not appear to be called again, but for some reason I’m getting the init() to be called for every resize. I know I’m doing something wrong. I know if I switch to GLCanvas() then I don’t see init() being called again so what is the issue with the GLJPanel() and init().

I think what I would really like to find is some example code for how to setup the GLJPanel() with loading textures and then I could go from there…any suggestions?

Repeated calls to GLEventListener.init() are an essentially inevitable consequence of using the GLJPanel. The backing store (pbuffer or bitmap / pixmap) has a fixed size and needs to be expanded as the GLJPanel increases in size. This is why it is best to design your GLEventListeners in a way that init() can be called multiple times with no adverse side-effects.

Please look at the jogl-demos workspace for examples. Nearly all of the demos run inside the demos.jrefract.JRefract harness, where they are run inside GLJPanels as opposed to GLCanvases.

Thank you for that confirmation…I suspected as much but could not find a reference on the net to verify this.

btw, this has been discussed already in other posts such as this one ( http://www.java-gaming.org/forums/index.php?topic=16295.msg128795#msg128795 )...unfortunately I plead ignorance of the topic and of JOGL but I do apologize for double postings.

I guess I need to review what goes into an init() method to begin with because loading the textures and models in it is obviously incorrect…since they would be repeatedly loaded with resizes. Yes I can put a static flag check to ensure those textures and models are read only once but when I did this my scene end up getting cleared out so I must be forcibly clearing the scene without knowing it. Maybe the JRefract example will help…thanks. (or if anyone else has an example I would not be opposed to seeing it.)

Talking with others I realized that because the GLJPanel() resize causes the GLContext to be destroyed and so that is why I lose my textures and models. It was suggested that I essentially build a separate GLContext at the start where I load my textures and models (make it current initially and then release it), then follow this with building the normal GLContext for my scene and then share the initial context data with it in the init() function (i.e. following resizes, etc). Has anyone done this? And have you been successful? The extent of my knowledge in JOGL is still quite small so I suspect this will be quite an adventure.

As a last resort I guess I can revert to using a GLCanvas()…I was intending to use the GLJPanel() because I was mixing my 3D view with 2D Swing panel but can someone elaborate on what the major issues are with employing a GLCanvas() in a JPanel() in a JFrame()? Thanks.

See the section “Heavyweight and Lightweight Issues” in the JOGL Users’ Guide.