glPolygonOffset Needing Extreme Values



Hi. I'm trying to draw an outline around a polygonal model. Most
examples online do something like this:

draw wireframe model
offset depth by negative values
draw solid model

I tried this, but found some problems with some polygons in the solid
model appearing before closer polygons. This occurred near the edges
of the model, where I suppose the depth slope was high. I want the
solid model to appear normally, so I thought this would make more
sense:

draw solid model
offset depth by positive values
draw wireframe model

In this order, I don't need to worry about getting the parameters to
glPolygonOffset just right.

However, I'm having a really hard time getting those lines pushed back
far enough. If I call glPolygonOffset(10.0f, 10.0f), I get this
image:

http://www.cs.utk.edu/~cjohnson/forothers/teapot_low.png

The lines apparently aren't pushed back far enough, as you can see.
So, I c

all glPolygonOffset with the exorbitant parameters of 100000000.0f and
1000000000.0f, and I get:

http://www.cs.utk.edu/~cjohnson/forothers/teapot_high.png

This is what I want. But just several orders of magnitude less still
yields lines appearing before the solid model. This seems odd.

To make matters more confusing, when I draw the wireframe model, I
have to enable GL_POLYGON_OFFSET_FILL, though the polygon mode is
GL_LINE. (Using GL_POLYGON_OFFSET_LINE has no effect.) This seems to
contradict the red book's description of how glPolygonOffset works.

Here's the relevant code. The model is contained in a display list,
and just contains a call to glutSolidTeapot or a gluSphere.

glCallList(object_list + list_offset);

/* It doesn't make sense to me why polygon offset needs to be on
* for fill mode and not line, but this is the only way it works.
*/
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glPolygonOffset(100000000.0f, 1000000000.0f);
glLineWidth(6.0f);
glDisable(GL_LIGHTING);
glColor3fv(rgb);
glCallList(object_list + list_offset);
glLineWidth(1.0f);
glEnable(GL_LIGHTING);
glDisable(GL_POLYGON_OFFSET_FILL);

glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

zNear and zFar are reasonably set to 0.1 and 200.0f. I think this is
reasonable, isn't it? If anyone can offer any explanation of why I
need to use OFFSET_FILL and why I need such large values to make a
difference, I'd appreciate it.

- Chris

.



Relevant Pages

  • Re: glPolygonOffset Needing Extreme Values
    ... draw wireframe model ... but found some problems with some polygons in the solid ... solid model to appear normally, so I thought this would make more ...
    (comp.graphics.api.opengl)
  • Re: glPolygonOffset Needing Extreme Values
    ... draw wireframe model ... but found some problems with some polygons in the solid ... solid model to appear normally, so I thought this would make more ...
    (comp.graphics.api.opengl)
  • Re: Polygon missing vertex
    ... draw a Polygon, it handles it, like it is a Triangle-Fan. ... That's why you cannot draw convex Polygons. ... Just Remember OGL has to handle everything as Triangles, even if you wont see first. ... So as fungus said, OGL can't handle non-convex polygons, but sometimes you can get it handle this right. ...
    (comp.graphics.api.opengl)
  • Two points in an IFS at the same coordinates dont render
    ... I am currently having troubles displaying an IFS which contains polygons, ... I need to draw a quadrangle, ... Jonas Huckestein ...
    (comp.lang.vrml)
  • How to "draw" (print) "graphics" on black text screen (console) - text mode
    ... I would like to "draw" polygons on console screen in "text ... to draw '**'s instead of lines. ... activate polygon methods and see it on screen, ... how do I do gotoXYin black console screen. ...
    (comp.lang.java.help)