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 )

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org