GL_POLYGON fill problem

In my program i get several polgons through image processing. When drawing these with GL_LINE_LOOP all goes well, but when I swicth to GL_POLYGON, the fill skips a few corners, probably normal behaviour, but i want to know how to draw the entire shape correctly.

See the image for an example shape. How can i make sure that i wind up with the figure on the left filled with a pure white and not the figure on the right.

Thanx!

If you would just like to draw the shape on the left filled. Try
ofFill();
ofBeginShape();
ofVertex(x1, y1);
… etc
ofEndShape(true);

You can see more on how to use this in the polyShapeExample/

If you want to do it directly in openGL (it will be more calculations for you but faster for filled shapes) you can check the docs here:
http://www.cs.utk.edu/~vose/c-stuff/opengl/glEnd.html

I think the way the GL_POLYGON and GL_TRIANGLE_FAN work is that the first two points specify the first two points of the first triangle and then every point after is used to make a new triangle from the previous two vertexes. This means that you can’t just give openGL an outline of the shape you want to draw - but instead all the points for the shape as represented by a series of triangles.

That is why ofBeginShape is nice - you don’t have to figure out the triangulation yourself :smiley:

Print out these guys and tape them up close to your workstation, works for me :slight_smile:

OpenGL primitives:
http://www.cs.uregina.ca/Links/class-in-…-itives.png

OpenGL texture coordinates:
http://www.gmonline.demon.co.uk/cscene/CS8/texcoord.jpg

oh wow - thats awesome!
printing right now :smiley:

[quote author=“theo”]If you would just like to draw the shape on the left filled. Try
ofFill();
ofBeginShape();
ofVertex(x1, y1);
… etc
ofEndShape(true);
[/quote]

Feel kind of stupid, of course this works. Got my mind set to GL that it was hard to get it out of there. For now this works, untill speed-issues arise of course :stuck_out_tongue:

Thanks a lot!