PDA

View Full Version : Draw polygon

Never
03-17-2008, 12:26 PM
i used the code below to draw a rectangle. now i want to draw a six vertice POLYGON... any help please?

glTranslatef(3.0f,0.0f,0.0f); // Move Right 3 Units
glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glEnd();

eggzcape
03-17-2008, 01:40 PM
you just have to use glVertex3f to specify the 6 vertices like you did for the rectangle, for isntance:

glVertex3f(-0.5f, 1.0f, 0.0f); // Top Left
glVertex3f(-1.0f, 0.0f, 0.0f); // Left
glVertex3f(-0.5f, 1.0f, 0.0f); // Bottom Left
glVertex3f(0.5f, 1.0f, 0.0f); // Top Right
glVertex3f(1.0f, 0.0f, 0.0f); // Right
glVertex3f(0.5f, 1.0f, 0.0f); // Bottom Right
glEnd();

Jay I
03-17-2008, 04:46 PM

Never
03-17-2008, 09:43 PM
how to implement GL_TRIANGLE_FAN?

Never
03-17-2008, 10:07 PM
is it possible to use GL_LINE to draw the vertex?

eggzcape
03-18-2008, 04:50 AM
A GL_TRIANGLE_FAN is a set of triangles with 1 common point, the the case on a 6 vertex polygon it would be something like:

glBegin(GL_TRIANGLE_FAN); // Draw A 6 vertex polygon
glVertex3f(-0.5f, 1.0f, 0.0f); // Top Left
glVertex3f(-1.0f, 0.0f, 0.0f); // Left
glVertex3f(-0.5f, 1.0f, 0.0f); // Bottom Left
glVertex3f(0.5f, 1.0f, 0.0f); // Top Right
glVertex3f(1.0f, 0.0f, 0.0f); // Right
glVertex3f(0.5f, 1.0f, 0.0f); // Bottom Right
glEnd();

if you want to draw the outline of a polygon you can use GL_LINE_LOOP:

glBegin(GL_LINE_LOOP); // Draw A 6 vertex polygon
glVertex3f(-0.5f, 1.0f, 0.0f); // Top Left
glVertex3f(-1.0f, 0.0f, 0.0f); // Left
glVertex3f(-0.5f, 1.0f, 0.0f); // Bottom Left
glVertex3f(0.5f, 1.0f, 0.0f); // Top Right
glVertex3f(1.0f, 0.0f, 0.0f); // Right
glVertex3f(0.5f, 1.0f, 0.0f); // Bottom Right
glEnd();

This questions you are asking are the very basic about OpenGL primitives, you should read some introduction to OpenGL either online or on paper, to learn all sorts of primitives you can use.