z-buffer question

Started by
7 comments, last by alnite 19 years, 1 month ago
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.
Advertisement
Did you call glEnable(GL_DEPTH_TEST)?
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 enable GL_DEPTH_TEST and pass GL_LEQUAL to glDepthFunc(), and I clear GL_DEPTH_BUFFER_BIT every frame.
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]
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.
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.
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.
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.

This topic is closed to new replies.

Advertisement