6 #define GL_GLEXT_PROTOTYPES
16 static GLfloat Xrot
= 40, Yrot
= 0, Zrot
= 0;
17 static GLboolean Anim
= GL_TRUE
;
18 static GLuint Vbuffer
= 0;
20 static GLfloat buf
[NUM_QUADS
* 6 * 4];
22 static GLboolean SwapBuffers
= GL_TRUE
;
24 static GLint Frames
= 0, T0
= 0;
40 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
43 glRotatef(Xrot
, 1, 0, 0);
44 glRotatef(Yrot
, 0, 1, 0);
45 glRotatef(Zrot
, 0, 0, 1);
47 glDrawArrays(GL_QUADS
, 0, NUM_QUADS
*4);
59 GLint t
= glutGet(GLUT_ELAPSED_TIME
);
62 GLfloat seconds
= (t
- T0
) / 1000.0;
63 GLfloat fps
= Frames
/ seconds
;
64 printf("%d frames in %6.3f seconds = %6.3f FPS\n",
65 Frames
, seconds
, fps
);
74 Reshape(int width
, int height
)
76 glViewport(0, 0, width
, height
);
77 glMatrixMode(GL_PROJECTION
);
79 glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
80 glMatrixMode(GL_MODELVIEW
);
82 glTranslatef(0.0, 0.0, -8.0);
87 Key(unsigned char key
, int x
, int y
)
89 const GLfloat step
= 3.0;
94 SwapBuffers
= !SwapBuffers
;
110 glutDestroyWindow(Win
);
119 SpecialKey(int key
, int x
, int y
)
121 const GLfloat step
= 3.0;
143 quad(float x
, float y
, float z
, float *v
)
148 v
[k
++] = x
* 0.5 + 0.5;
149 v
[k
++] = y
* 0.5 + 0.5;
150 v
[k
++] = z
* 0.5 + 0.5;
157 v
[k
++] = -x
* 0.5 + 0.5;
158 v
[k
++] = -y
* 0.5 + 0.5;
159 v
[k
++] = z
* 0.5 + 0.5;
166 v
[k
++] = -x
* 0.5 + 0.5;
167 v
[k
++] = -y
* 0.5 + 0.5;
168 v
[k
++] = -z
* 0.5 + 0.5;
175 v
[k
++] = x
* 0.5 + 0.5;
176 v
[k
++] = y
* 0.5 + 0.5;
177 v
[k
++] = -z
* 0.5 + 0.5;
185 gen_quads(GLfloat
*buf
)
191 for (i
= 0; i
< NUM_QUADS
; i
++) {
192 float angle
= i
/ (float) NUM_QUADS
* M_PI
;
193 float x
= r
* cos(angle
);
194 float y
= r
* sin(angle
);
202 for (i
= 0; i
< NUM_QUADS
* 4 * 2; i
++) {
203 printf("%d: %f %f %f\n", i
, p
[0], p
[1], p
[2]);
213 int bytes
= NUM_QUADS
* 4 * 2 * 3 * sizeof(float);
217 glGenBuffers(1, &Vbuffer
);
218 glBindBuffer(GL_ARRAY_BUFFER
, Vbuffer
);
219 glBufferData(GL_ARRAY_BUFFER_ARB
, bytes
, NULL
, GL_STATIC_DRAW_ARB
);
220 f
= (float *) glMapBuffer(GL_ARRAY_BUFFER_ARB
, GL_WRITE_ONLY_ARB
);
222 glUnmapBuffer(GL_ARRAY_BUFFER_ARB
);
223 glColorPointer(3, GL_FLOAT
, 6*sizeof(float), (void *) 0);
224 glVertexPointer(3, GL_FLOAT
, 6*sizeof(float), (void *) 12);
228 glColorPointer(3, GL_FLOAT
, 6*sizeof(float), buf
);
229 glVertexPointer(3, GL_FLOAT
, 6*sizeof(float), buf
+ 3);
232 glEnableClientState(GL_COLOR_ARRAY
);
233 glEnableClientState(GL_VERTEX_ARRAY
);
235 glEnable(GL_DEPTH_TEST
);
237 glClearColor(0.5, 0.5, 0.5, 0.0);
242 main(int argc
, char *argv
[])
244 glutInit(&argc
, argv
);
245 glutInitWindowPosition(0, 0);
246 glutInitWindowSize(600, 600);
247 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
248 Win
= glutCreateWindow(argv
[0]);
249 glutReshapeFunc(Reshape
);
250 glutKeyboardFunc(Key
);
251 glutSpecialFunc(SpecialKey
);
252 glutDisplayFunc(Draw
);