Polygon Overlapping problem.

I try to render 2 polygon A and B. Say polygon A is a clone of polygon B and offseted 1 unit to the positive z. When I rotate the view to a certain angle, certain area of polygon A is overlapping with polygon B. How to get rid of this problem? Thanks.

Do you see z-fighting ?
You need to get more depth precision.
Put the near plane farther, and the far plane nearer.
http://www.opengl.org/wiki/index.php/Depth_Buffer_Precision

Thanks, it is exactly as what you have mention. Is it the only solution for this problem is to decrease the distance between near and far plane?

  • make sure you have a 24 bits depth zbuffer (16 bits is ugly)
  • increase your offset (1 unit is very small).
  • what I said above.

One more idea is to sort your polygons.
Sorting however, shoud not be based on distance function. Proper sorting means you check if one polygon is in front or behind other by testing one polygon’s vertices against other polygon’s plane.
Then you use GL_LEQUAL function and draw from furthest to nearest, or GL_LESS function and draw from nearest to furtest (second option is recommended, because it will take advantage of early-z optimizations on the GPU).

Of course, you use this solution only if these pointed out by ZbuffeR don’t meet your needs for some reason.