View Full Version : Having trouble with clipping and edge flags

Victor Villagomez
06-27-2009, 04:37 PM
Hello everyone,

First a bit of background:

http://img218.imageshack.us/img218/8470/fulltriangle.th.png (http://img218.imageshack.us/i/fulltriangle.png/)

When drawing a polygon in GL_LINE mode with a user defined clipping plane, Opengl will use the newly created verteces (from the clipping) to recontruct the edge on the cutting plane as shown in the image below.

http://img34.imageshack.us/img34/9969/clippedtriangle.th.jpg (http://img34.imageshack.us/i/clippedtriangle.jpg/)

Im trying to take advantage of this feature to eventually get the edge of the polygon that lies on the cutting plane and discard everything else. In order to do that I set an edge flag equal to false when declaring my vertices so that only the newly calculated verteces keep a value of TRUE and, thus, are the only ones to be rasterized.

glPolygonMode(GL_FRONT, GL_LINE);
glVertex3i(-8, -4, 0);
glVertex3i(8, -4, 0);
glVertex3i(0, 4, 0);

The problem is that this trick doesnt work for me as all I see after doing this is a black screen. Its as if the false flag was set to all verteces including the newly created ones.

But I dont understand why. After all the opengl documentation on clipping says that "... 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."

Does any one have any idea as to why the edge flag trick is not working?. Can anyone reproduce the trick? Any idea or suggestion will be appreciated.

06-28-2009, 04:30 AM
Relying on "clipping may require the introduction of new vertices into a polygon" seem very fragile to me.
It may only work on your computer :)

Edge flags is a very obscure feature, that I only learned about some weeks ago (after almost 10 years of tinkering with OpenGL). So maybe the spec is not exactly followed on this. If you manually switch on and off the edge flag, on the smae triangle, does it works as expected ?

Victor Villagomez
06-28-2009, 02:32 PM
I think it is safe to assume that Opengl will create new vertices every time the clipping process requires it. Keep in mind that I am defining my own clipping plane so that I control where the polygon will be clipped.

With respect to the edge flags, I checked and yes they switch on and off as expected ({on} you see the triangle, {off} you don't). My problem is that this 'switch' is not supposed to operate on the new vertices (the ones from the clipping). These newly created vertices have a default edgeflag set to ON and this setting should be kept no matter what I do from the client side.

At least this is my interpretation of the documentation. Is it correct?

Victor Villagomez
07-01-2009, 06:42 AM
I just realized that the trick Im trying to reproduce does work. I tried the same code on a computer with a Nvidia GPU and it worked as I expected from the documentation.

I noticed also that this trick won't work on computers with old ATIs GPU's (this was my problem). Seems that ATI implementation of OpenGL is a bit different from the specs. I dont know if this is true for their newer cards.

The reason I suspect of ATI implementation is what I read here: http://www.groupsrv.com/computers/about623878.html

Hope this may be useful to somebody somewhere