PDA

View Full Version : Objects behind other objects



nickcartwright
11-04-2003, 01:10 AM
Hiya!

Im having a problem with openGL not recognising that an object is behind another.

To put things into context - i am drawing a terrain and at the moment im adding some water. For the water i'm simply drawing a level quad across the terrain with some blue alpha... Good in theory but when i zoom out on the terrain the quad appears on parts of the terrain where is should be beneath it and sometimes the entire quad is shown.

Is there an easy way to fix this (ie - by changing a flag?) or am I going to have to place my water down with much more accuracy so it doesn't go beneath the landscape (if you get what i mean)..

Any help much appreciated!

Thankyou.

Rog
11-04-2003, 01:40 AM
Have you done glEnable(GL_DEPTH_TEST) ?

nickcartwright
11-04-2003, 05:12 AM
Yeah, I'v enabled Depth Testing...

Perhaps an image would show my problem better.

http://www.dcs.warwick.ac.uk/~csvog/problem.gif

The white square shown should be half under the green terrain and half above. The part that is below is half above and below.

It only corrects itself properley when i zoom in really close.

Any ideas?

Rog
11-04-2003, 05:25 AM
Could be z fighting. Do you have a big range in your znear zfar when you set the projection matrix?

And you're using 16-bit or 24-bit (32 whatever) depth buffer when you set the pixel format?

nickcartwright
11-04-2003, 05:32 AM
Could be z fighting. Do you have a big range in your znear zfar when you set the projection matrix?


Yeah - i have a massive range



And you're using 16-bit or 24-bit (32 whatever) depth buffer when you set the pixel format?


32 bits

Could be the z fighting thing then I guess..

Is there a simple resolve for this?

If not perhaps the best solution would be for me to calculate the coordinates of a quad that fitted the gap i wanted to fill more precisley...

chowe6685
11-04-2003, 05:42 AM
Push out the near clip plane, this will help to improve depth buffer accuracy. You could also pull the far plane in a bit, but moving out the near plane will give a better improvment

Rog
11-04-2003, 05:44 AM
Simple answer is to keep your near/far clip planes as tight as possible. Maybe you can change the position of your near clip plane depending on your camera position? So if you are closer to the action, your clip plane is nearer the camera. I suppose I mean you could adjust the near clip plane so it just catches the "nearest" object.

If you change the near/far values you'll soon be able to see if it improves, so it should be easy to test the z fighting theory.