View Full Version : Urgent help needed on glPolygonOffset!!!!!

07-31-2000, 01:00 AM

does anyone know how to solve the "z-fighting" effect of coplanar polygons using glPolygonOffset??

For example in a situation where there are 6 overlapping triangles, how should i turn on the polygon offset, are there any limitation on the number of decals i can have?

pls reply fast, thanks a lot!!!

07-31-2000, 02:50 AM
In your case I would draw the "base" polygon at the desired z depth. Then, assuming your depth compare func is GL_LESS, glEnable(GL_POLYGON_OFFSET_FILL), start with glPolygonOffset(-1.0, 0.0) for the first polygon, and so forth with parameter factor=-2, -3, -4, -5.
That should do the trick for filled primitives.
Thinking about it, for better overdraw performance, perhaps start with the front one first, so that more depth tests fail.

07-31-2000, 04:42 PM
Hi! Thanks for your prompt reply, it does help to solve a part of my problem but failed to remove a bug which i have encountered earlier.

When i set the camera to be looking straight at 6 upright triangles lying on the same z-plane, the "z-fighting" effect is still visible, unless the camera is rotated to look at the triangles at an angle, why is this so?

is offset -1 to -5 too big a value?

Kilam Malik
07-31-2000, 09:10 PM
The first parameter of the glPolygonOffset is multiplicated with the change of z over the triangle. So if the triangle lies parallel to the camera, there is no "delta z" and you get no offsetting. The second parameter from glPolygonOffset is simply added to the z-Buffer when drawing the triangle. So if you put in here a value too it should work.


07-31-2000, 10:39 PM
Yup, thanks.
Interestingly it doesn't happen in the TOffset demo in the MSSDK from which defaults I hacked the answer.
So to all of you out there: If someone gives you advice on an OpenGL function, always looks up the manual for it. :eek:

07-31-2000, 11:27 PM
Thanks Relic n Kilam, I managed to solve the problem, case closed!!

Apparently, the mistake I made was that the increments I made to both parameters in glPolygonOffset was too small, n thus could not resolve the "z-fighting"! Many thanks again!!