static int WIDTH = 640;
static int HEIGHT = 480;
-#define FRAME 50
+static GLint T0 = 0;
+static GLint Frames = 0;
#define NUMBLOC 5
static void
draw(void)
{
- static int count = 0;
- static char frbuf[80];
+ static char frbuf[80] = "";
int i;
float fr, base, offset;
glPopMatrix();
glPopMatrix();
- if ((count % FRAME) == 0) {
- fr = gettime();
- sprintf(frbuf, "Frame rate: %f", FRAME / fr);
- }
-
glDisable(GL_TEXTURE_2D);
glDisable(GL_FOG);
glShadeModel(GL_FLAT);
glutSwapBuffers();
- count++;
+ Frames++;
+
+ {
+ GLint t = glutGet(GLUT_ELAPSED_TIME);
+ if (t - T0 >= 2000) {
+ GLfloat seconds = (t - T0) / 1000.0;
+ GLfloat fps = Frames / seconds;
+ sprintf(frbuf, "Frame rate: %f", fps);
+ T0 = t;
+ Frames = 0;
+ }
+ }
}
int