Jump to content
  • Advertisement
Sign in to follow this  

Quick question about drawing triangles in Opengl

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

I got a quick question.
I've been doing the tutorials on gametutorials.com, and theres one thing I dont undertstand;

Look at these triangles: http://www.gametutorials.com/gtstore/pc-4-1-matrices.aspx

When I try to do something similiar, my triangle which is closest to me appears to be "behind" the other two triangles rather than infront of them (like in the picture in the link)

Here's the code
void cApp::renderScene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity();

// Position View Up Vector
gluLookAt(0, 0, 6, 0, 0, 0, 0, 1, 0);

drawTriangle(0,0,0,2,2);

glPushMatrix();
glTranslatef(-1,0,-1);
drawTriangle(0,0,0,2,2);
glPopMatrix();

glPushMatrix();
glTranslatef(1,0,-1);
drawTriangle(0,0,0,2,2);
glPopMatrix();

SDL_GL_SwapBuffers();
}


What could be the reason for this? Since the first triangle is closer to the camera position, shouldn't it overlap the two in the back?

Share this post


Link to post
Share on other sites
Advertisement
Cause you could want to get them rendered in the order you drew them instead of by their z-position. There are possibly other reasons but that's one from the top of my head.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!