The following code segments create a cube. All the cube's data points are stored in a single array. Each side of the cube is a different color.
For simplicity and flexibility, I put the declarations outside the display function. In other words, I made them global. The cubepoints array holds the actual data points. Each of the other arrays (front, back, top, etc.) indicate the indexes of the data in cubepoints. Notice that data point number 0 (-10,-10,10) is shared by the "front", "bottom", and "left" sides of the cube.
static int cubepoints[] = {-10,-10,10, 10,-10,10, 10,10,10, -10,10,10, -10,-10,-10, 10,-10,-10, 10,10,-10, -10,10,-10};
static GLubyte front[] = {0,1,2,3};
static GLubyte back[] = {4,5,6,7};
static GLubyte bottom[]= {0,1,5,4};
static GLubyte top[] = {2,3,7,6};
static GLubyte left[] = {0,3,7,4};
static GLubyte right[] = {1,2,6,5};
The following code was cut-and-pasted out of display(). The cube is composed of six quads. Each quad is a different color.
glColor3f(1.0,1.0,1.0); glDrawElements(GL_QUADS, 4, GL_UNSIGNED_BYTE, front); glColor3f(0.8,0.8,0.8); glDrawElements(GL_QUADS, 4, GL_UNSIGNED_BYTE, back); glColor3f(0.2,0.9,0.2); glDrawElements(GL_QUADS, 4, GL_UNSIGNED_BYTE, top); glColor3f(0.5,0.9,0.5); glDrawElements(GL_QUADS, 4, GL_UNSIGNED_BYTE, bottom); glColor3f(0.8,0.3,0.3); glDrawElements(GL_QUADS, 4, GL_UNSIGNED_BYTE, left); glColor3f(0.8,0.0,0.0); glDrawElements(GL_QUADS, 4, GL_UNSIGNED_BYTE, right);