#include <GL/glut.h> void init() { glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_COLOR_MATERIAL); } void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); double aspect = (double)viewport[2] / (double)viewport[3]; gluPerspective(60, aspect, 1, 100); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // move back a bit glTranslatef( 0, 0, -35 ); static float angle = 0; angle += 1.0f; glPushMatrix(); glTranslatef(0,0,0); glRotatef(angle, 0.1, 0.2, 0.5); glColor3ub(255,0,255); glutSolidCube(5); glPopMatrix(); glPushMatrix(); glTranslatef(10,-10,0); glRotatef(angle, 0.1, 0.2, 0.5); glColor3ub(255,0,0); glutSolidCube(5); glPopMatrix(); glPushMatrix(); glTranslatef(10,10,0); glRotatef(angle, 0.1, 0.2, 0.5); glColor3ub(0,255,0); glutSolidCube(5); glPopMatrix(); glPushMatrix(); glTranslatef(-10,10,0); glRotatef(angle, 0.1, 0.2, 0.5); glColor3ub(0,0,255); glutSolidCube(5); glPopMatrix(); glPushMatrix(); glTranslatef(-10,-10,0); glRotatef(angle, 0.1, 0.2, 0.5); glColor3ub(255,255,0); glutSolidCube(5); glPopMatrix(); glutSwapBuffers(); } void reshape(int w, int h) { glViewport(0, 0, w, h); } void timer(int extra) { glutPostRedisplay(); glutTimerFunc(16, timer, 0); } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitWindowSize(640,480); glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE); glutCreateWindow("CUBES"); glutDisplayFunc(display); glutReshapeFunc(reshape); glutTimerFunc(0, timer, 0); init(); glutMainLoop(); return 0; }