From ed6323d7e5f4e3ceee7e4054efb306ba8445c552 Mon Sep 17 00:00:00 2001 From: Epicalert Date: Thu, 18 Mar 2021 18:59:04 +0800 Subject: [PATCH] Add FPS counter and unlock webcam framerate Maybe disable webcam view altogether and make it a compiler flag? --- src/cv.cpp | 2 +- src/graphics.cpp | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/cv.cpp b/src/cv.cpp index ff0c7ee..281a555 100644 --- a/src/cv.cpp +++ b/src/cv.cpp @@ -131,5 +131,5 @@ void cvFrame() { void cvShowFrame() { cv::imshow("Video Input", frame); - cv::waitKey(32); + cv::waitKey(1); } diff --git a/src/graphics.cpp b/src/graphics.cpp index baba755..d9065e8 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -10,7 +10,10 @@ #include +#include + #include +#include #include #include @@ -26,6 +29,9 @@ GLuint transUniform; //location of the "transMatrix" transformation matrix unifo float windowAspectRatio; +int frameCount; +std::chrono::high_resolution_clock::time_point secondStart; + //parts of the model (see modelpart.hpp) Model* model; @@ -76,6 +82,13 @@ void initBuffers (GLuint* vaoNum) { glEnableVertexAttribArray(uvAttr); } +void fpsCounterReset() { + glutSetWindowTitle(fmt::format("{0} - {1} @ {2} FPS", PROJECT_NAME, model->getName(), frameCount).c_str()); + + secondStart = std::chrono::high_resolution_clock::now(); + frameCount = 0; +} + void initGraphics () { int argc = 1; char *argv[1] = {(char*)"fc2d"}; @@ -91,7 +104,7 @@ void initGraphics () { model = new Model(resolvePath(("models/"+optData.model+".fma").c_str()).c_str()); - glutSetWindowTitle((PROJECT_NAME " - " + model->getName()).c_str()); + fpsCounterReset(); //enable blending for alpha textures glEnable(GL_BLEND); @@ -191,6 +204,14 @@ void initShader() { void graphicsFrame () { glutMainLoopEvent(); + + auto timeSinceSecondStart = std::chrono::high_resolution_clock::now() - secondStart; + frameCount++; + long usSinceSecondStart = std::chrono::duration_cast(timeSinceSecondStart).count(); + + if (usSinceSecondStart >= 1000000) { + fpsCounterReset(); + } } void printShaderCompileLog(GLuint shader) {