diff options
author | Zack Rusin <zack@tungstengraphics.com> | 2007-11-09 08:19:27 -0500 |
---|---|---|
committer | Zack Rusin <zack@tungstengraphics.com> | 2007-12-11 09:49:33 -0500 |
commit | 025b140b2fd6860039a0d4b545130751473563c5 (patch) | |
tree | 77b126a0f0a4f0e405d4cf7da11546c69c3a0084 /progs/vp | |
parent | 6dc4e6ae15676cf4acdebb9c798bfa4083ad1e14 (diff) |
Add a simple fps counter to the example
Diffstat (limited to 'progs/vp')
-rw-r--r-- | progs/vp/vp-tris.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/progs/vp/vp-tris.c b/progs/vp/vp-tris.c index 5dbe5ac835..e5be65e78c 100644 --- a/progs/vp/vp-tris.c +++ b/progs/vp/vp-tris.c @@ -7,6 +7,8 @@ #include <math.h> #define GL_GLEXT_PROTOTYPES #include <GL/glut.h> +#include <unistd.h> +#include <signal.h> static const char *filename = NULL; static GLuint nr_steps = 4; @@ -18,8 +20,24 @@ static void usage( char *name ) fprintf( stderr, "options:\n" ); fprintf( stderr, " -f flat shaded\n" ); fprintf( stderr, " -nNr subdivision steps\n" ); + fprintf( stderr, " -fps show frames per second\n" ); } +unsigned show_fps = 0; +unsigned int frame_cnt = 0; +void alarmhandler(int); + +void alarmhandler (int sig) +{ + if (sig == SIGALRM) { + printf("%d frames in 5.0 seconds = %.3f FPS\n", frame_cnt, + frame_cnt / 5.0); + + frame_cnt = 0; + } + signal(SIGALRM, alarmhandler); + alarm(5); +} static void args(int argc, char *argv[]) { @@ -32,6 +50,9 @@ static void args(int argc, char *argv[]) else if (strcmp(argv[i], "-f") == 0) { glShadeModel(GL_FLAT); } + else if (strcmp(argv[i], "-fps") == 0) { + show_fps = 1; + } else if (i == argc - 1) { filename = argv[i]; } @@ -168,7 +189,11 @@ static void Display( void ) glEnd(); - glFlush(); + glFlush(); + if (show_fps) { + ++frame_cnt; + glutPostRedisplay(); + } } @@ -211,6 +236,10 @@ int main( int argc, char *argv[] ) glutDisplayFunc( Display ); args( argc, argv ); Init(); + if (show_fps) { + signal(SIGALRM, alarmhandler); + alarm(5); + } glutMainLoop(); return 0; } |