PDA

View Full Version : Gl_POLYGON

Al Grant
05-25-2006, 05:55 PM
Hi Guys,

I am trying to draw a polygon, which is essentially like a upside down "L", if I use GL_POINTS they are in the right place, but when I use GL_POLYGON I get a different shape???

The problem is around 4,5,6. Any got any ideaS???

Cheers

-Al

glBegin(GL_POINTS);
glVertex3f(-1.75f,0.05f,0.0f); //1
glVertex3f(-0.75f,0.05f,0.0f); //2
glVertex3f(-0.75f,-0.15f,0.0f); //3
glVertex3f(-0.85f,-0.15f,0.0f); //4
glVertex3f(-0.85f,-0.05f,0.0f); //5
glVertex3f(-1.75f,-0.05f,0.0f); //6
glEnd();

songho
05-25-2006, 08:48 PM
The problem is that "L" shape is a concave polygon, but OpenGL accepts only convex polygons.

You may tessellate it into a convex polygon by using GLU tessellattor, or may try the stencil trick.

The redbook(OpenGL programming Guide) describes both methods very well. Please look at "Drawing Filled, Polygons Using the Stencil Buffer" section especially for the stencil trick.

Al Grant
05-25-2006, 10:46 PM
Righto - sounds good. Thanks!

glome
05-26-2006, 01:34 AM
Or simply split your "L" to 2 convex polygons (rectangles) "|" and "_".

Serge K
05-26-2006, 07:57 PM
Originally posted by glome:
Or simply split your "L" to 2 convex polygons (rectangles) "|" and "_". ...but watch out for T-junctions...