So I just started learning LWJGL, and I am not having much difficulty with it, but I found that whenever I move 2 (or more) objects in front of each other, it doesn't quite preform perfectly. Regardless of depth, one of the objects (the one that was written) is rendered in front of the other. So they are rendered in order instead of by depth. I know I could fix this by writing something myself to determine in what order to render the shapes, but isn't there a way to do this with LWJGL? I haven't seen this mentioned before and I did a lot of Googling. I tried using depth testing with:
GL11.glClearDepth(1.0f);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDepthFunc(GL11.GL_LEQUAL);
But all that did was make the shapes flicker when they position above each other.
How do I fix this? Here's my code:
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluPerspective(45f, 800f/600f, 0.0f, 50.0f);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
GL11.glPushMatrix();
GL11.glTranslatef(0f, 0f, -200f);
GL11.glRotatef(angle, 1f, 0f, 0f);
//cube
GL11.glBegin(GL11.GL_QUADS);
int s = 50;
//bottom side
GL11.glColor3f(1f, 0f, 0f);
GL11.glVertex3f(-s, -s, s);
GL11.glVertex3f(-s, -s, -s);
GL11.glVertex3f(s, -s, -s);
GL11.glVertex3f(s, -s, s);
//top side
GL11.glColor3f(0f, 1f, 0f);
GL11.glVertex3f(-s, s, s);
GL11.glVertex3f(-s, s, -s);
GL11.glVertex3f(s, s, -s);
GL11.glVertex3f(s, s, s);
GL11.glEnd();
GL11.glPopMatrix();