From 4649c33832ed57be428fea524d5f8812832bf59c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Sat, 1 Jun 2019 19:22:55 +0200 Subject: [PATCH] Add FPS --- testSDL.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/testSDL.c b/testSDL.c index 4e8d1bd..d62c240 100644 --- a/testSDL.c +++ b/testSDL.c @@ -6,6 +6,7 @@ #include #include #include +#include //#define S3L_PRESET_HIGHEST_QUALITY @@ -164,6 +165,10 @@ else S3L_Transform3D modelTransform; S3L_DrawConfig conf; +clock_t nextT; + +int fps = 0; + void draw() { S3L_newFrame(); @@ -181,6 +186,19 @@ void draw() if (offScreenPixels > 0) printf("offscreen pixels: %d\n",offScreenPixels); + + clock_t nowT = clock(); + + double timeDiff = ((double) (nowT - nextT)) / CLOCKS_PER_SEC; + + fps++; + + if (timeDiff >= 1.0) + { + nextT = nowT; + printf("FPS: %d\n",fps); + fps = 0; + } } int main() @@ -191,6 +209,8 @@ int main() SDL_Surface *screenSurface = SDL_GetWindowSurface(window); SDL_Event event; + nextT = clock(); + S3L_initCamera(&scene.camera); // scene.camera.transform.translation.z = -S3L_FRACTIONS_PER_UNIT * 2;