glpolygonoffset problem

  • Follow


I have some unexpected behaviour coming from glPolygonOffset. I draw my 
object using GL_TRIANGLE_STRIP and everything comes out as expected. i.e.

glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(0.0, 1.0);
glPolygonMode(GL_FRONT, GL_FILL);
glBegin(GL_TRIANGLE_STRIP);
......
glEnd();
glDisable(GL_POLYGON_OFFSET_FILL);

This works great. Immediately following this I try and draw a black depth 
offset border so I use:

glColor3f(0.0f,0.0f,0.f);
glPolygonMode(GL_FRONT, GL_LINE);
glBegin(GL_POLYGON);
......
glEnd();

For some of my object the border looks nice but for this latest object the 
border doesn't follow the contour nicely. It seems to be missing some pixels 
or something at some the corners. I even tried increasing the size of the 
object and it is still a problem. It draws a black line following the 
contour of the object until it reaches a corner and then doesn't draw fill a 
black pixel at the corner. It looks bad.

Any suggestions?

Thanks


0
Reply slycaper 1/19/2005 4:45:12 PM

slycaper wrote:
> I have some unexpected behaviour coming from glPolygonOffset.

glPolygonOffset() hardly ever works properly. My advice
is: "Don't use PolygonOffset()!". The parameters are
very hard to get right (they depend on the angle of the
polygon into the screen) and there's always a better,
more reliable way to do whatever it is you're trying
to do. If I was king PolygonOffset would be history.

eg. To outline a polygon you have a few choices:

If stencil is available, draw the line and set the
stencil buffer to some value (eg. 1) at the same time.
Now draw the polygon except where the stencil buffer
is 1, clear the stencil buffer as you draw it.

If no stencil, disable depth buffer write. Draw the
polygon. Draw the outline. Enable depth write, disable
color write. Draw the polygon. Enable color write.


-- 
<\___/>
/ O O \
\_____/  FTB.    For email, remove my socks.

Governments, like diapers, should be changed often,
and for the same reason.
0
Reply fungus 1/19/2005 6:24:08 PM


"slycaper" <sly_caper@(NOSPAM)yahoo.com> wrote in message 
news:s8wHd.36321$06.17989@clgrps12...
> glPolygonOffset(0.0, 1.0);

With the 'factor' parameter set to zero, polygon offset won't work unless 
your  polygon is exactly face-on to the viewer.

Polygon offset always works fine for me when I use:
    glPolygonOffset( 1.0, 1.0 );

Note that positive 'factor' and 'bias' push geometry back into the depth 
buffer; that's what you want in this case.
   -Paul 


0
Reply Paul 1/19/2005 8:22:37 PM

"fungus" <openglMY@SOCKSartlum.com> wrote in message 
news:eBxHd.13770$US.641@news.ono.com...
> glPolygonOffset() hardly ever works properly.

Really?!? I've never encountered a problem with it myself. Can you post some 
code that shows it not working properly? Have you reported it as a bug to 
your graphics hardware manufacturer?
   -Paul 


0
Reply Paul 1/19/2005 8:24:09 PM

Paul Martz wrote:
> "fungus" <openglMY@SOCKSartlum.com> wrote in message 
> news:eBxHd.13770$US.641@news.ono.com...
> 
>>glPolygonOffset() hardly ever works properly.
> 
> 
> Really?!? I've never encountered a problem with it myself. Can you post some 
> code that shows it not working properly? Have you reported it as a bug to 
> your graphics hardware manufacturer?
>   

I mean it hardly ever obeys your will.


-- 
<\___/>
/ O O \
\_____/  FTB.    For email, remove my socks.
0
Reply fungus 1/19/2005 8:39:42 PM

My polygon's are exactly "face on" the viewer. I'm only using 2D right now. 
Unfortunately glPolygonOffset( 1.0, 1.0 ); didn't make any difference. 
Polygon offseting works fine on some objects but not others.


"Paul Martz" <pmartz-at-frii-dot-com> wrote in message 
news:41eec17e$0$206$75868355@news.frii.net...
> "slycaper" <sly_caper@(NOSPAM)yahoo.com> wrote in message 
> news:s8wHd.36321$06.17989@clgrps12...
>> glPolygonOffset(0.0, 1.0);
>
> With the 'factor' parameter set to zero, polygon offset won't work unless 
> your  polygon is exactly face-on to the viewer.
>
> Polygon offset always works fine for me when I use:
>    glPolygonOffset( 1.0, 1.0 );
>
> Note that positive 'factor' and 'bias' push geometry back into the depth 
> buffer; that's what you want in this case.
>   -Paul
> 


