View Full Version : 2D polygon wont display properly
tim00
12-07-2004, 11:59 AM
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?
Silkut
12-07-2004, 12:19 PM
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
glBegin(GL_QUADS);
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
tim00
12-07-2004, 12:22 PM
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 :confused:
Aeluned
12-07-2004, 01:14 PM
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.
tim00
12-07-2004, 01:37 PM
ah hah! thank you very much. atleast I got 1 thing right, opengl cant handle a U shape on its own
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.