1 #include <GL/freeglut.h>
7 static int slices = 16;
8 static int stacks = 16;
11 reshape(int width, int height)
15 glViewport( 0, 0, width, height);
16 glMatrixMode(GL_PROJECTION);
18 ar = (float) width / (float) height;
19 glFrustum ( -ar, ar, -1.0, 1.0, 2.0, 100.0);
21 glMatrixMode(GL_MODELVIEW) ;
28 float t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
31 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
34 glTranslatef(-2.4,1.2,-6);
38 glutSolidSphere(1,slices,stacks);
42 glTranslatef(0,1.2,-6);
46 glutSolidCone(1,1,slices,stacks);
50 glTranslatef(2.4,1.2,-6);
54 glutSolidTorus(0.2,0.8,slices,stacks);
58 glTranslatef(-2.4,-1.2,-6);
62 glutWireSphere(1,slices,stacks);
66 glTranslatef(0,-1.2,-6);
70 glutWireCone(1,1,slices,stacks);
74 glTranslatef(2.4,-1.2,-6);
78 glutWireTorus(0.2,0.8,slices,stacks);
86 key(unsigned char key, int x, int y)
114 GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
115 GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
116 GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
117 GLfloat light_position[] = { 2.0, 5.0, 5.0, 0.0 };
119 GLfloat mat_ambient[] = { 0.7, 0.7, 0.7, 1.0 };
120 GLfloat mat_diffuse[] = { 0.8, 0.8, 0.8, 1.0 };
121 GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
122 GLfloat high_shininess[] = { 100.0 };
125 main(int argc, char *argv[])
127 glutInit(&argc, argv);
128 glutInitWindowSize(640,480);
129 glutInitWindowPosition (40,40);
130 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
132 glutCreateWindow("FreeGLUT Shapes");
134 glutReshapeFunc(reshape);
135 glutDisplayFunc(display);
136 glutKeyboardFunc(key);
139 glClearColor(1,1,1,1);
140 glEnable(GL_CULL_FACE);
143 glEnable(GL_DEPTH_TEST);
144 glDepthFunc(GL_LESS);
147 glEnable(GL_NORMALIZE);
148 glEnable(GL_COLOR_MATERIAL);
149 glEnable(GL_LIGHTING);
151 glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
152 glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
153 glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
154 glLightfv(GL_LIGHT0, GL_POSITION, light_position);
156 glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
157 glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
158 glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
159 glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);