[3D/Beginner] Depth/Drawing order issue

Started by
0 comments, last by Labrasones 12 years, 3 months ago
Hi. I'm trying to learn some basic 3D with LWJGL, a java game library that uses OpenGL. For my first test I used a very basic colored 3D pyramid code I got from the internet. The code to render the shape is shown below.

glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 0.0f); // Red
glVertex3f(0.0f, 1.0f, 0.0f); // Top Of Triangle (Front)
glColor3f(0.0f, 1.0f, 0.0f); // Green
glVertex3f(-1.0f, -1.0f, 1.0f); // Left Of Triangle (Front)
glColor3f(0.0f, 0.0f, 1.0f); // Blue
glVertex3f(1.0f, -1.0f, 1.0f); // Right Of Triangle (Front)
glColor3f(1.0f, 0.0f, 0.0f); // Red
glVertex3f(0.0f, 1.0f, 0.0f); // Top Of Triangle (Right)
glColor3f(0.0f, 0.0f, 1.0f); // Blue
glVertex3f(1.0f, -1.0f, 1.0f); // Left Of Triangle (Right)
glColor3f(0.0f, 1.0f, 0.0f); // Green
glVertex3f(1.0f, -1.0f, -1.0f); // Right Of Triangle (Right)
glColor3f(1.0f, 0.0f, 0.0f); // Red
glVertex3f(0.0f, 1.0f, 0.0f); // Top Of Triangle (Back)
glColor3f(0.0f, 1.0f, 0.0f); // Green
glVertex3f(1.0f, -1.0f, -1.0f); // Left Of Triangle (Back)
glColor3f(0.0f, 0.0f, 1.0f); // Blue
glVertex3f(-1.0f, -1.0f, -1.0f); // Right Of Triangle (Back)
glColor3f(1.0f, 0.0f, 0.0f); // Red
glVertex3f(0.0f, 1.0f, 0.0f); // Top Of Triangle (Left)
glColor3f(0.0f, 0.0f, 1.0f); // Blue
glVertex3f(-1.0f, -1.0f, -1.0f); // Left Of Triangle (Left)
glColor3f(0.0f, 1.0f, 0.0f); // Green
glVertex3f(-1.0f, -1.0f, 1.0f); // Right Of Triangle (Left)
glEnd();


Also, i've made a simple code myself to move the screen around the shape (or the shape around the screen) witch works well. The only probem I have now, is that the pyramid thingy is visible, but it looks a bit strage, and I think it has to do with the drawing order. Instead of drawing in order from far to close, so the near shapes overlap the far shapes, I think it draws the shapes in the order they are rendered in the code. The result looks like this:
1hc6ww.png

Does anyone know how to fix this? I couldn't find anything helpfull on google.

Thanks!
Advertisement
have you enabled gl depth tests? It shouldn't be too hard to find a reference to it somewhere. I can't remember it off the top of my head (I'm new too)

This topic is closed to new replies.

Advertisement