# 2D polygon wont display properly

Im drawing a simple 2d polygon shaped like this |_| but upside down:

``````	glBegin(GL_POLYGON);
glVertex2f(-4,2);
glVertex2f(4,2);
glVertex2f(4,-7);
glVertex2f(1,-7);
glVertex2f(1,-4);
glVertex2f(-1,-4);
glVertex2f(-1,-7);
glVertex2f(-4,-7);
glEnd();
``````

except one of the straight vertices is displaying at an angle and not rendering properly, it doesnt make any sense! can anyone see what the problem might be?

What poly do you want to draw ?
If it’s a square you should code it like that:

`````` 	glLoadIdentity();  // clean matrix
glColor3f(r.rf, g.gf, b.bf); // color ?
glTranslatef(x.xf, y.yf, z.zf); //position in 3d space

glVertex2f(0.0f, 1.0f);
glVertex2f(0.0f, 0.0f);
glVertex2f(2.0f, 0.0f);
glVertex2f(2.0f, 1.0f);
glEnd();
``````

Check the GL^RedBook out
hope that helps

Im trying to draw an odd shaped polygon, like this but upside down |_|
It animates one of the straight lines at a diagonal angle for some reason, I cant figure out why though.
Maybe a U shape just isnt valid with GL_POLYGON

You’re trying to draw a concave polygon that’s why it’s not coming out right.
OpenGL doesn’t handle concave polygons only convex ones.

break your polygon into 3 polygons (the right side, the bar across the top and the left side) and render it as 3 quads.

ah hah! thank you very much. atleast I got 1 thing right, opengl cant handle a U shape on its own