Resizing a GLJPanel with JOGL causes my model to disappear.

Posted by badcodenotreat on Stack Overflow See other posts from Stack Overflow or by badcodenotreat
Published on 2010-03-05T21:16:07Z Indexed on 2010/06/08 9:02 UTC
Read the original article Hit count: 262

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about java

Related posts about swing