Drawing concave polygons HELP!

I have to draw convex and concave polygons. By clicking the mouse, the user adds a point and the polygon updates itself.
How can I do it?
I appreciate your help.
LD

PS: Polygon in 2D

[This message has been edited by fandecine (edited 10-14-2002).]

I would just try to break the poly into tris if that fits into your app.

Sorry but I don’t know what you mean. How do you do it?

lets say your poly has 5 verts:

v1----v2
| /
| v3
|
v5----v4

build a method to convert the poly into triangles:

v1----v2
| \ /
| v3
| /
v5----v4

see what I mean? its still the same shape, only the individual polys are convex no matter the over all shape.

hope this helps…

GRRR… stupid browser!!! my pic is messed up…

try this:

v1-v2
\ |
v5|
/ |
v4-v3

v1-v2
/|
v5|
/|
v4-v3

[This message has been edited by john_at_kbs_is (edited 10-14-2002).]

ahhhh!!! sorry, for the ghetto pics, I hope that they look good enough to help out…

[This message has been edited by john_at_kbs_is (edited 10-14-2002).]

Do a google for “ear clipping” or more general “polygon tesselation”.

try this: www.codeproject.com/useritems/polygon_tesselation.asp

Or render the polygon into the stencil buffer first as a triangle fan (don’t wory about the tessalation) with a StencilMask of 1 and GL_INVERT StencilOp then draw the bounding rectangle of the polygon using GL_EQUAL,1 StencilFunc. This will not be teribly efficient with lots of independent shapes because you have to clear the stencil each time, but it’s perfect for complex shapes (text for instance, this approach will take care of the holes and you can draw the whole text at once). Also if you’re clever with the StencilMask you can draw up to 8(or whatever the number of stencil bits avaiable) shapes before clearing the stencil.