Sign in to follow this  
0Buzzard

GL_DEPTH_TEST problem, help!

Recommended Posts

Hey people,

I have a problem with my renderer where i want to depth test on my md5 mesh so you can´t see through it, but when i do set glEnable(GL_DEPTH_TEST), the model just disappears and i have searched around the internet and i have found people having the same problem and i tried the solutions offerd but nothing has helped.

I set glDisable(GL_DEPTH_TEST);, glDepthFunc(GL_LEQUAL); and glClearDepth(1.0f); for the default GL state (when first initialized) and before rendering the mesh, i set glClear(GL_DEPTH_BUFFER_BIT); and glEnable(GL_DEPTH_TEST);.

I do request 24 bit depth buffer from the context and i use gluPerspective(45.0f, glConfig.screenWidth/glConfig.screenHeight, 3.0f, 0.0f);, now i just toyed around with zFar and zNear so thats why its 3 and 0.

Does anyone have any clue to what im doing wrong or missing here?.



Here is where i don´t use depth test
http://img408.imageshack.us/img408/5843/namnlsc.jpg

And here is where i use depth test
http://img809.imageshack.us/img809/5461/namnls2y.jpg

- Thanks

Share this post


Link to post
Share on other sites
You have the planes in the wrong order. The second last parameter is the near plane and the last is the far plane. The far plane must be greater than the near plane, and 0 is not greater than 3.

Furthermore, even if you correct your code and swap them (which I assume is what you intended), the near plane must be a positive value.

Share this post


Link to post
Share on other sites
Quote:
Original post by Brother Bob
You have the planes in the wrong order. The second last parameter is the near plane and the last is the far plane. The far plane must be greater than the near plane, and 0 is not greater than 3.

Furthermore, even if you correct your code and swap them (which I assume is what you intended), the near plane must be a positive value.


Okey so i did swap them to 0.1f and 3.0f but then it wont draw at all with depth test on :s. It seems that setting zFar to 1000.0f makes it draw but depth test is still failing (it only draws the skeleton).

Share this post


Link to post
Share on other sites
Quote:
Original post by Brother Bob
Reduce your code to an absolute minimum working program by removing things that don't affect the problem, and post it here. More often than not, this process of isolating the problem actually helps you find it.


Yeah, i was thinking that too, my renderer is kinda messy so im going to rewrite it and go by "trail and error" testing and see what the problem is.

Share this post


Link to post
Share on other sites
Quote:
Okey so i did swap them to 0.1f and 3.0f but then it wont draw at all with depth test on :s. It seems that setting zFar to 1000.0f makes it draw but depth test is still failing (it only draws the skeleton).
This is because the geometry was getting clipped against the far plane. Usually, you want to make the distance between the planes large for testing, and reduce them for better precision.

I agree that the issue is probably something that could be fixed by some housekeeping, but it would also be nice to have some code to look at here.

-G

Share this post


Link to post
Share on other sites
I found out what the problem was. A GL call was "GL_EQUAL" when it should be "GL_LEQUAL".

Thanks for all your replies!.

-- Image of the working "zfat" zombie --
http://img829.imageshack.us/img829/6878/namnlsbi.jpg

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