PDA

View Full Version : glPolygonOffset (more info required).......



Robbo
04-04-2002, 12:57 PM
glEnable ( GL_POLYGON_OFFSET_FILL );
glPolygonOffset ( 1.0f, 1.0f );

// Draw something (cylinder)

{
...
}

glPolygonOffset ( 1.0f, 2.0f );

// Draw perturbed cylinder inside cylinder above (some points touch the outer one)!

{
...
}

Result? Well, its hard to predict by looking at the numbers I plugged in. I'm getting some `sparkling' - you know, odd pixels flashing on\off with the inner then outer cylinder as it rotates.

I've read the other threads about pg offset, but still can't quite get my head around exactly what its doing. Please enlighten me.

(p.s. I consider this to be advanced - apologies if you gurus don't!)

zeckensack
04-04-2002, 01:59 PM
First, make sure your depth precision is ok. Look at how your projection matrix is set up. A near value of less than 0.5 is going to get you in trouble. Try using at least 1.0 for now.

If that's not it, try using glDepthFunc(GL_LEQUAL) instead of GL_LESS.

Then - on a sidenote - it shouldn't really be necessary to apply a polygon offset to the first layer (outer cylinder in your case). You should be able disable that for the first layer, in turn increasing your effective polygon offset.

If this all doesn't help, or you already tried that, let me know. http://www.opengl.org/discussion_boards/ubb/smile.gif

dorbie
04-04-2002, 02:12 PM
This function is a mess and shouldn't be. The root of the problem is that the conformance test is willfully deficient.

There are two parameters, one is absolute offset, in units where one should guarantee minimum separation. The other is a gradient based offset scale in multiples of delta z between adjacent fragments which is useful compensating for rounding or imprecise interpolation and when drawing 2D primitives with width on offset surfaces.

You should probably increase factor not just units for multiple offset layers because of imprecise z, but you probably want to make units more than 1.0 because the conformance test has a stupidly simple polygon with an offset of 4.

This may be plain broken on some implementations requiring an offser of perhaps 4, on others an offset of 4 (or even 1) will be insanely large and you will get punchthrough on objects or just crazy Z values (because of vendor confusion with the EXT extension).

This is not a good situation in screwing up the conformance test the opportunity was lost in the move to alter units in the move from EXT to core function.

The situation may have improved on PC cards since I last looked at this.

Robbo
04-08-2002, 02:47 AM
Originally posted by zeckensack:
First, make sure your depth precision is ok. Look at how your projection matrix is set up. A near value of less than 0.5 is going to get you in trouble. Try using at least 1.0 for now.

If that's not it, try using glDepthFunc(GL_LEQUAL) instead of GL_LESS.

Then - on a sidenote - it shouldn't really be necessary to apply a polygon offset to the first layer (outer cylinder in your case). You should be able disable that for the first layer, in turn increasing your effective polygon offset.

If this all doesn't help, or you already tried that, let me know. http://www.opengl.org/discussion_boards/ubb/smile.gif

Yes - I don't do it for the outside cylinder - I do it for the middle layer and the inner layer - I wouldn't need to show the middle layer at all except I'm using alpha test to show holes in the inner layers such that the outer layer can show through in certain circumstances.

Now - I'll give your other ideas a quick try... Hold on!

Robbo
04-08-2002, 01:02 PM
Stupid me.

Now using a 24bit depth buffer and everything is cool.

Coconut
04-09-2002, 09:04 AM
Originally posted by Robbo:
Stupid me.

Now using a 24bit depth buffer and everything is cool.

What graphics card do you have?

Robbo
04-10-2002, 02:28 AM
I have a GF 2 MX - now I didn't think they supported 24 bit depth buffers - oh well! Seems ok now - no polygon offset is being used (a bit of z fighting).