/* colorcube.c */// Rotating, colorized cube#include <GLUT/glut.h>#include <math.h>void cube(){	glBegin(GL_QUADS);	glColor3f(1, 0, 0);	glVertex3f(-0.5,-0.5,-0.5);	glVertex3f(-0.5, 0.5,-0.5);	glVertex3f( 0.5, 0.5,-0.5);	glVertex3f( 0.5,-0.5,-0.5);	glColor3f(0, 1, 0);	glVertex3f( 0.5,-0.5,0.5);	glVertex3f( 0.5, 0.5,0.5);	glVertex3f(-0.5, 0.5,0.5);	glVertex3f(-0.5,-0.5,0.5);	glColor3f(0, 0, 1);	glVertex3f( 0.5,-0.5,-0.5);	glVertex3f( 0.5, -0.5,0.5);	glVertex3f(-0.5, -0.5,0.5);	glVertex3f(-0.5,-0.5,-0.5);	glColor3f(1, 1, 0);	glVertex3f(-0.5,0.5,-0.5);	glVertex3f(-0.5, 0.5,0.5);	glVertex3f( 0.5, 0.5,0.5);	glVertex3f( 0.5,0.5,-0.5);	glColor3f(1,0, 1);	glVertex3f(-0.5,-0.5, 0.5);	glVertex3f(-0.5, 0.5, 0.5);	glVertex3f(-0.5, 0.5,-0.5);	glVertex3f(-0.5,-0.5,-0.5);	glColor3f(0,1, 1);	glVertex3f(0.5,-0.5,-0.5);	glVertex3f(0.5, 0.5,-0.5);	glVertex3f( 0.5, 0.5,0.5);	glVertex3f( 0.5,-0.5,0.5);	glEnd();}void display(){	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		glRotatef(2, 1,1,1);	cube();		glutSwapBuffers();}void reshape(GLsizei w, GLsizei h){	// Viewport is a separate setting	glViewport(0, 0, w, h);	// Projection in projection matrix	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	glFrustum(-1, 1, -1, 1, 1, 20); // left, right, bottom, top, near, far	// Camera placement in modelview matrix	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();	gluLookAt(0, 0, 2,  0, 0, 0,  0, 1, 0); // camera, look-at-point, up-vector}void timer(int i){	glutTimerFunc(20, timer, i);	glutPostRedisplay();}int main(int argc, char **argv){	glutInit(&argc, argv);	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);	glutCreateWindow("colorcube");	glutDisplayFunc(display);	glutTimerFunc(20, timer, 0);	glutReshapeFunc(reshape);		glEnable(GL_CULL_FACE);	glEnable(GL_DEPTH_TEST);		glutMainLoop();}
