From adc3de3882824f82825933e7d36f372a1672d317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9verin=20Lemaignan?= Date: Tue, 23 Oct 2012 14:26:42 +0200 Subject: [PATCH] Compute and display FPS in Simple_OpenGL demo application --- samples/SimpleOpenGL/Sample_SimpleOpenGL.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/samples/SimpleOpenGL/Sample_SimpleOpenGL.c b/samples/SimpleOpenGL/Sample_SimpleOpenGL.c index a2b4502e2..921046a44 100644 --- a/samples/SimpleOpenGL/Sample_SimpleOpenGL.c +++ b/samples/SimpleOpenGL/Sample_SimpleOpenGL.c @@ -11,6 +11,7 @@ // ---------------------------------------------------------------------------- #include +#include #include @@ -235,11 +236,23 @@ void recursive_render (const struct aiScene *sc, const struct aiNode* nd) void do_motion (void) { static GLint prev_time = 0; + static GLint prev_fps_time = 0; + static int frames = 0; int time = glutGet(GLUT_ELAPSED_TIME); angle += (time-prev_time)*0.01; prev_time = time; + frames += 1; + if ((time - prev_fps_time) > 1000) // update every seconds + { + int current_fps = frames * 1000 / (time - prev_fps_time); + printf("%d fps\n", current_fps); + frames = 0; + prev_fps_time = time; + } + + glutPostRedisplay (); }