Add FPS counter and unlock webcam framerate

Maybe disable webcam view altogether and make it a compiler flag?
This commit is contained in:
Epicalert 2021-03-18 18:59:04 +08:00
parent 3220795821
commit ed6323d7e5
No known key found for this signature in database
GPG key ID: CAA46F858D0979BD
2 changed files with 23 additions and 2 deletions

View file

@ -131,5 +131,5 @@ void cvFrame() {
void cvShowFrame() { void cvShowFrame() {
cv::imshow("Video Input", frame); cv::imshow("Video Input", frame);
cv::waitKey(32); cv::waitKey(1);
} }

View file

@ -10,7 +10,10 @@
#include <webp/decode.h> #include <webp/decode.h>
#include <fmt/core.h>
#include <iostream> #include <iostream>
#include <chrono>
#include <graphics.hpp> #include <graphics.hpp>
#include <modelpart.hpp> #include <modelpart.hpp>
@ -26,6 +29,9 @@ GLuint transUniform; //location of the "transMatrix" transformation matrix unifo
float windowAspectRatio; float windowAspectRatio;
int frameCount;
std::chrono::high_resolution_clock::time_point secondStart;
//parts of the model (see modelpart.hpp) //parts of the model (see modelpart.hpp)
Model* model; Model* model;
@ -76,6 +82,13 @@ void initBuffers (GLuint* vaoNum) {
glEnableVertexAttribArray(uvAttr); 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 () { void initGraphics () {
int argc = 1; int argc = 1;
char *argv[1] = {(char*)"fc2d"}; char *argv[1] = {(char*)"fc2d"};
@ -91,7 +104,7 @@ void initGraphics () {
model = new Model(resolvePath(("models/"+optData.model+".fma").c_str()).c_str()); 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 //enable blending for alpha textures
glEnable(GL_BLEND); glEnable(GL_BLEND);
@ -191,6 +204,14 @@ void initShader() {
void graphicsFrame () { void graphicsFrame () {
glutMainLoopEvent(); glutMainLoopEvent();
auto timeSinceSecondStart = std::chrono::high_resolution_clock::now() - secondStart;
frameCount++;
long usSinceSecondStart = std::chrono::duration_cast<std::chrono::microseconds>(timeSinceSecondStart).count();
if (usSinceSecondStart >= 1000000) {
fpsCounterReset();
}
} }
void printShaderCompileLog(GLuint shader) { void printShaderCompileLog(GLuint shader) {