0
Reply slycaper 1/19/2005 8:45:41 PM

slycaper wrote:
> My polygon's are exactly "face on" the viewer. I'm only using 2D right now. 
> Unfortunately glPolygonOffset( 1.0, 1.0 ); didn't make any difference. 
> Polygon offseting works fine on some objects but not others.
> 

Try a glTranslate() towards you. It's the same thing
but a lot easier to understand and figure out a
suitable value for.

One "depth step" = (far-near)/(2^depth_buffer_bits)

To avoid floating point rounding errors translate by
three or four depth steps.



-- 
<\___/>
/ O O \
\_____/  FTB.    For email, remove my socks.

Governments, like diapers, should be changed often,
and for the same reason.
0
Reply fungus 1/19/2005 9:35:19 PM

Thanks.

I did actually try the stencil buffer just now and that is resulting in the 
same problem. It actually does appear to be size dependent. I tried drawing 
small portions of my object and they appear choppy however the larger parts 
appear as expected. Here is example of what I have. This example is only of 
a small rectangle that is part of the object
glNewList(_displaylist, GL_COMPILE);
    glClearStencil(0);
    glClear(GL_STENCIL_BUFFER_BIT);
    glEnable(GL_STENCIL_TEST);
    glStencilFunc(GL_ALWAYS, 1, -1);
    glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);


    // Draw outline
    glColor3f(0.0f,0.0f,0.f);
    glPolygonMode(GL_FRONT, GL_LINE);
    glBegin(GL_POLYGON);        /// tried GL_LINE_LOOP with no luck
        glVertex2f(x17,y17);
        glVertex2f(x18,y18);
        glVertex2f(x19,y19);
        glVertex2f(x20,y20);
    glEnd();


    glStencilFunc(GL_NOTEQUAL, 1, -1);
    glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
    glPolygonMode(GL_FRONT, GL_LINE);
    glColor3f(1.0f,0.0f,0.f);
    glPolygonMode(GL_FRONT, GL_FILL);

    // Draw filled object
    glBegin(GL_POLYGON);
        glVertex2f(x17,y17);
        glVertex2f(x18,y18);
        glVertex2f(x19,y19);
        glVertex2f(x20,y20);
    glEnd();

    glDisable(GL_STENCIL_TEST);
glEndList();

19        18
+-------+
|             |
|             |
|             |
+-------+
20        17

My object is missing a small pixel "chunk" from vertices 18 & 19.



"fungus" <openglMY@SOCKSartlum.com> wrote in message 
news:eBxHd.13770$US.641@news.ono.com...
> slycaper wrote:
>> I have some unexpected behaviour coming from glPolygonOffset.
>
> glPolygonOffset() hardly ever works properly. My advice
> is: "Don't use PolygonOffset()!". The parameters are
> very hard to get right (they depend on the angle of the
> polygon into the screen) and there's always a better,
> more reliable way to do whatever it is you're trying
> to do. If I was king PolygonOffset would be history.
>
> eg. To outline a polygon you have a few choices:
>
> If stencil is available, draw the line and set the
> stencil buffer to some value (eg. 1) at the same time.
> Now draw the polygon except where the stencil buffer
> is 1, clear the stencil buffer as you draw it.
>
> If no stencil, disable depth buffer write. Draw the
> polygon. Draw the outline. Enable depth write, disable
> color write. Draw the polygon. Enable color write.
>
>
> -- 
> <\___/>
> / O O \
> \_____/  FTB.    For email, remove my socks.
>
> Governments, like diapers, should be changed often,
> and for the same reason. 


0
Reply slycaper 1/19/2005 9:41:41 PM

It appears that the offsetting isn't even the problem. I rendered the object 
in line mode only and it had the same choppy result. If I do the filled for 
it looks fine.

