PDA

View Full Version : a polygon drawing problem



kazmalak
11-11-2005, 01:46 AM
I have encountered a strange problem when I was drawing a polygon having 7 vertices. The problem is that when one of the interior angle of the polygon is greater than 180 degrees, the polygon is not correctly drawn at that vertex. The code which I used to draw polygon is below;


glBegin(GL_POLYGON);
glVertex3f(-22.60,0,0);
glVertex3f(-22.60,0,40.49);
glVertex3f(-50,0,40.49);
glVertex3f(-50,0,100);
glVertex3f(50,0,100);
glVertex3f(50,0,27.80);
glVertex3f(24.57,0,0);
glEnd();The second vertex causes this problem.

Does it mean that I always have to draw polygons that have interior angles smaller than 180 degrees?
If so, is there another way to draw these kind of polygons?

11-11-2005, 02:17 AM
Yes, as far as I'm aware, OGL requires your polygons to be convex, not concave. Any angle over 180 would make a polygon concave.

http://www.korthalsaltes.com/gif/convex-concave-polygon.gif

You can easily overcome this simply by splitting your polygons down into smaller triangles. That way, they'll all be convex.

Dan.

songho
11-11-2005, 08:34 AM
kazmalak,
You may try tessellator in GLU library.
Please look at OpenGL FAQ 4.040 (http://www.opengl.org/resources/faq/technical/glu.htm) .


GLU provides tessellation routines to let you render concave polygons, self-intersecting polygons, and polygons with holes.