CUBE EXAMPLE

(Reference: Angel, 4.4.4, p.137)
How do you describe a cube?
You could define six faces of the cube. Here is a cube face.
-- Alternatively, you could use GL_QUADS.
-- These are unsatisfactory: there are only 8 vertices, not 24.
Instead, let us create an array of 8 points: index into the array to form the faces. THUS.


A CUBE FACE

glBegin(GL_POLYGON)
glVertex3f(0.0,0.0,0.0);
glVertex3f(0.0,0.1,0.0);
glVertex3f(1.0,0.0,0.0);
glVertex3f(1.0,0.1,0.0);
glEnd()


USING GL_QUADS

glBegin(GL_QUADS)
...a list of 24 glVertices here...
glEnd()


THE COLOR CUBE

typedef point GLFloat[3];
point node[8]={{0.0, 0.0, 0.0},{0.0,0.0,1.0},{0.0,1.0,0.0},{0.0,1.0,1.0},
   {1.0, 0.0, 0.0},{1.0,0.0,1.0},{1.0,1.0,0.0},{1.0,1.0,1.0}};
Glfloat color[][3]={{0.0, 0.0, 0.0},{0.0,0.0,1.0},{0.0,1.0,0.0},{0.0,1.0,1.0},
   {1.0, 0.0, 0.0},{1.0,0.0,1.0},{1.0,1.0,0.0},{1.0,1.0,1.0}};
void quad(int a, int b, int c, int d)
{
   glBegin{GL_POLYGON};
       glColor3fv(color[a]);
       glVertex3fv(node[a]);
       glColor3fv(color[b]);
       glVertex3fv(node[b]);
       glColor3fv(color[c]);
       glVertex3fv(node[c]);
       glColor3fv(color[d]);
       glVertex3fv(node[d]);
   glEnd();
}
void colorcube()
{
  : quad(0,3,2,1);
  : quad(2,3,7,6);
  : quad(0,4,7,3);
  : quad(1,2,6,5);
  : quad(4,5,6,7);
  : quad(0,1,5,4);
}