[SOLVED]What makes your renderer do this???

I’m confused. I actually even borrowed my display code from another project I made which does not have this issue. Do you see how my objects when overlapping one another get all chopped up?

That’s supposed to be a black cube infront of a white Box shape. The White Box shape should have some little black spots on it though(lame texture haha).

Note: these objects are perfectly fine looking when they don’t overlap each other.

Any hints, or tips would be really cool as always :smiley:

Perhaps you need to use glPolygonOffset…

If you draw different polygons so they are very nearly co-planar, the depth buffer’s loss of precision will most likely have a problem figuring it out. This results in what is called z-fighting, were some pixels of one polygon win and others, right next to it, are from the other colored polygon. Obviously this is pretty ugly.

As gouessej said, glPolygonOffset is a way to solve this problem. Essentially, it allows you to declare which polygon is the winner in an effective tie. There are problems with glPolygonOffset because it can be implemented differently on different hardware, making one offset value acceptable on a Nvidia card still not look good with an ATI card.

That being said, if you need your boxes to be co-planar, you should experiment with using it; otherwise, I’d make them not on the same plane.

And, if you’re positive that the boxes aren’t drawn with faces on the same plane, then we have a more serious issue. My best guess, in that case, would be that your depth buffer is screwed up and isn’t being cleared correctly.

also keep in mind that zbuffer’s precision depends on the distance to the viewer. Z-Precision of faces rendered near to the viewer is better than faces rendered far away. You can decrease z-fighting artifacts by adjusting the z position of near and far clipping panes.
(its hard to tell from the screenshot how far the objects are actually away from the viewer :P)

this page explains it pretty well:
http://www.sjbaker.org/steve/omniv/love_your_z_buffer.html

(but this won’t help much for 100% coplanar faces, only fyi)

Thanks everyone for the awesome explanations and links. I found out as suggested it was my stupid GluPercpective I set the NearClip to 0, changed it to 1 and it’s gorgeus GL again :D.

Never ever set near-plane to 0.

At least make it 0.01 (1cm), otherwise you’ll have sever z-fighting near your far-plane.