PDA

View Full Version : glPolygonMode problem



michele
06-14-2005, 02: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;

http://photos1.blogger.com/img/247/3223/640/ok.jpg

while here you can see the wrong visualization:
http://photos1.blogger.com/img/247/3223/640/ko.jpg

the gray area is the border of the picture box.

thank you.
michele

dorbie
06-14-2005, 02: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.

michele
06-14-2005, 02: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:

http://photos1.blogger.com/img/247/3223/640/primitives.jpg

anyway i'll keep on trying...tanx

dorbie
06-14-2005, 02: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.

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

Relic
06-14-2005, 04: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
flags."

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

dorbie
06-14-2005, 05: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.

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

dorbie
06-14-2005, 05: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.

Relic
06-14-2005, 06: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.

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