summaryrefslogtreecommitdiff
path: root/progs/demos/ray.c
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>2000-09-12 18:44:45 +0000
committerBrian Paul <brian.paul@tungstengraphics.com>2000-09-12 18:44:45 +0000
commitd49b34a233628a476b87dd2e2609405d76ac8866 (patch)
tree6d3d34783a333150862160cee8ccfd29629e14da /progs/demos/ray.c
parentb8cc1508362ccad0182d838faa3c4079632cd7fb (diff)
better FPS calculation
Diffstat (limited to 'progs/demos/ray.c')
-rw-r--r--progs/demos/ray.c39
1 files changed, 14 insertions, 25 deletions
diff --git a/progs/demos/ray.c b/progs/demos/ray.c
index 24f27a0539..aede3d8edb 100644
--- a/progs/demos/ray.c
+++ b/progs/demos/ray.c
@@ -24,7 +24,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 BASESIZE 7.5f
#define SPHERE_RADIUS 0.75f
@@ -94,21 +95,6 @@ static int showreflectmap = 1;
static int joyavailable = 0;
static int joyactive = 0;
-static float
-gettime(void)
-{
- static float told = 0.0f;
- float tnew, ris;
-
- tnew = glutGet(GLUT_ELAPSED_TIME);
-
- ris = tnew - told;
-
- told = tnew;
-
- return ris / 1000.0;
-}
-
static void
calcposobs(void)
{
@@ -622,9 +608,7 @@ updatemaps(void)
static void
draw(void)
{
- static int count = 0;
- static char frbuf[80];
- float fr;
+ static char frbuf[80] = "";
dojoy();
@@ -657,11 +641,6 @@ draw(void)
glPopMatrix();
- if ((count % FRAME) == 0) {
- fr = gettime();
- sprintf(frbuf, "Frame rate: %f", FRAME / fr);
- }
-
glDisable(GL_DEPTH_TEST);
glDisable(GL_FOG);
@@ -746,7 +725,17 @@ 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;
+ }
+ }
}
static void