View Full Version : glPolygonMode problem

06-14-2005, 01:24 AM
i'm trying to draw some polygons and their outline.
i'm using glPolygonMode() and glPolygonOffset.
it works smmothly till all the polygon falls inside my view area.
if some of the polygon falls outside of the view area it draws also some internal lines.
it's like if the polygon is decomposed in triangles and then the outlines of each triangles are drawn.
is this effect something known or just an internal bug of my program?

to give you an idea of the problem, this picture shows some polygons correctly drawn;


while here you can see the wrong visualization:

the gray area is the border of the picture box.

thank you.

06-14-2005, 01:32 AM
The problem is due to clipping.

If a polygon is clipped novel primitives are generated. In your case it looks like you draw quads, then when they start to clip they generate new vertices and the hardware produces triangles, and even multiple triangles as seen on the top polygon.

This is normal if undesirable behavior.

You could try to simply draw outlines for your primitives with offset to prevent zfighting instead of using polygonmode.

06-14-2005, 01:53 AM
this is what i supposed(/feared)...
and yes i'm drawing quads!

i've already tried to draw the outlines using primitives and playing with glDepthRange (i found this in the faq...).
but there was *another* problem: the polygons you see are the faces of cubes, and if i draw using primitives and glDepthRange it happens that the outlines of the hidden faces are alse drawn.
as you can see here:


anyway i'll keep on trying...tanx

06-14-2005, 01:57 AM
Use glPolygonOffset to fix this. Negative units can be used for the polygon pass, don't forget to enable GL_POLYGON_OFFSET_FILL when doing this.

06-14-2005, 02:15 AM
great! it works.
thanks a lot.

06-14-2005, 03:40 AM
Originally posted by dorbie:
This is normal if undesirable behavior.

You could try to simply draw outlines for your primitives with offset to prevent zfighting instead of using polygonmode.I disagree. Spec says this:

"If the primitive is a polygon, then it is passed if every one of its edges lies
entirely inside the clip volume and either clipped or discarded otherwise. Polygon
clipping may cause polygon edges to be clipped, but because polygon connectivity
must be maintained, these clipped edges are connected by new edges that lie along
the clip volume’s boundary. Thus, clipping may require the introduction of new
vertices into a polygon. Edge flags are associated with these vertices so that edges
introduced by clipping are flagged as boundary (edge flag TRUE), and so that original
edges of the polygon that become cut off at these vertices retain their original

Means only boundary edges are drawn in polygon mode line, even when clipped.
The clipped quad should not draw the inner edges.

06-14-2005, 04:05 AM
I might tend to agree but if you read elsewhere in the spec section 3.5.4 is actually where it says;

"LINE causes edges that are tagged as boundary to be rasterized as line segments."

Your quote from section 2.12 includes;

"so that edges introduced by clipping are flagged as boundary"

So seemingly the novel clipped edges flagged as "boundary" would be drawn. I'd happily accept that the intention was different and this may be a spec problem. Clearly it's not always desirable but the spec doesn't seem to say it's wrong.

In this case the spec does seem to waste a lot of time carefully trying to say something that is ultimately clear as mud, and probably "the wrong thing" TM.

06-14-2005, 04:23 AM
I see no contradiction. Additional inner edges generated by the clipping are not on the boundary.

06-14-2005, 04:51 AM
I never claimed a contradiction I pointed to another relevant part of the spec. I don't know how a single sentence can be made any clearer, but I'll try:

"so that edges introduced by clipping are flagged as boundary"

The spec can clearly be read as not saying what you claim. I agree the behavior you describe is desirable but you reading an absolutely unequivocal statement in the spec to mean what you want it to instead of what it actually says doesn't alter the facts.

All that verbage & flags for this seems highly redundant. It makes me suspect somewhere along the lines the original idea got corrupted, it happens.

06-14-2005, 05:32 AM
Only edges building the boundary are considered. The newly added inner edges seen in the screenshots are only there because the hardware triangulates the geometry. But nobody says you have to do that. Imagine you had an advanced rasterizer which would be able to generate the whole polygon without triangulation, then there wouldn't be other edges than the boundary and this is what the clipping is about. Cut one vertex off and you get two new ones and an additional edge which is part of the boundary, nothing more.

06-14-2005, 05:45 AM
I'll buy that, I think the spec should say it clearly if that's the intent.