viewing perspective problem

Hi I got a quick problem and I need your help…

Let there be two objects, one is at (x,y,0), the other is at (x,y,100), ie, right above the other one. By default, when I am moving them, I will not see them overlap, because of the viewing effects. Is there any way to make them overlap? Thanks.

My guess is that you didn’t enable depth testing yet. Try adding this to your code:

glClearDepth(1.0f);
glClear(GL_DEPTH_BUFFER_BIT);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
//draw here
glDisable(GL_DEPTH_TEST);

seems it doesn’t work.

what I meant was, opengl sets the view point as the middle of the window. so if I move them to the middle, they overlap. but when I put them on the lower-left side, the (x,y,0) appears to be to the lower-left of the (x,y,100), as (x,y,100) is closer to the viewing point.

I just want them to overlap at any time…

That’s a completely different problem indeed, although I’m still unclear about what you’re trying to accomplish. Maybe a screenshot can help?

Ehm…, are you referring to the fact that the projection matrix is set to the identity matrix by default? Or something else?

so 100 is closer to the view point that is in the middle of the window…? Rather confusing :slight_smile: