summaryrefslogtreecommitdiffstats
path: root/progs/demos/ipers.c
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2000-09-12 18:44:45 +0000
committerBrian Paul <[email protected]>2000-09-12 18:44:45 +0000
commitd49b34a233628a476b87dd2e2609405d76ac8866 (patch)
tree6d3d34783a333150862160cee8ccfd29629e14da /progs/demos/ipers.c
parentb8cc1508362ccad0182d838faa3c4079632cd7fb (diff)
better FPS calculation
Diffstat (limited to 'progs/demos/ipers.c')
-rw-r--r--progs/demos/ipers.c37
1 files changed, 16 insertions, 21 deletions
diff --git a/progs/demos/ipers.c b/progs/demos/ipers.c
index 8993d3fc222..aa15d67b534 100644
--- a/progs/demos/ipers.c
+++ b/progs/demos/ipers.c
@@ -28,6 +28,9 @@ static int fullscreen = 1;
static int WIDTH = 640;
static int HEIGHT = 480;
+static GLint T0;
+static GLint Frames;
+
#define MAX_LOD 9
#define TEX_SKY_WIDTH 256
@@ -195,21 +198,6 @@ inittextures(void)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
-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 void
calcposobs(void)
{
@@ -544,11 +532,10 @@ drawipers(int depth, int from)
static void
draw(void)
{
- static int count = 0;
- static char frbuf[80];
+ static char frbuf[80] = "";
static GLfloat alpha = 0.0f;
static GLfloat beta = 0.0f;
- float fr;
+ static float fr = 0.0;
dojoy();
@@ -610,10 +597,9 @@ draw(void)
/* Help Screen */
- fr = gettime();
sprintf(frbuf,
"Frame rate: %0.2f LOD: %d Tot. poly.: %d Poly/sec: %.1f",
- 1.0 / fr, LODbias, totpoly, totpoly / fr);
+ fr, LODbias, totpoly, totpoly * fr);
glDisable(GL_TEXTURE_2D);
glDisable(GL_FOG);
@@ -644,7 +630,16 @@ draw(void)
glutSwapBuffers();
- count++;
+ Frames++;
+ {
+ GLint t = glutGet(GLUT_ELAPSED_TIME);
+ if (t - T0 >= 2000) {
+ GLfloat seconds = (t - T0) / 1000.0;
+ fr = Frames / seconds;
+ T0 = t;
+ Frames = 0;
+ }
+ }
}
int