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 | |
parent | b8cc1508362ccad0182d838faa3c4079632cd7fb (diff) |
better FPS calculation
Diffstat (limited to 'progs')
-rw-r--r-- | progs/demos/fire.c | 40 | ||||
-rw-r--r-- | progs/demos/ipers.c | 37 | ||||
-rw-r--r-- | progs/demos/ray.c | 39 | ||||
-rw-r--r-- | progs/demos/teapot.c | 39 | ||||
-rw-r--r-- | progs/demos/terrain.c | 43 | ||||
-rw-r--r-- | progs/demos/tunnel.c | 18 | ||||
-rw-r--r-- | progs/demos/tunnel2.c | 42 |
7 files changed, 93 insertions, 165 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; + } + } } 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 diff --git a/progs/demos/ray.c b/progs/demos/ray.c index 24f27a05393..aede3d8edbd 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 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) diff --git a/progs/demos/terrain.c b/progs/demos/terrain.c index fbc88039069..2fe1df3a071 100644 --- a/progs/demos/terrain.c +++ b/progs/demos/terrain.c @@ -38,9 +38,10 @@ static int fullscreen = 1; #define WIDTH 640 #define HEIGHT 480 -#define TSCALE 4 +static GLint T0 = 0; +static GLint Frames = 0; -#define FRAME 50 +#define TSCALE 4 #define FOV 85 @@ -71,21 +72,6 @@ static float v = 15.0; static float alpha = 75.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 void calcposobs(void) { @@ -360,9 +346,7 @@ dojoy(void) static void drawscene(void) { - static int count = 0; - static char frbuf[80]; - float fr; + static char frbuf[80] = ""; dojoy(); @@ -391,11 +375,6 @@ drawscene(void) drawterrain(); glPopMatrix(); - if ((count % FRAME) == 0) { - fr = gettime(); - sprintf(frbuf, "Frame rate: %.3f", FRAME / fr); - } - glDisable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); glDisable(GL_FOG); @@ -424,7 +403,17 @@ drawscene(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 @@ -558,7 +547,7 @@ loadpic(void) GLenum gluerr; if ((FilePic = fopen("terrain.dat", "r")) == NULL) { - fprintf(stderr, "Error loading Mnt.bin\n"); + fprintf(stderr, "Error loading terrain.dat\n"); exit(-1); } fread(bufferter, 256 * 256, 1, FilePic); diff --git a/progs/demos/tunnel.c b/progs/demos/tunnel.c index 10d9a540b7e..712edc5d7bd 100644 --- a/progs/demos/tunnel.c +++ b/progs/demos/tunnel.c @@ -155,21 +155,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) { @@ -369,7 +354,7 @@ draw(void) { static char frbuf[80] = ""; int i; - float fr, base, offset; + float base, offset; dojoy(); @@ -445,7 +430,6 @@ draw(void) glutSwapBuffers(); Frames++; - { GLint t = glutGet(GLUT_ELAPSED_TIME); if (t - T0 >= 2000) { 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)) { |