diff options
author | Brian Paul <[email protected]> | 2000-09-12 17:38:22 +0000 |
---|---|---|
committer | Brian Paul <[email protected]> | 2000-09-12 17:38:22 +0000 |
commit | 4df1f7c7ba9fe52de6c13e3290df831d1eb245c9 (patch) | |
tree | d2ecc211db5e1c40cdd07013c786d3a8d5560b60 /progs/demos/tunnel.c | |
parent | 82cfcfa63a7823a97c368c26e049926044abf89b (diff) |
better fps computation
Diffstat (limited to 'progs/demos/tunnel.c')
-rw-r--r-- | progs/demos/tunnel.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/progs/demos/tunnel.c b/progs/demos/tunnel.c index 98484ee68da..10d9a540b7e 100644 --- a/progs/demos/tunnel.c +++ b/progs/demos/tunnel.c @@ -27,7 +27,8 @@ static int fullscreen = 1; static int WIDTH = 640; static int HEIGHT = 480; -#define FRAME 50 +static GLint T0 = 0; +static GLint Frames = 0; #define NUMBLOC 5 @@ -366,8 +367,7 @@ dojoy(void) static void draw(void) { - static int count = 0; - static char frbuf[80]; + static char frbuf[80] = ""; int i; float fr, base, offset; @@ -416,11 +416,6 @@ draw(void) 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); @@ -449,7 +444,18 @@ draw(void) 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 |