"slycaper" <sly_caper@(NOSPAM)yahoo.com> wrote in message 
news:puAHd.36428$06.36398@clgrps12...
> Thanks.
>
> I did actually try the stencil buffer just now and that is resulting in 
> the same problem. It actually does appear to be size dependent. I tried 
> drawing small portions of my object and they appear choppy however the 
> larger parts appear as expected. Here is example of what I have. This 
> example is only of a small rectangle that is part of the object
> glNewList(_displaylist, GL_COMPILE);
>    glClearStencil(0);
>    glClear(GL_STENCIL_BUFFER_BIT);
>    glEnable(GL_STENCIL_TEST);
>    glStencilFunc(GL_ALWAYS, 1, -1);
>    glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
>
>
>    // Draw outline
>    glColor3f(0.0f,0.0f,0.f);
>    glPolygonMode(GL_FRONT, GL_LINE);
>    glBegin(GL_POLYGON);        /// tried GL_LINE_LOOP with no luck
>        glVertex2f(x17,y17);
>        glVertex2f(x18,y18);
>        glVertex2f(x19,y19);
>        glVertex2f(x20,y20);
>    glEnd();
>
>
>    glStencilFunc(GL_NOTEQUAL, 1, -1);
>    glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
>    glPolygonMode(GL_FRONT, GL_LINE);
>    glColor3f(1.0f,0.0f,0.f);
>    glPolygonMode(GL_FRONT, GL_FILL);
>
>    // Draw filled object
>    glBegin(GL_POLYGON);
>        glVertex2f(x17,y17);
>        glVertex2f(x18,y18);
>        glVertex2f(x19,y19);
>        glVertex2f(x20,y20);
>    glEnd();
>
>    glDisable(GL_STENCIL_TEST);
> glEndList();
>
> 19        18
> +-------+
> |             |
> |             |
> |             |
> +-------+
> 20        17
>
> My object is missing a small pixel "chunk" from vertices 18 & 19.
>
>
>
> "fungus" <openglMY@SOCKSartlum.com> wrote in message 
> news:eBxHd.13770$US.641@news.ono.com...
>> slycaper wrote:
>>> I have some unexpected behaviour coming from glPolygonOffset.
>>
>> glPolygonOffset() hardly ever works properly. My advice
>> is: "Don't use PolygonOffset()!". The parameters are
>> very hard to get right (they depend on the angle of the
>> polygon into the screen) and there's always a better,
>> more reliable way to do whatever it is you're trying
>> to do. If I was king PolygonOffset would be history.
>>
>> eg. To outline a polygon you have a few choices:
>>
>> If stencil is available, draw the line and set the
>> stencil buffer to some value (eg. 1) at the same time.
>> Now draw the polygon except where the stencil buffer
>> is 1, clear the stencil buffer as you draw it.
>>
>> If no stencil, disable depth buffer write. Draw the
>> polygon. Draw the outline. Enable depth write, disable
>> color write. Draw the polygon. Enable color write.
>>
>>
>> -- 
>> <\___/>
>> / O O \
>> \_____/  FTB.    For email, remove my socks.
>>
>> Governments, like diapers, should be changed often,
>> and for the same reason.
>
> 


0
Reply slycaper 1/19/2005 9:57:56 PM

Do you have a depth buffer?
   -Paul

"slycaper" <sly_caper@(NOSPAM)yahoo.com> wrote in message 
news:VFzHd.36366$06.31450@clgrps12...
> My polygon's are exactly "face on" the viewer. I'm only using 2D right 
> now. Unfortunately glPolygonOffset( 1.0, 1.0 ); didn't make any 
> difference. Polygon offseting works fine on some objects but not others.
>
>
> "Paul Martz" <pmartz-at-frii-dot-com> wrote in message 
> news:41eec17e$0$206$75868355@news.frii.net...
>> "slycaper" <sly_caper@(NOSPAM)yahoo.com> wrote in message 
>> news:s8wHd.36321$06.17989@clgrps12...
>>> glPolygonOffset(0.0, 1.0);
>>
>> With the 'factor' parameter set to zero, polygon offset won't work unless 
>> your  polygon is exactly face-on to the viewer.
>>
>> Polygon offset always works fine for me when I use:
>>    glPolygonOffset( 1.0, 1.0 );
>>
>> Note that positive 'factor' and 'bias' push geometry back into the depth 
>> buffer; that's what you want in this case.
>>   -Paul
>>
>
> 


0
Reply Paul 1/19/2005 10:18:03 PM

Yes. Here are some of the method calls I have in my control. They are not 
all in the same function though.

///////////////
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

//////////////
static PIXELFORMATDESCRIPTOR pfd =
{
sizeof (PIXELFORMATDESCRIPTOR), // strcut size
1, // Version number
PFD_DRAW_TO_WINDOW | // Flags, draw to a window,
PFD_SUPPORT_OPENGL | // use OpenGL
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA, // RGBA pixel values
24, // 24-bit color
0, 0, 0, // RGB bits & shift sizes.
0, 0, 0, // Don't care about them
0, 0, // No alpha buffer info
0, 0, 0, 0, 0, // No accumulation buffer
32, // 32-bit depth buffer               ------------> depth
0, // No stencil buffer
0, // No auxiliary buffers
0, // Layer type (Ignored)
0, // Reserved (must be 0)
0, // No layer mask (Ignored)
0, // No visible mask (Transparent colour in RGBA mode)
0 // No damage mask (Ignored)
};

