I have been programming a jogl application and I can’t get deph testing to work. Can anyone with more experience than me sugfgest something i am missing, or something silly i have done?
I use the following code (in my class that implements GLEventListener) to enable depth testing,
public void display(GLDrawable drawable)
{
GL gl = drawable.getGL();
GLU glu = drawable.getGLU();
camera.position(gl, glu);
//enable removal of hidden faces
gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_LEQUAL);
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
owner.display(drawable);
gl.glFlush();
}
where owner.display(drawable) calls a display object function in all the objects in the universe, each of which either draws a quad of a triangle, as follows:
public void displayObject(GLDrawable drawable)
{
GL gl = drawable.getGL();
if(fill) { gl.glPolygonMode( GL.GL_FRONT, GL.GL_FILL ); gl.glPolygonMode( GL.GL_BACK, GL.GL_POINT); }
else { gl.glPolygonMode( GL.GL_FRONT_AND_BACK, GL.GL_LINE ); }
//gl.glCullFace(GL.GL_FRONT_AND_BACK);
//l.glPolygonMode( GL.GL_FRONT_AND_BACK, GL.GL_FILL );
gl.glColor4f(colour[0], colour[1], colour[2], colour[3]);
gl.glBegin(GL.GL_POLYGON);
for(int i = 0; i < points.length; i++)
{
gl.glNormal3d(vertexNormals[i].getX(), vertexNormals[i].getY(), vertexNormals[i].getZ()); //Set the normal for the node
gl.glVertex3d(points[i].getX(), points[i].getY(), points[i].getZ());
}
gl.glEnd();
}