I’m new to opengl and to JOGL so I’m trying to learn from the opengl superbible. This program is drawing a 3d plane and rotating it around the y axis. The camera stays still and I get a ton of flicker no matter how slowly it rotates. I have depth testing enabled and I have doubleBuffering enabled but I still have peices, like the tail fin, being displayed behind objects that it should be in front of. The odd thing is, the fin would every once in a while be displayed correctly. The wings do similar stuff, sometimes in front of the body like it should be and other times behind the body when it should be in front. Sometimes it will be displayed wrng for a whole frame, other times it will flciker on the redraw. It all seems fairly random and I’m stumped. Thanks for any help you give and here’s what my render code looks like. Please note that this code is modified from the openGL superbible.
public void display(GLDrawable glDrawable) {
GL gl=glDrawable.getGL();
GLU glu=glDrawable.getGLU();
int width=canvas.getWidth();
int height=canvas.getHeight();
gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL.GL_PROJECTION);
/**
* Then we clear the projection matrix to the Identity matrix
*/
gl.glLoadIdentity();
glu.gluPerspective(90.0f,1.0f,0,-500);
glu.gluLookAt(0.0f,100.0f,-50.0f,0.0f,0.0f,0.0f,0.0f,0.0f,1.0f);
//gl.glOrtho(-width/2,width/2,-height/2,height/2,-500,500);
gl.glMatrixMode(gl.GL_MODELVIEW);
gl.glLoadIdentity();
// Save the matrix state
gl.glPushMatrix();
//gl.glScalef(.5f,.5f,.5f);
//gl.glTranslatef(-20.0f,-20.0f,0.0f);
gl.glRotatef(xRot, 1.0f, 0.0f, 0.0f);
gl.glRotatef(yRot, 0.0f, 1.0f, 0.0f);
// Nose Cone /////////////////////////////
// Bright Green
gl.glColor3ub((byte)0, (byte)255, (byte)0);
gl.glBegin(gl.GL_TRIANGLES);
gl.glVertex3f(0.0f, 0.0f, 60.0f);
gl.glVertex3f(-15.0f, 0.0f, 30.0f);
gl.glVertex3f(15.0f,0.0f,30.0f);
gl.glVertex3f(15.0f,0.0f,30.0f);
gl.glVertex3f(0.0f, 15.0f, 30.0f);
gl.glVertex3f(0.0f, 0.0f, 60.0f);
gl.glVertex3f(0.0f, 0.0f, 60.0f);
gl.glVertex3f(0.0f, 15.0f, 30.0f);
gl.glVertex3f(-15.0f,0.0f,30.0f);
// Body of the Plane ////////////////////////
// light gray
gl.glColor3ub((byte)192,(byte)192,(byte)192);
gl.glVertex3f(-15.0f,0.0f,30.0f);
gl.glVertex3f(0.0f, 15.0f, 30.0f);
gl.glVertex3f(0.0f, 0.0f, -56.0f);
gl.glVertex3f(0.0f, 0.0f, -56.0f);
gl.glVertex3f(0.0f, 15.0f, 30.0f);
gl.glVertex3f(15.0f,0.0f,30.0f);
gl.glVertex3f(15.0f,0.0f,30.0f);
gl.glVertex3f(-15.0f, 0.0f, 30.0f);
gl.glVertex3f(0.0f, 0.0f, -56.0f);
///////////////////////////////////////////////
// Left wing
// Dark gray
gl.glColor3ub((byte)64,(byte)64,(byte)64);
gl.glVertex3f(0.0f,2.0f,27.0f);
gl.glVertex3f(-60.0f, 2.0f, -8.0f);
gl.glVertex3f(60.0f, 2.0f, -8.0f);
gl.glVertex3f(60.0f, 2.0f, -8.0f);
gl.glVertex3f(0.0f, 7.0f, -8.0f);
gl.glVertex3f(0.0f,2.0f,27.0f);
gl.glVertex3f(60.0f, 2.0f, -8.0f);
gl.glVertex3f(-60.0f, 2.0f, -8.0f);
gl.glVertex3f(0.0f,7.0f,-8.0f);
// Other wing top section
gl.glVertex3f(0.0f,2.0f,27.0f);
gl.glVertex3f(0.0f, 7.0f, -8.0f);
gl.glVertex3f(-60.0f, 2.0f, -8.0f);
// Tail section///////////////////////////////
// Bottom of back fin
gl.glColor3ub((byte)255,(byte)255,(byte)0);
gl.glVertex3f(-30.0f, -0.50f, -57.0f);
gl.glVertex3f(30.0f, -0.50f, -57.0f);
gl.glVertex3f(0.0f,-0.50f,-40.0f);
// top of left side
gl.glVertex3f(0.0f,-0.5f,-40.0f);
gl.glVertex3f(30.0f, -0.5f, -57.0f);
gl.glVertex3f(0.0f, 4.0f, -57.0f);
// top of right side
gl.glVertex3f(0.0f, 4.0f, -57.0f);
gl.glVertex3f(-30.0f, -0.5f, -57.0f);
gl.glVertex3f(0.0f,-0.5f,-40.0f);
// back of bottom of tail
gl.glVertex3f(30.0f,-0.5f,-57.0f);
gl.glVertex3f(-30.0f, -0.5f, -57.0f);
gl.glVertex3f(0.0f, 4.0f, -57.0f);
// Top of Tail section left
gl.glColor3ub((byte)255,(byte)0,(byte)0);
gl.glVertex3f(0.0f,0.5f,-40.0f);
gl.glVertex3f(3.0f, 0.5f, -57.0f);
gl.glVertex3f(0.0f, 25.0f, -65.0f);
gl.glVertex3f(0.0f, 25.0f, -65.0f);
gl.glVertex3f(-3.0f, 0.5f, -57.0f);
gl.glVertex3f(0.0f,0.5f,-40.0f);
// Back of horizontal section
gl.glVertex3f(3.0f,0.5f,-57.0f);
gl.glVertex3f(-3.0f, 0.5f, -57.0f);
gl.glVertex3f(0.0f, 25.0f, -65.0f);
gl.glEnd();
gl.glPopMatrix();
}