////////////////////
glEnable(GL_DEPTH_TEST); // Enable depth testing.
////////////////////

Thanks


"Paul Martz" <pmartz-at-frii-dot-com> wrote in message 
news:41eedc8b$0$207$75868355@news.frii.net...
> Do you have a depth buffer?
>   -Paul
>
> "slycaper" <sly_caper@(NOSPAM)yahoo.com> wrote in message 
> news:VFzHd.36366$06.31450@clgrps12...
>> My polygon's are exactly "face on" the viewer. I'm only using 2D right 
>> now. Unfortunately glPolygonOffset( 1.0, 1.0 ); didn't make any 
>> difference. Polygon offseting works fine on some objects but not others.
>>
>>
>> "Paul Martz" <pmartz-at-frii-dot-com> wrote in message 
>> news:41eec17e$0$206$75868355@news.frii.net...
>>> "slycaper" <sly_caper@(NOSPAM)yahoo.com> wrote in message 
>>> news:s8wHd.36321$06.17989@clgrps12...
>>>> glPolygonOffset(0.0, 1.0);
>>>
>>> With the 'factor' parameter set to zero, polygon offset won't work 
>>> unless your  polygon is exactly face-on to the viewer.
>>>
>>> Polygon offset always works fine for me when I use:
>>>    glPolygonOffset( 1.0, 1.0 );
>>>
>>> Note that positive 'factor' and 'bias' push geometry back into the depth 
>>> buffer; that's what you want in this case.
>>>   -Paul
>>>
>>
>>
>
> 


0
Reply slycaper 1/19/2005 10:26:24 PM

slycaper wrote:
> 
>>I did actually try the stencil buffer just now and that is resulting in 
>>the same problem. It actually does appear to be size dependent. I tried 
>>drawing small portions of my object and they appear choppy however the 
>>larger parts appear as expected. Here is example of what I have. This 
>>example is only of a small rectangle that is part of the object
>>glNewList(_displaylist, GL_COMPILE);
>>   glClearStencil(0);
>>   glClear(GL_STENCIL_BUFFER_BIT);
>>   glEnable(GL_STENCIL_TEST);
>>   glStencilFunc(GL_ALWAYS, 1, -1);
>>   glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
>>

I forgot:

glDepthMask(GL_FALSE);

>>
>>   // Draw outline
>>   glColor3f(0.0f,0.0f,0.f);
>>   glPolygonMode(GL_FRONT, GL_LINE);
>>   glBegin(GL_POLYGON);        /// tried GL_LINE_LOOP with no luck
>>       glVertex2f(x17,y17);
>>       glVertex2f(x18,y18);
>>       glVertex2f(x19,y19);
>>       glVertex2f(x20,y20);
>>   glEnd();
>>
>>
>>   glStencilFunc(GL_NOTEQUAL, 1, -1);
>>   glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
>>   glPolygonMode(GL_FRONT, GL_LINE);
>>   glColor3f(1.0f,0.0f,0.f);
>>   glPolygonMode(GL_FRONT, GL_FILL);
>>

glDepthMask(GL_TRUE);

>>   // Draw filled object
>>   glBegin(GL_POLYGON);
>>       glVertex2f(x17,y17);
>>       glVertex2f(x18,y18);
>>       glVertex2f(x19,y19);
>>       glVertex2f(x20,y20);
>>   glEnd();
>>
>>   glDisable(GL_STENCIL_TEST);
>>glEndList();
>>
>>19        18
>>+-------+
>>|             |
>>|             |
>>|             |
>>+-------+
>>20        17
>>
>>My object is missing a small pixel "chunk" from vertices 18 & 19.
>>
>>
>>
>>"fungus" <openglMY@SOCKSartlum.com> wrote in message 
>>news:eBxHd.13770$US.641@news.ono.com...
>>
>>>slycaper wrote:
>>>
>>>>I have some unexpected behaviour coming from glPolygonOffset.
>>>
>>>glPolygonOffset() hardly ever works properly. My advice
>>>is: "Don't use PolygonOffset()!". The parameters are
>>>very hard to get right (they depend on the angle of the
>>>polygon into the screen) and there's always a better,
>>>more reliable way to do whatever it is you're trying
>>>to do. If I was king PolygonOffset would be history.
>>>
>>>eg. To outline a polygon you have a few choices:
>>>
>>>If stencil is available, draw the line and set the
>>>stencil buffer to some value (eg. 1) at the same time.
>>>Now draw the polygon except where the stencil buffer
>>>is 1, clear the stencil buffer as you draw it.
>>>
>>>If no stencil, disable depth buffer write. Draw the
>>>polygon. Draw the outline. Enable depth write, disable
>>>color write. Draw the polygon. Enable color write.
>>>
>>>
>>>-- 
>>><\___/>
>>>/ O O \
>>>\_____/  FTB.    For email, remove my socks.
>>>
>>>Governments, like diapers, should be changed often,
>>>and for the same reason.
>>
>>
> 
> 


