frame rate counter
This commit is contained in:
parent
14ff26f1e3
commit
3f6c99cf21
27
u06-2/main.c
27
u06-2/main.c
|
@ -28,6 +28,11 @@ GLFWwindow* window;
|
||||||
|
|
||||||
GLfloat aspectRatio = 1.0f;
|
GLfloat aspectRatio = 1.0f;
|
||||||
|
|
||||||
|
double timeBetweenUpdates = 0.2f;
|
||||||
|
|
||||||
|
double timeSinceUpdate = 0.0f;
|
||||||
|
int framesSinceUpdate = 0;
|
||||||
|
|
||||||
GLfloat step = 0.0f;
|
GLfloat step = 0.0f;
|
||||||
const GLfloat pi = 3.14159f;
|
const GLfloat pi = 3.14159f;
|
||||||
|
|
||||||
|
@ -179,8 +184,25 @@ void init(void) {
|
||||||
glClearColor(0.1f, 0.1f, 0.3f, 1.0f);
|
glClearColor(0.1f, 0.1f, 0.3f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateStats() {
|
||||||
|
printf("\rFPS: %.1f", framesSinceUpdate / timeSinceUpdate);
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
|
||||||
void draw(void) {
|
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
|
// camera movement
|
||||||
handleInputs();
|
handleInputs();
|
||||||
|
|
||||||
|
@ -190,7 +212,7 @@ void draw(void) {
|
||||||
|
|
||||||
// step for rotations
|
// step for rotations
|
||||||
// counts up to 1.0 and then resets back to 0.0 forever
|
// 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;
|
if (step > 1.0f) step -= 1.0f;
|
||||||
|
|
||||||
// step multiplied by pi * 2 for use in rotation and trig functions
|
// step multiplied by pi * 2 for use in rotation and trig functions
|
||||||
|
@ -272,6 +294,9 @@ int main(void) {
|
||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(window);
|
||||||
|
|
||||||
|
// disable framerate cap
|
||||||
|
glfwSwapInterval(0);
|
||||||
|
|
||||||
// register keyboard event handler
|
// register keyboard event handler
|
||||||
glfwSetKeyCallback(window, keyboardHandler);
|
glfwSetKeyCallback(window, keyboardHandler);
|
||||||
|
|
||||||
|
|
|
@ -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* vertices = (vec3*) malloc(sizeof(vec3) * numVertices);
|
||||||
vec3* normals = (vec3*) malloc(sizeof(vec3) * numVertexNormals);
|
vec3* normals = (vec3*) malloc(sizeof(vec3) * numVertexNormals);
|
||||||
|
|
Loading…
Reference in New Issue