PDA

View Full Version : viewing perspective problem



usfish
02-29-2008, 02:59 PM
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.

-NiCo-
02-29-2008, 03:02 PM
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);

usfish
02-29-2008, 03:48 PM
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.....


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);

-NiCo-
02-29-2008, 04:00 PM
That's a completely different problem indeed, although I'm still unclear about what you're trying to accomplish. Maybe a screenshot can help?


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.

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


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.


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