frame rate counter

This commit is contained in:
Luca Conte 2024-04-25 16:52:19 +02:00
parent 14ff26f1e3
commit 3f6c99cf21
2 changed files with 27 additions and 2 deletions

View File

@ -28,6 +28,11 @@ GLFWwindow* window;
GLfloat aspectRatio = 1.0f;
double timeBetweenUpdates = 0.2f;
double timeSinceUpdate = 0.0f;
int framesSinceUpdate = 0;
GLfloat step = 0.0f;
const GLfloat pi = 3.14159f;
@ -179,8 +184,25 @@ void init(void) {
glClearColor(0.1f, 0.1f, 0.3f, 1.0f);
}
void updateStats() {
printf("\rFPS: %.1f", framesSinceUpdate / timeSinceUpdate);
fflush(stdout);
}
void draw(void) {
// FPS Counter
framesSinceUpdate++;
double deltaTime = glfwGetTime();
timeSinceUpdate += deltaTime;
glfwSetTime(0.0f);
if (timeSinceUpdate >= timeBetweenUpdates) {
updateStats();
timeSinceUpdate = 0.0f;
framesSinceUpdate = 0;
}
// camera movement
handleInputs();
@ -190,7 +212,7 @@ void draw(void) {
// step for rotations
// counts up to 1.0 and then resets back to 0.0 forever
step += 0.002f;
step += deltaTime / 5;
if (step > 1.0f) step -= 1.0f;
// step multiplied by pi * 2 for use in rotation and trig functions
@ -272,6 +294,9 @@ int main(void) {
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glfwMakeContextCurrent(window);
// disable framerate cap
glfwSwapInterval(0);
// register keyboard event handler
glfwSetKeyCallback(window, keyboardHandler);

View File

@ -53,7 +53,7 @@ ParsedObjFile readObjFile(char* path) {
}
}
printf("Vertices: %d\nFaces: %d\nNormals:%d\nTextures:%d\n", numVertices, numFaces, numVertexNormals, numTextureCoords);
// printf("Vertices: %d\nFaces: %d\nNormals:%d\nTextures:%d\n", numVertices, numFaces, numVertexNormals, numTextureCoords);
vec3* vertices = (vec3*) malloc(sizeof(vec3) * numVertices);
vec3* normals = (vec3*) malloc(sizeof(vec3) * numVertexNormals);