# OpenGL [3D/Beginner] Depth/Drawing order issue

This topic is 2524 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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:

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

Thanks!

##### Share on other sites
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)

1. 1
2. 2
Rutin
23
3. 3
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 11
• ### Forum Statistics

• Total Topics
633653
• Total Posts
3013158
×