-- 
<\___/>
/ O O \
\_____/  FTB.    For email, remove my socks.

Governments, like diapers, should be changed often,
and for the same reason.
0
Reply fungus 1/19/2005 10:48:44 PM

fungus wrote:
> slycaper wrote:
> 
>> My polygon's are exactly "face on" the viewer. I'm only using 2D right 
>> now. Unfortunately glPolygonOffset( 1.0, 1.0 ); didn't make any 
>> difference. Polygon offseting works fine on some objects but not others.
>>
> 
> Try a glTranslate() towards you. It's the same thing
> but a lot easier to understand and figure out a
> suitable value for.
> 
> One "depth step" = (far-near)/(2^depth_buffer_bits)
> 
> To avoid floating point rounding errors translate by
> three or four depth steps.

I usually used glDepthRange rather than glTranslate. Neither will help 
much with polygons that are at an angle to the screen.

I certainly agree with you that polygon offset is a hack.

--
Andy V
0
Reply Andy 1/20/2005 1:22:02 AM

Andy V wrote:
> fungus wrote:
> 
>> Try a glTranslate() towards you. It's the same thing
>> but a lot easier to understand and figure out a
>> suitable value for.
>>
> 
> I usually used glDepthRange rather than glTranslate. 

So you admit you don't use glPolygonOffset()? :-)

> Neither will help 
> much with polygons that are at an angle to the screen.
> 


In 2d a simple glTranslate() should work perfectly.
In 3D you have to translate in W which is slightly
trickier but works better than glPolygonOffset().

For pixel-perfection you have to use the stencil and
glDepthMask() tricks though.


> I certainly agree with you that polygon offset is a hack.
> 

It does nothing that you can't do better with other
functions. It might have been useful if it wrote
the original (non-offset) depth values into the depth
buffer but it doesn't.


-- 
<\___/>
/ O O \
\_____/  FTB.    For email, remove my socks.

Governments, like diapers, should be changed often,
and for the same reason.
0
Reply fungus 1/20/2005 5:21:57 AM

Yes, rendering just the lines is giving me the same bad result. The filled 
primitive looks fine. I've tried line width > 1 and it just amplifies the 
problem. The rectangle polygon looks as if it's a circle if the line width 
is large enough. (missing several pixels at each of the joints).

"Andy V" <nobody@nowhere.togo> wrote in message 
news:bKDHd.141$vM4.22040@petpeeve.ziplink.net...
> slycaper wrote:
>> For some of my object the border looks nice but for this latest object 
>> the border doesn't follow the contour nicely. It seems to be missing some 
>> pixels or something at some the corners. I even tried increasing the size 
>> of the object and it is still a problem. It draws a black line following 
>> the contour of the object until it reaches a corner and then doesn't draw 
>> fill a black pixel at the corner. It looks bad.
>
> Are you using a line width > 1? Are you running into the problem that 
> OpenGL lines don't have good joints? What if you just render the lines and 
> not the filled area -- do you get similar results?
>
> --
> Andy V 


0
Reply slycaper 1/20/2005 2:59:27 PM

slycaper wrote:
> Yes, rendering just the lines is giving me the same bad result. The filled 
> primitive looks fine. I've tried line width > 1 and it just amplifies the 
> problem. The rectangle polygon looks as if it's a circle if the line width 
> is large enough. (missing several pixels at each of the joints).

If you need better line joints, you will have to do it with polygons. 
OpenGL lines just do not have good joints.

--
Andy V
0
Reply Andy 1/21/2005 2:03:27 AM

15 Replies
496 Views

(page loaded in 0.141 seconds)

Similiar Articles:


















7/24/2012 8:44:44 AM


Reply: