10 #include "glut_wrap.h"
16 static GLfloat Xrot
= 40, Yrot
= 0, Zrot
= 0;
17 static GLboolean Anim
= GL_TRUE
;
18 static GLuint Vbuffer
= 0;
22 static GLfloat buf
[NUM_QUADS
* 6 * 4];
25 static GLboolean doSwapBuffers
= GL_TRUE
;
27 static GLint Frames
= 0, T0
= 0;
43 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
46 glRotatef(Xrot
, 1, 0, 0);
47 glRotatef(Yrot
, 0, 1, 0);
48 glRotatef(Zrot
, 0, 0, 1);
50 glDrawArrays(GL_QUADS
, 0, NUM_QUADS
*4);
62 GLint t
= glutGet(GLUT_ELAPSED_TIME
);
65 GLfloat seconds
= (t
- T0
) / 1000.0;
66 GLfloat fps
= Frames
/ seconds
;
67 printf("%d frames in %6.3f seconds = %6.3f FPS\n",
68 Frames
, seconds
, fps
);
77 Reshape(int width
, int height
)
79 glViewport(0, 0, width
, height
);
80 glMatrixMode(GL_PROJECTION
);
82 glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
83 glMatrixMode(GL_MODELVIEW
);
85 glTranslatef(0.0, 0.0, -8.0);
90 Key(unsigned char key
, int x
, int y
)
92 const GLfloat step
= 3.0;
97 doSwapBuffers
= !doSwapBuffers
;
113 glutDestroyWindow(Win
);
122 SpecialKey(int key
, int x
, int y
)
124 const GLfloat step
= 3.0;
146 quad(float x
, float y
, float z
, float *v
)
151 v
[k
++] = x
* 0.5 + 0.5;
152 v
[k
++] = y
* 0.5 + 0.5;
153 v
[k
++] = z
* 0.5 + 0.5;
160 v
[k
++] = -x
* 0.5 + 0.5;
161 v
[k
++] = -y
* 0.5 + 0.5;
162 v
[k
++] = z
* 0.5 + 0.5;
169 v
[k
++] = -x
* 0.5 + 0.5;
170 v
[k
++] = -y
* 0.5 + 0.5;
171 v
[k
++] = -z
* 0.5 + 0.5;
178 v
[k
++] = x
* 0.5 + 0.5;
179 v
[k
++] = y
* 0.5 + 0.5;
180 v
[k
++] = -z
* 0.5 + 0.5;
188 gen_quads(GLfloat
*buf
)
194 for (i
= 0; i
< NUM_QUADS
; i
++) {
195 float angle
= i
/ (float) NUM_QUADS
* M_PI
;
196 float x
= r
* cos(angle
);
197 float y
= r
* sin(angle
);
205 for (i
= 0; i
< NUM_QUADS
* 4 * 2; i
++) {
206 printf("%d: %f %f %f\n", i
, p
[0], p
[1], p
[2]);
216 int bytes
= NUM_QUADS
* 4 * 2 * 3 * sizeof(float);
220 glGenBuffers(1, &Vbuffer
);
221 glBindBuffer(GL_ARRAY_BUFFER
, Vbuffer
);
222 glBufferData(GL_ARRAY_BUFFER_ARB
, bytes
, NULL
, GL_STATIC_DRAW_ARB
);
223 f
= (float *) glMapBuffer(GL_ARRAY_BUFFER_ARB
, GL_WRITE_ONLY_ARB
);
225 glUnmapBuffer(GL_ARRAY_BUFFER_ARB
);
226 glColorPointer(3, GL_FLOAT
, 6*sizeof(float), (void *) 0);
227 glVertexPointer(3, GL_FLOAT
, 6*sizeof(float), (void *) 12);
231 glColorPointer(3, GL_FLOAT
, 6*sizeof(float), buf
);
232 glVertexPointer(3, GL_FLOAT
, 6*sizeof(float), buf
+ 3);
235 glEnableClientState(GL_COLOR_ARRAY
);
236 glEnableClientState(GL_VERTEX_ARRAY
);
238 glEnable(GL_DEPTH_TEST
);
240 glClearColor(0.5, 0.5, 0.5, 0.0);
245 main(int argc
, char *argv
[])
247 glutInit(&argc
, argv
);
248 glutInitWindowPosition(0, 0);
249 glutInitWindowSize(600, 600);
250 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
251 Win
= glutCreateWindow(argv
[0]);
253 glutReshapeFunc(Reshape
);
254 glutKeyboardFunc(Key
);
255 glutSpecialFunc(SpecialKey
);
256 glutDisplayFunc(Draw
);