Jump to content
  • Advertisement
Sign in to follow this  
alnite

OpenGL z-buffer question

This topic is 4884 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

I am making a building by drawing 5 quads (left, right, front, back, and top), and the order of which side get drawn first affect how the building is drawn. The result is similar to z-fighting, except that it's a lot more obvious. For example, if I draw left,right,front,and back first, then the top, the building looks OK if seen from the ground, but once you go the sky and look down to the building, you can see the sides are fighting with the top because the drawing order is sides first and top. Sometimes the sides are fighting to each other too depending who get drawn first. I don't know if this is my video card only or OpenGL always behaves this way, but is there a cure to this? edit: I tried triangle strips for the sides and it's still like that.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by alnite
I don't know if this is my video card only or OpenGL always behaves this way, but is there a cure to this?


Make sure you have enabled depth testing. If it is enabled, make sure you are actually getting a depth buffer when you set up the pixel format.

Share this post


Link to post
Share on other sites
I enable GL_DEPTH_TEST and pass GL_LEQUAL to glDepthFunc(), and I clear GL_DEPTH_BUFFER_BIT every frame.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kalidor
Quote:
Original post by alnite
I don't know if this is my video card only or OpenGL always behaves this way, but is there a cure to this?


Make sure you have enabled depth testing. If it is enabled, make sure you are actually getting a depth buffer when you set up the pixel format.

I use GLUT, so I don't set the pixel format.

This is strange. I made a checker game before and the board is made off 64 tiny cubes and no z-fighting occured. This is a freaking huge building and it's everywhere.

[Edited by - alnite on March 7, 2005 9:58:18 PM]

Share this post


Link to post
Share on other sites
Hmm... what are your near and far clip plane distances? And I know it's a longshot but maybe you have polygon offset enabled? I don't know what else it could be.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kalidor
Hmm... what are your near and far clip plane distances? And I know it's a longshot but maybe you have polygon offset enabled? I don't know what else it could be.

That was it. I fixed it. The near was like 0.05 and my far was around 1024.0, and field of view was about 45 degree. I changed it to 1.0-1024.0, 60degree field of view, it is a lot (!) better.

Share this post


Link to post
Share on other sites
Quote:
Original post by alnite
That was it. I fixed it. The near was like 0.05 and my far was around 1024.0, and field of view was about 45 degree. I changed it to 1.0-1024.0, 60degree field of view, it is a lot (!) better.


Ah good, I'm glad you fixed it. In case you haven't seen it, or would like to learn in more detail about how the z-buffer works, check out this link.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kalidor
Ah good, I'm glad you fixed it. In case you haven't seen it, or would like to learn in more detail about how the z-buffer works, check out this link.

Thanks for the great link. I was so stupid that I thought increasing z-far clipping plane and decreasing z-near plane can increase the accuracy.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!