Basic JOGL Problems

Hey everyone, I’ve been tearing my hair out on this one.

I’m working JOGL. I have a GLCanvas with an associated GLEventListener. The problem is that the buffer seems to be getting cleared faster than it can draw the cube so I never see it. If I resize the frame I can occasionaly see the green cube as I am resizing. Once I stop resizing the frame I’m back to my dark gray glClear color with no cube. My display method for the listener looks like this:

public void display( GLAutoDrawable drawable ) {

GL gl = drawable.getGL();
GLUT glut = new GLUT();

//Clear the buffer and fill with background color
gl.glClear( GL.GL_COLOR_BUFFER_BIT );

//Clear the matrix and perform the viewing transformation
gl.glLoadIdentity();
glu.gluLookAt( 25.0, 25.0, 25.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 );

for (ObjectState state : objectStates) {
int x = Integer.parseInt( state.getValue( “Lat” ) );
int y = Integer.parseInt( state.getValue( “Lon” ) );
gl.glColor3f( 0f, 1f, 0f );
gl.glPushMatrix();
gl.glTranslatef( x, y, 0 );
glut.glutSolidCube( 1 );
gl.glPopMatrix();
}

gl.glFlush();
}

When do you swap buffers ?
Be sure to use double buffering and do glutSwapBuffers at the end of the display(), instead of the glFlush().

More preciselly, use GLDrawable.swapBuffers()