summaryrefslogtreecommitdiffstats
path: root/progs/demos/tunnel2.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/tunnel2.c
parentb8cc1508362ccad0182d838faa3c4079632cd7fb (diff)
better FPS calculation
Diffstat (limited to 'progs/demos/tunnel2.c')
-rw-r--r--progs/demos/tunnel2.c42
1 files changed, 16 insertions, 26 deletions
diff --git a/progs/demos/tunnel2.c b/progs/demos/tunnel2.c
index cc660374e35..e82c2c604dc 100644
--- a/progs/demos/tunnel2.c
+++ b/progs/demos/tunnel2.c
@@ -40,7 +40,8 @@ static int HEIGHTC0 = 480;
static int WIDTHC1 = 640;
static int HEIGHTC1 = 480;
-#define FRAME 50
+static GLint T0 = 0;
+static GLint Frames = 0;
#define NUMBLOC 5
@@ -167,21 +168,6 @@ drawobjs(int *l, float *f)
}
}
-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)
{
@@ -409,10 +395,9 @@ dojoy(void)
static void
draw(void)
{
- static int count = 0;
- static char frbuf[80];
+ static char frbuf[80] = "";
int i;
- float fr, base, offset;
+ float base, offset;
dojoy();
@@ -461,11 +446,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);
@@ -492,7 +472,17 @@ draw(void)
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
- 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;
+ }
+ }
}
static void
@@ -564,7 +554,7 @@ main(int ac, char **av)
glutInitWindowSize(WIDTHC0, HEIGHTC0);
glutInit(&ac, av);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_ALPHA);
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
#ifdef FX
if (!fxMesaSelectCurrentBoard(0)) {