views:

190

answers:

2

I switched over to using a GLJPanel from a GLCanvas to avoid certain flickering issues, however this has created several unintended consequences of it's own.

From what I've gleaned so far, GLJPanel calls GLEventListener.init() every time it's resized which either resets various openGL functions i've enabled in init() (depth test, lighting, etc...) if i'm lucky, or completely obliterates my model if i'm not.

I've tried debugging it but I'm not able to correct this behavior. This is my init() function:

    gl.glShadeModel( GL.GL_SMOOTH );

    gl.glEnable( GL.GL_DEPTH_TEST );
    gl.glDepthFunc( GL.GL_LEQUAL );
    gl.glDepthRange( zNear, zFar );

    gl.glDisable( GL.GL_LINE_SMOOTH );
    gl.glEnable(GL.GL_NORMALIZE);

    gl.glEnable( GL.GL_BLEND );
    gl.glBlendFunc( GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA );

    // set up the background color
    gl.glClearColor( ((float)backColor.getRed  () / 255.0f),
                     ((float)backColor.getGreen() / 255.0f),
                     ((float)backColor.getBlue () / 255.0f), 1.0f);

    gl.glEnable ( GL.GL_LIGHTING );
    gl.glLightfv( GL.GL_LIGHT0, GL.GL_AMBIENT, Constants.AMBIENT_LIGHT, 0 );
    gl.glLightfv( GL.GL_LIGHT0, GL.GL_DIFFUSE, Constants.DIFFUSE_LIGHT, 0 );

    gl.glEnable ( GL.GL_LIGHT0 );

    gl.glTexEnvf( GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE );
    gl.glHint( GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST );

    // code to generate model

Is there any way around this other than removing everything from init(), adding it to my display() function? Given the behavior of init() and reshape() for GLJPanel, i'm not sure if that will fix it either.

A: 

GLJPanel and CLCanvas are essentially identical in their function, as far as JOGL is concerned. The only difference is that GLJPanel is JComponent and lightweight, whereas GLCanvas is a Component and heavyweight. It is likely that any problems you are seeing are not due to those differences (although JOGL is not the most stable part of Java, and there might be an 'undocumented' difference).

A disappearing model is probably due to either not actually calling the draw code, or mis-setting something in the GL initialisation (very easy to do). I would recommend transferring everything to the display() function. If that fixes it move things back one at a time (it's only a performance issue).

Having said that I don't see you setting the viewport size in init(). That is one of the things that has to be done every time the window size changes.

DJClayworth
Dear god i think that might be it, viewport gets set in my Display and Reshape function, so naturally i guess i didn't think to include that in my init() function.
badcodenotreat
A: 

From gljpanel doc:

Note that because this component attempts to use pbuffers for rendering, and because pbuffers can not be resized, somewhat surprising behavior may occur during resize operations; the GLEventListener.init(net.java.games.jogl.GLDrawable) method may be called multiple times as the pbuffer is resized to be able to cover the size of the GLJPanel. This behavior is correct, as the textures and display lists for the GLJPanel will have been lost during the resize operation. The application should attempt to make its GLEventListener.init() methods as side-effect-free as possible.

Yeah, It sucks. Because you need to store your vertex data and other in the small JVM memory. Actually I search why they don't re-use the same context.