Solved
Draw a 8 Sided Prism using OPENGL
Posted on 2005-04-03
Hi All,
I am doing a 8 and 7 sided polygon using Openg.But i need all the sided to be of a same width.But when i draw using the GL_POLYGON i dont get all the sided of the polygon with the same width.
Below is the program i did to draw the 8 sided polygon.Can anybody help me to find the angles i need to use like the x,y,z or cn anybody tell me is there any formula to find the angle.And can i also know how to do a fraw a 7 sided polygon
glColor4f(1,0,0,0);
glBegin (GL_POLYGON);// Draw the First from square,Square 1.
glVertex3f(-0.5,-1,1.5);
glVertex3f(0.5,-1,1.5);
glVertex3f(0.5,1,1.5);
glVertex3f(-0.5,1,1.5);
glEnd();
glColor4f(1,1,0,0);
glBegin (GL_POLYGON);// Draw the right from the front the square.
glVertex3f(0.5,-1,1.5);
glVertex3f(1,-1,0.5);
glVertex3f(1,1,0.5);
glVertex3f(0.5,1,1.5);
glEnd();
glColor4f(0,0,1,0);
glBegin (GL_POLYGON);// Draw the straight square from right.
glVertex3f(1,-1,0.5);
glVertex3f(1,-1,-0.5);
glVertex3f(1,1,-0.5);
glVertex3f(1,1,0.5);
glEnd();
glColor4f(0,1,1,0);
glBegin (GL_POLYGON);
glVertex3f(1,-1,-0.5);
glVertex3f(0.5,-1,-1.5);
glVertex3f(0.5,1,-1.5);
glVertex3f(1,1,-0.5);
glEnd();
glColor4f(0,1,0,0);
glBegin (GL_POLYGON);// Draw the behind square.
glVertex3f(0.5,-1,-1.5);
glVertex3f(-0.5,-1,-1.5);
glVertex3f(-0.5,1,-1.5);
glVertex3f(0.5,1,-1.5);
glEnd();
glColor4f(1,1,1,0);
glBegin (GL_POLYGON);//draw the left suare.
glVertex3f(-0.5,-1,-1.5);
glVertex3f(-1,-1,-0.5);
glVertex3f(-1,1,-0.5);
glVertex3f(-0.5,1,-1.5);
glEnd();
glColor4f(0,1,1,0);
glBegin (GL_POLYGON);// Draw the square next to the left..
glVertex3f(-1,-1,-0.5);
glVertex3f(-1,-1,0.5);
glVertex3f(-1,1,0.5);
glVertex3f(-1,1,-0.5);
glEnd();
glColor4f(1,0,.6,1);
glBegin (GL_POLYGON);// Draw the square next to the left..
glVertex3f(-1,-1,0.5);
glVertex3f(-0.5,-1,1.5);
glVertex3f(-0.5,1,1.5);
glVertex3f(-1,1,0.5);
glEnd();
Thanks
Hari