add fps display
This commit is contained in:
parent
6b87b05634
commit
9516aeeb6a
32
src/main.c
32
src/main.c
|
@ -2,11 +2,15 @@
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "shader.h"
|
#include "shader.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "src/shader.h"
|
#include "src/shader.h"
|
||||||
|
|
||||||
|
#define STATUS_INTERVAL 0.5
|
||||||
|
|
||||||
GLuint program;
|
GLuint program;
|
||||||
|
|
||||||
GLuint vertexArrayObject;
|
GLuint vertexArrayObject;
|
||||||
|
@ -14,6 +18,27 @@ GLuint vertexArrayObject;
|
||||||
GLuint initialWindowWidth = 800;
|
GLuint initialWindowWidth = 800;
|
||||||
GLuint initialWindowHeight = 600;
|
GLuint initialWindowHeight = 600;
|
||||||
|
|
||||||
|
int frameCount = 0;
|
||||||
|
struct timespec last_time, current_time;
|
||||||
|
|
||||||
|
void initialiseStatusDisplay() {
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &last_time);
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateStatusDisplay() {
|
||||||
|
frameCount++;
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, ¤t_time);
|
||||||
|
double elapsed = (current_time.tv_sec - last_time.tv_sec) +
|
||||||
|
(current_time.tv_nsec - last_time.tv_nsec) / 1e9;
|
||||||
|
if (elapsed >= STATUS_INTERVAL) {
|
||||||
|
double fps = frameCount / elapsed;
|
||||||
|
frameCount = 0;
|
||||||
|
last_time = current_time;
|
||||||
|
printf("\rFPS: %.2f ", fps);
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void init(void) {
|
void init(void) {
|
||||||
INFO("Compiling Shaders...");
|
INFO("Compiling Shaders...");
|
||||||
|
|
||||||
|
@ -55,12 +80,14 @@ void init(void) {
|
||||||
0.5f, -0.5f, 1.0f, 1.0f, 0.0f
|
0.5f, -0.5f, 1.0f, 1.0f, 0.0f
|
||||||
};
|
};
|
||||||
|
|
||||||
|
DEBUG("Creating vertext buffer");
|
||||||
GLuint vertexBuffer;
|
GLuint vertexBuffer;
|
||||||
glGenBuffers(1, &vertexBuffer);
|
glGenBuffers(1, &vertexBuffer);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
|
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(triangleVertices), triangleVertices, GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, sizeof(triangleVertices), triangleVertices, GL_STATIC_DRAW);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
|
||||||
|
DEBUG("Creating vertex array object");
|
||||||
// create vertex array object
|
// create vertex array object
|
||||||
glGenVertexArrays(1, &vertexArrayObject);
|
glGenVertexArrays(1, &vertexArrayObject);
|
||||||
glBindVertexArray(vertexArrayObject);
|
glBindVertexArray(vertexArrayObject);
|
||||||
|
@ -86,9 +113,14 @@ void init(void) {
|
||||||
|
|
||||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
||||||
glViewport(0, 0, initialWindowWidth, initialWindowHeight);
|
glViewport(0, 0, initialWindowWidth, initialWindowHeight);
|
||||||
|
|
||||||
|
initialiseStatusDisplay();
|
||||||
|
|
||||||
|
INFO("--- Initialisation done ---");
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw(void) {
|
void draw(void) {
|
||||||
|
updateStatusDisplay();
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
glUseProgram(program);
|
glUseProgram(program);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue