diff options
author | Brian Paul <[email protected]> | 2000-09-12 18:44:45 +0000 |
---|---|---|
committer | Brian Paul <[email protected]> | 2000-09-12 18:44:45 +0000 |
commit | d49b34a233628a476b87dd2e2609405d76ac8866 (patch) | |
tree | 6d3d34783a333150862160cee8ccfd29629e14da /progs/demos/fire.c | |
parent | b8cc1508362ccad0182d838faa3c4079632cd7fb (diff) |
better FPS calculation
Diffstat (limited to 'progs/demos/fire.c')
-rw-r--r-- | progs/demos/fire.c | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/progs/demos/fire.c b/progs/demos/fire.c index f4c45219d05..52ea8683021 100644 --- a/progs/demos/fire.c +++ b/progs/demos/fire.c @@ -71,7 +71,9 @@ static int fullscreen = 1; static int WIDTH = 640; static int HEIGHT = 480; -#define FRAME 50 +static GLint T0 = 0; +static GLint Frames = 0; + #define DIMP 20.0 #define DIMTP 16.0 @@ -137,21 +139,6 @@ static float alpha = -90.0; static float beta = 90.0; static float -gettime(void) -{ - static clock_t told = 0; - clock_t tnew, ris; - - tnew = clock(); - - ris = tnew - told; - - told = tnew; - - return (ris / (float) CLOCKS_PER_SEC); -} - -static float vrnd(void) { return (((float) rand()) / RAND_MAX); @@ -387,10 +374,8 @@ dojoy(void) static void drawfire(void) { - static int count = 0; - static char frbuf[80]; + static char frbuf[80] = ""; int j; - float fr; dojoy(); @@ -468,11 +453,6 @@ drawfire(void) } glEnd(); - if ((count % FRAME) == 0) { - fr = gettime(); - sprintf(frbuf, "Frame rate: %f", FRAME / fr); - } - glDisable(GL_TEXTURE_2D); glDisable(GL_ALPHA_TEST); glDisable(GL_DEPTH_TEST); @@ -499,7 +479,17 @@ drawfire(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; + } + } } |