glPolygonOffset problem

Hi, I drawing in a OpenGL scene a lot of coplanar polygons.

How I use “glPolygonOffset” in order to resolve z-fight problem.

I do not know setup the units and factors parameters correctly.

thanks.

Yea - I would appreciate some tips from the Gurus about this - I’m using pg offset (successfully) but haven’t got a fugging clue what the parameters actually mean - I just plugged in some values until it looked nice!

The blue\red book is vague in the extreme (as is SuperBible).

Did you try the all singing and dancing and generally wonderful FAQ ?

Yes, I already have readed it.

I setup the scene with…

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);

I set the polygon offset…

glEnable (GL_POLYGON_OFFSET_FILL);
glDisable(GL_POLYGON_OFFSET_LINE);
glPolygonOffset(100.0f, 0.0f);
glPolygonMode(GL_FRONT, GL_FILL);

and with the “gluTessXXXX” functions I draw the polygons.

When the z-world is colineal whith then z-coordinate of the camera, it works fine. But the camera rotate then some polygons are not fully drawed above previous poloygon layers.

thank your reply.

I think I’ve answered that one in this thread .

HTH

Thanks for that - makes sense (phew).

I must remember to search before I post…
I must remember to search before I post…
I must remember to search before I post…
I must remember to search before I post…
I must remember to search before I post…
I must remember to search before I post…
I must remember to search before I post…
I must remember to search before I post…

my “glPolygonOffset” does not work.

zNear/zFar ratio of the “gluPerspective()” must be between some values ???

I think but I do not calculate then zNear and zFar values correctly for my large terrain viewer and then my z-buffer contains “trash”.

Push your near plane out and pull your far plane in. If that helps, your problem wasn’t PolygonOffset but depth buffer precision.

Why not just do glDepthFunc(GL_LEQUAL);

as long as your z-mapping is the typical format (otherwise, GL_GEQUAL)

I have read and experimented with glPolygonOffset. All it does is it adds an offset to the polygons you render when it is enabled. The problem is, for it to work, the polygons are quite visibly offsetted and it looks ugly. hmmm, perhaps my znear and zfar didnt help either.

V-man

Originally posted by V-man:
[b]
I have read and experimented with glPolygonOffset. All it does is it adds an offset to the polygons you render when it is enabled. The problem is, for it to work, the polygons are quite visibly offsetted and it looks ugly. hmmm, perhaps my znear and zfar didnt help either.

V-man[/b]

I have been using polygon offset too. For the ugly look, I notice on some old ATI cards, the offset looks very different(and ugly) from other implementations.

Try this:

glPolygonOffset(1.0f, 2.0f);

The second parameter is the more important for coplanar polys and 1.0 should work here but I suggest 2 to be on the save side, increase this until it works, but understand results will vary from card to card. 100 is an insanely large number and you had it on the first parameter, which means you only get offset on polys which slope into the screen, and then you probably get too much offset.

I also wouldn’t assume that offset fill and offset line are completely orthoogonal, they should be but I doubt it’s tested, so if you still have problems look there.

V-man, because of limited precision the less than or equal test will not work except under special circumstances, and even then only on some cards.

[This message has been edited by dorbie (edited 04-04-2002).]

I’ve tried values between 1 and 3 (blindly) and it wasnt sufficient. I programmed code to dynamically change both factor and unit (with keyboard) and I noticed that values that didnt show noticeable offsetting, showed z-fighting and vice-versa.

My conclusion was that glPolygonOffset is not much different than from doing glVertex3f(x, y, z+zoffset) (with zoffset computed on a per vertex basis)

Reading the red book gave me the impression that plugging in 1.0 for each parameter is good enough. Nope, it is not!

V-man

If you can’t use polygon offset without visually shifting your geometry around, you most likely have depth precision problems. Push out the near plane as far as you can manage.

V-man, your reading of the manual is correct, it should work as you interpreted it, are you sure you glEnabled it for filled polys?