Depth test for cones

Below is my code for drawing 2 cones. But when I rotate it, the 2nd cone always overlaps the 1st cone. Actually when rotated beyond 180 degrees, the 1st cone should overlap the 2nd one. Any suggestions or clues for avoiding this problem?

//1st Cone
GL.glLoadIdentity();
GL.glPushMatrix();
GL.glTranslatef(0.0f, -1.0f, -5.0f);
GL.glRotatef(xrot, 1.0f, 0.0f, 0.0f);
GL.glRotatef(yrot, 0.0f, 1.0f, 0.0f);
GL.glColor3f(1.0f,0.0f,0.0f);
GL.gluCylinder(this.cone, 0.5f, 0.0f, 3.0f, 32,1);

//2nd Cone
GL.glTranslatef(1.5f, 0.0f, 0.0f);
GL.glColor3f(0.0f,1.0f,0.0f);
GL.gluCylinder(this.cone, 0.5f, 0.0f, 2.0f, 32,1);
GL.glPopMatrix();
GL.glFlush();

The order of the transformation faunctions is so important. first, you translate the coordinate system and rotate it. Then you draw your fist cone. Then you add another translation to your code. Since you haven’t used from the glLoadIdentity() or glPopMatrix(), you actually use from the transformed modelview matrix to draw your second cone. The following code is correct:–Do you mean it?

glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glPushMatrix();
//do your translation and rotation
//Draw your first cone
glPopMatrix();

glPushMatrix();
//do your translation and rotation
//Draw your second cone
glPopMatrix();

-Ehsan-

Hi Ehsan,
Thanks for the quick reply. Hey, I was doing the same thing which you have suggested. But I intend to rotate the cones using keyboard. When I tried to do that using your strategy, both the cones appear to rotate about their individual axes and not about a common axis. To avoid this, I had included the entire routine in a single stack operation.