| 359 | } |
| 360 | |
| 361 | void Draw(void) { |
| 362 | int width, height, x; |
| 363 | double t; |
| 364 | |
| 365 | t = glfwGetTime (); |
| 366 | glfwGetMousePos (&x, NULL); |
| 367 | |
| 368 | // Get window size (may be different than the requested size) |
| 369 | glfwGetWindowSize (&width, &height); |
| 370 | |
| 371 | // Special case: avoid division by zero below |
| 372 | height = height > 0 ? height : 1; |
| 373 | |
| 374 | glViewport (0, 0, width, height); |
| 375 | // Clear color buffer to black |
| 376 | glClearColor (0.1f, 0.2f, 0.3f, 0.0f); |
| 377 | glClear (GL_COLOR_BUFFER_BIT); |
| 378 | |
| 379 | // Select and setup the projection matrix |
| 380 | glMatrixMode (GL_PROJECTION); |
| 381 | glLoadIdentity (); |
| 382 | gluPerspective (65.0f, (GLfloat) width / (GLfloat) height, 1.0f, 100.0f); |
| 383 | |
| 384 | // Select and setup the modelview matrix |
| 385 | glMatrixMode (GL_MODELVIEW); |
| 386 | glLoadIdentity (); |
| 387 | gluLookAt (0.0f, 1.0f, 0.0f, // Eye-position |
| 388 | 0.0f, 20.0f, 0.0f, // View-point |
| 389 | 0.0f, 0.0f, 1.0f); // Up-vector |
| 390 | |
| 391 | // Draw a rotating colorful triangle |
| 392 | //glTranslatef (0.0f, 14.0f, 0.0f); |
| 393 | glTranslatef (0.0f, 1.0f, 0.0f); |
| 394 | glRotatef (0.3f * (GLfloat) x + (GLfloat) t * 100.0f, 0.0f, 0.0f, 1.0f); |
| 395 | glBegin (GL_TRIANGLES); |
| 396 | glColor3f (1.0f, 0.0f, 0.0f); |
| 397 | glVertex3f (-5.0f, 0.0f, -4.0f); |
| 398 | glColor3f (0.0f, 1.0f, 0.0f); |
| 399 | glVertex3f (5.0f, 0.0f, -4.0f); |
| 400 | glColor3f (0.0f, 0.0f, 1.0f); |
| 401 | glVertex3f (0.0f, 0.0f, 6.0f); |
| 402 | glEnd (); |
| 403 | |
| 404 | // Swap buffers |
| 405 | glfwSwapBuffers (); |
| 406 | } |
| 407 | |
| 408 | // the time of the previous frame |
| 409 | double old_time; |