summaryrefslogtreecommitdiffstats
path: root/progs/demos/teapot.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/teapot.c
parentb8cc1508362ccad0182d838faa3c4079632cd7fb (diff)
better FPS calculation
Diffstat (limited to 'progs/demos/teapot.c')
-rw-r--r--progs/demos/teapot.c39
1 files changed, 15 insertions, 24 deletions
diff --git a/progs/demos/teapot.c b/progs/demos/teapot.c
index c36865f4bc2..4769139ed98 100644
--- a/progs/demos/teapot.c
+++ b/progs/demos/teapot.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 BASESIZE 10.0
@@ -65,20 +66,6 @@ static int joyactive=0;
static GLuint t1id,t2id;
static GLuint teapotdlist,basedlist,lightdlist;
-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)
{
dir[0]=sin(alpha*M_PI/180.0);
@@ -339,9 +326,7 @@ static void dojoy(void)
static void draw(void)
{
- static int count=0;
- static char frbuf[80];
- float fr;
+ static char frbuf[80] = "";
dojoy();
@@ -375,11 +360,6 @@ static void draw(void)
drawlight2();
glPopMatrix();
- if((count % FRAME)==0) {
- fr=gettime();
- sprintf(frbuf,"Frame rate: %f",FRAME/fr);
- }
-
glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
@@ -405,7 +385,18 @@ static void 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 inittextures(void)