vendredi 20 mars 2015

can anyone explain the following opengl code?


can any one explain how glvertex3fv works when the function call


`GLfloat v[][8][3]={{{-1.5,-1.5,-1.0}, {-1.3,-1.5,-1.0}, {-1.3,-1.3,-1.0}, {-1.5,-1.3,-1.0}, {-1.6,-1.6,1.0}, {-1.4,-1.6,1.0}, {-1.4,-1.4,1.0}, {-1.6,-1.4,1.0}} ,


{{-1.3,-1.5,-1.0}, {-1.1,-1.5,-1.0}, {-1.1,-1.3,-1.0}, {-1.3,-1.3,-1.0}, {-1.4,-1.6,1.0}, {-1.2,-1.6,1.0}, {-1.2,-1.4,1.0}, {-1.4,-1.4,1.0}} ,


{{-1.1,-1.5,-1.0}, {-0.9,-1.5,-1.0}, {-0.9,-1.3,-1.0}, {-1.1,-1.3,-1.0}, {-1.2,-1.6,1.0}, {-1.0,-1.6,1.0}, {-1.0,-1.4,1.0}, {-1.2,-1.4,1.0}} ,


{{-1.5,-1.3,-1.0}, {-1.3,-1.3,-1.0}, {-1.3,-1.1,-1.0}, {-1.5,-1.1,-1.0}, {-1.6,-1.4,1.0}, {-1.4,-1.4,1.0}, {-1.4,-1.2,1.0}, {-1.6,-1.2,1.0}} ,


{{-1.3,-1.3,-1.0}, {-1.1,-1.3,-1.0}, {-1.1,-1.1,-1.0}, {-1.3,-1.1,-1.0}, {-1.4,-1.4,1.0}, {-1.2,-1.4,1.0}, {-1.2,-1.2,1.0}, {-1.4,-1.2,1.0}} ,


{{-1.1,-1.3,-1.0}, {-0.9,-1.3,-1.0}, {-0.9,-1.1,-1.0}, {-1.1,-1.1,-1.0}, {-1.2,-1.4,1.0}, {-1.0,-1.4,1.0}, {-1.0,-1.2,1.0}, {-1.2,-1.2,1.0}} ,


{{-1.5,-1.1,-1.0}, {-1.3,-1.1,-1.0}, {-1.3,-0.9,-1.0}, {-1.5,-0.9,-1.0}, {-1.6,-1.2,1.0}, {-1.4,-1.2,1.0}, {-1.4,-1.0,1.0}, {-1.6,-1.0,1.0}} ,


{{-1.3,-1.1,-1.0}, {-1.1,-1.1,-1.0}, {-1.1,-0.9,-1.0}, {-1.3,-0.9,-1.0}, {-1.4,-1.2,1.0}, {-1.2,-1.2,1.0}, {-1.2,-1.0,1.0}, {-1.4,-1.0,1.0}} ,


{{-1.1,-1.1,-1.0}, {-0.9,-1.1,-1.0}, {-0.9,-0.9,-1.0}, {-1.1,-0.9,-1.0}, {-1.2,-1.2,1.0}, {-1.0,-1.2,1.0}, {-1.0,-1.0,1.0}, {-1.2,-1.0,1.0}}};


GLfloat colors[][3]={{0.0,0.0,0.0}, //black


{1.0,0.0,0.0}, //red


{1.0,1.0,0.0}, //yellow


{0.0,1.0,0.0}, //green


{1.0,0.0,1.0}, //magenta


{0.0,1.0,1.0}}; //cyan ....


void polygon(int a,int b,int c,int d,int i)


{


glBegin(GL_POLYGON);


glColor3fv(colors[a]);


glVertex3fv(v[i][a]); //wt is the meaning of this line


glColor3fv(colors[b]);


glVertex3fv(v[i][b]);


glColor3fv(colors[c]);


glVertex3fv(v[i][c]);


glColor3fv(colors[d]);


glVertex3fv(v[i][d]);


glFlush();


glEnd(); }


void colorcube() {


polygon(0,3,2,1,i); //wt is the meaning of i


polygon(2,3,7,6,i);


polygon(0,4,7,3,i);


polygon(1,2,6,5,i);


polygon(4,5,6,7,i);


polygon(0,1,5,4,i);


} `





Aucun commentaire:

Enregistrer un commentaire