PDA

View Full Version : glPolygonOffset problem



ahuarte
04-04-2002, 02:59 AM
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.

Robbo
04-04-2002, 03:51 AM
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).

harsman
04-04-2002, 03:57 AM
Did you try the all singing and dancing and generally wonderful FAQ (http://www.opengl.org/developers/faqs/technical/polygonoffset.htm) ?

ahuarte
04-04-2002, 04:33 AM
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.

zeckensack
04-04-2002, 05:10 AM
I think I've answered that one in this thread (http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/005844.html) .

HTH http://www.opengl.org/discussion_boards/ubb/smile.gif

Robbo
04-04-2002, 05:35 AM
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....

ahuarte
04-04-2002, 07:31 AM
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".

http://www.opengl.org/discussion_boards/ubb/confused.gif

harsman
04-04-2002, 09:21 AM
Push your near plane out and pull your far plane in. If that helps, your problem wasn't PolygonOffset but depth buffer precision.

V-man
04-04-2002, 12:36 PM
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

Coconut
04-04-2002, 12:44 PM
Originally posted by V-man:

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


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.

dorbie
04-04-2002, 02:19 PM
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.

dorbie
04-04-2002, 02:22 PM
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).]

V-man
04-05-2002, 01:36 PM
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

zeckensack
04-05-2002, 01:55 PM
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.

dorbie
04-05-2002, 02:59 PM
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?