Sign in to follow this  
KaiserJohan

Quick question about drawing triangles in Opengl

Recommended Posts

KaiserJohan    2317
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
[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();
}[/code]

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
owl    376
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this