Visual Glitches

I have a sample openGL program that diplsays an object of several thousand triangles. On some machines it is OK, but on other visual glithes appear on the surface of the object when it is moved - colors on some triangles change form what it should be to black, other triangles have random black lines that appear and dissapear, other triangles have strange glittering. How to write openGL code that works fine on any computer? I define my surface properties using glColor, glMaterial anf GL_LIGHT0.

Thank you.

It is hard to say what your problem is wothout seeing a screen shot, but my guess is you’re seeing z fighting. Push your near plane out (increase the near value in your call to gluPerspective if there is one, if you set up your frustum using glFrusutm, you should know what I’m talking about).


you are right. Thank you :slight_smile:
I’ve tried different values in glPerspective, the problem is with Z buffer. But why is it working in different ways on different computers? The fulcrum that is OK on my computer is catastrophe for another and vice versa. How to make it universal for all computers??

How soon you get z-fighting depends on the number of bits available for the depth buffer pixels. Generally you ask for a certain number of bits
(e.g 16 or 24 bits are common) when creating your OpenGL window. Exactly how this is done depends on which windowing toolkit you use.

What settings for near and far to use to get sufficient precision really depends on the scene displayed, but as a rule of thumb i use a factor of 1000 difference between near and far, if near is at 0.1 far is 100 and so on. This tends to work well with 16-bit detph buffers which are fairly common. If you need more precision, make sure you ask for it.

In general pushing the near plane out gives you more precision than pulling the far plane in .