| 580 | } |
| 581 | |
| 582 | static void |
| 583 | gears_idle(void) |
| 584 | { |
| 585 | static int frames = 0; |
| 586 | static double tRot0 = -1.0, tRate0 = -1.0; |
| 587 | double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; |
| 588 | |
| 589 | if (tRot0 < 0.0) |
| 590 | tRot0 = t; |
| 591 | dt = t - tRot0; |
| 592 | tRot0 = t; |
| 593 | |
| 594 | /* advance rotation for next frame */ |
| 595 | angle += 70.0 * dt; /* 70 degrees per second */ |
| 596 | if (angle > 3600.0) |
| 597 | angle -= 3600.0; |
| 598 | |
| 599 | glutPostRedisplay(); |
| 600 | frames++; |
| 601 | |
| 602 | if (tRate0 < 0.0) |
| 603 | tRate0 = t; |
| 604 | if (t - tRate0 >= 5.0) { |
| 605 | GLfloat seconds = t - tRate0; |
| 606 | GLfloat fps = frames / seconds; |
| 607 | printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds, |
| 608 | fps); |
| 609 | tRate0 = t; |
| 610 | frames = 0; |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | static const char vertex_shader[] = |
| 615 | "attribute vec3 position;\n" |