Sign in to follow this  

Objects get overlayed incorrectly

This topic is 2663 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 have encountered a problem followingly.
First here the projection settings etc.

glMatrixMode(GL_PROJECTION); // select the projection matrix
glLoadIdentity(); // reset the projection matrix

gluPerspective(60.0f,(GLfloat)width/(GLfloat)height,-1.0f,1.0f);

glMatrixMode(GL_MODELVIEW)
glLoadIdentity();
gluLookAt(0, 0, 120, 0, 0, 0, 0, 1, 0);

then I make two triangle which intersect.(here the code)

glPushMatrix();

glTranslatef(0,0,0);
glColor3f(0,0,0);
glBegin(GL_TRIANGLES);

glVertex3f(0.0,15.0,10);
glVertex3f(15.0,0.0,10);
glVertex3f(15.0,15.0,10);
glEnd();

glPopMatrix();
glPushMatrix();
glTranslatef(0,0,0);
glColor3f(1,1,1);
glBegin(GL_TRIANGLES);
glVertex3f(0.0,40.0,0);
glVertex3f(0.0,0.0,0);
glVertex3f(40.0,40.0,0);
glEnd();
glPopMatrix();

But now if I change the z-value of one triangle to lets say 10.(s.code)
The black triangle should be displayed on top of the white one, thus should be moved towards me.

But the thing what happens is, that I will see the white one on top, although when I turn the model around I will see that the black one was correctly moved towards me. (I have a function for turning)

But for some reason the color of objects underneath dominate upper objects' colors.Why?

I am also not really sure about the gluperspective thing.
But Everything is displayed correctly so far except for this z-axis movement things.


Share this post


Link to post
Share on other sites
Ok wait.
I already have that included.

Here the rest of my initialisation:


glClearDepth(1.0f); // depth buffer setup
glEnable(GL_DEPTH_TEST); // enables depth testing
glDepthFunc(GL_LEQUAL); // the type of depth test to do

glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); /

glEnable(GL_CULL_FACE);
glEnable(GL_LINE_SMOOTH);


glShadeModel(GL_SMOOTH); // enables smooth shading


The problem remains the same.

Share this post


Link to post
Share on other sites

This topic is 2663 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.

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