Link to home
Start Free TrialLog in
Avatar of srihari1986
srihari1986

asked on

Polygin using C , OpenGL

Hi Guys,

I am actually using C to crete a 8 sided polygon.I have doen the below programming to create the polygon and it work.

glPushMatrix();  

     glColor4f(0, 0, 1.0, 0);
     glBegin (GL_POLYGON);
     glVertex3f (-0.66,-0.88,0.65);
     glVertex3f (0.08,-0.81,1.03);
     glVertex3f (0.07,0.85,0.98);
     glVertex3f (-0.67,0.78,0.60);
     glEnd();
     
     glColor4f(0, 1, 1.0, 0);
    glBegin (GL_POLYGON);
     glVertex3f (0.08,-0.81,1.03);
    glVertex3f  (0.83,-0.83,0.66);
     glVertex3f (0.81,0.82,0.61);
    glVertex3f  (0.07,0.85,0.98);
   glEnd();


   glColor4f(1, 0, 1.0, 0);
    glBegin (GL_POLYGON);
     glVertex3f (0.83,-0.83,0.66);
    glVertex3f  (1.01,-0.93,-0.18);
     glVertex3f (1.00,0.73,-0.23);
     glVertex3f (0.81,0.82,0.61);

    glEnd();


  glColor4f(0, 1, 0.0, 0);
    glBegin (GL_POLYGON);
     glVertex3f (1.01,-0.93,-0.18);
     glVertex3f (0.50,-1.02,-0.86);
     glVertex3f (0.49,0.64,-0.91);
     glVertex3f (1.00,0.73,-0.23);

    glEnd();



  glColor4f(1, 1, 0.0, 1);
    glBegin (GL_POLYGON);
     glVertex3f (0.50,-1.02,-0.86);
     glVertex3f (-0.32,-1.04,-0.87);
     glVertex3f (-0.33,0.61,-0.92);
     glVertex3f (0.49,0.64,-0.91);

    glEnd();

  glColor4f(1, 1, 1.0, 1);
    glBegin (GL_POLYGON);
     glVertex3f (-0.32,-1.04,-0.87);
     glVertex3f (-0.84,-0.98,-0.19);
     glVertex3f (-0.85,0.68,-0.24);
     glVertex3f (-0.33,0.61,-0.92);

    glEnd();

  glColor4f(1, 0, 0.0, 1);
    glBegin (GL_POLYGON);
     glVertex3f (-0.84,-0.98,-0.19);
     glVertex3f (-0.66,-0.88,0.65);
     glVertex3f (-0.67,0.78,0.60);
     glVertex3f (-0.85,0.68,-0.24);

    glEnd();

   
      glPopMatrix();

Is there any way i can use a for loop or anything to create this.As it seems that the codes are veery big.Do u have any idea.


Regards
Hari
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Appear to be 2 piramides joined by the base (I am guessing, really)

You can use either Triangle Fans or Triangle Strips to have a shorter code. Have a look to this tutorial. (Notice that OpenGL prefers to work with triangles rather than 4 sided polygons):
http://www.falloutsoftware.com/tutorials/gl/gl3.htm
ASKER CERTIFIED SOLUTION
Avatar of NovaDenizen
NovaDenizen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial