From 2d5e5d49191bf0c9d89960ba683541d6b1e7dc92 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sat, 1 Apr 2023 01:39:41 +0200 Subject: [PATCH] fps counter --- src/game.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/game.c b/src/game.c index e11543f..7dbdef8 100644 --- a/src/game.c +++ b/src/game.c @@ -1,6 +1,7 @@ +#include #include #include -#include +#include "miniglut.h" #include #include "game.h" #include "input.h" @@ -55,6 +56,8 @@ void game_shutdown(void) { int i; + putchar('\n'); + for(i=0; idestroy) { screens[i]->destroy(); @@ -64,11 +67,27 @@ void game_shutdown(void) void game_display(void) { + static long nframes, interv, prev_msec; + long msec; + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); cur_scr->display(); game_swap_buffers(); + + + msec = glutGet(GLUT_ELAPSED_TIME); + interv += msec - prev_msec; + prev_msec = msec; + if(interv >= 1000) { + float fps = (float)(nframes * 1000) / interv; + printf("\rfps: %.2f ", fps); + fflush(stdout); + nframes = 0; + interv = 0; + } + nframes++; } void game_reshape(int x, int y) -- 1.7.10.4