ASSISTANT
Here is an example program that draws a cube of size 1 and assigns each face a different material and color:
```
#include <GL/glut.h>
void drawCube()
{
// Define the vertices of the cube
GLfloat vertices[][3] = {{-0.5, -0.5, -0.5}, {0.5, -0.5, -0.5}, {0.5, 0.5, -0.5}, {-0.5, 0.5, -0.5}, {-0.5, -0.5, 0.5}, {0.5, -0.5, 0.5}, {0.5, 0.5, 0.5}, {-0.5, 0.5, 0.5}};
// Define the indices for each face of the cube
GLint indices[][4] = {{0, 1, 2, 3}, {1, 5, 6, 2}, {4, 5, 6, 7}, {0, 4, 7, 3}, {0, 1, 5, 4}, {3, 2, 6, 7}};
// Define the colors and materials for each face of the cube
GLfloat colors[][3] = {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}, {1.0, 1.0, 0.0}, {1.0, 0.0, 1.0}, {0.0, 1.0, 1.0}};
GLfloat ambient[][3] = {{0.2, 0.0, 0.0}, {0.0, 0.2, 0.0}, {0.0, 0.0, 0.2}, {0.2, 0.2, 0.0}, {0.2, 0.0, 0.2}, {0.0, 0.2, 0.2}};
GLfloat diffuse[][3] = {{0.8, 0.0, 0.0}, {0.0, 0.8, 0.0}, {0.0, 0.0, 0.8}, {0.8, 0.8, 0.0}, {0.8, 0.0, 0.8}, {0.0, 0.8, 0.8}};
GLfloat specular[][3] = {{1.0, 1.0, 1.0}, {1.0, 1.0, 1.0}, {1.0, 1.0, 1.0}, {1.0, 1.0, 1.0}, {1.0, 1.0, 1.0}, {1.0, 1.0, 1.0}};
GLfloat shininess[] = {100.0, 100.0, 100.0, 100.0, 100.0, 100.0};
// Draw each face of the cube with the appropriate color and material
glBegin(GL_QUADS);
for (int i = 0; i < 6; i++)
{
glColor3fv(colors[i]);
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient[i]);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse[i]);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular[i]);
glMaterialf(GL_FRONT, GL_SHININESS, shininess[i]);
for (int j = 0; j < 4; j++)
{
glVertex3fv(vertices[indices[i][j]]);
}
}
glEnd();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -5.0);
glRotatef(30.0, 1.0, 1.0, 1.0);
drawCube();
glutSwapBuffers();
}
void init()
{
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0};
GLfloat diffuse[] = {1.0, 1.0, 1.0, 1.0};
GLfloat specular[] = {1.0, 1.0, 1.0, 1.0};
GLfloat position[] = {1.0, 1.0, 1.0, 0.0};
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
glLightfv(GL_LIGHT0, GL_POSITION, position);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutCreateWindow("Cube");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
```
This program uses the GLUT library to set up a window to display the cube. The `drawCube` function defines the cube vertices, indices, colors, and materials, and then draws each face of the cube with the appropriate color and material. The `display` function sets up the projection and modelview matrices, calls the `drawCube` function, and swaps the front and back buffers. The `init` function enables depth testing and lighting, sets up a single point light, and defines the ambient, diffuse, and specular properties of the light. Finally, the `main` function initializes GLUT, sets the display mode and window size, creates the window, calls the `init` function, sets the display function, and enters the main loop.