PDA

View Full Version : How to draw 2d polygons in OpenGL



01-04-2002, 09:36 AM
Hi,
I tested the OpenGL polygon mode. It seems the following piece of code just draw a convex polygon:

glBegin(GL_POLYGON);
nVert = p->numVert();
for(i=0; i<nVert; i++)
{
x = p->x(i);
y = p->y(i);
glVertex2f((GLfloat)x, (GLfloat)y);
}
glEnd();
Any pointers how to draw a non-convex polygon in OpenGL?

Thanks

mikael_aronsson
01-04-2002, 10:08 AM
Hi !

OpenGL itself can only render simple polygons (convex, no overlaps and no holes), if you need non convex polygons you have to break it down into triangles yourself or use the GLU tesselator.

Mikael