commit 26a453a70420dc463e873f845f39d0af4af82fc5 Author: Alexander Popov Date: Sat Sep 12 20:58:39 2015 +0300 added fps counter diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f0605f6 --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +CC=gcc + +all: fps_counter + +fps_counter: + $(CC) fps_counter.c -lglfw -lGL -o fps_counter diff --git a/fps_counter.c b/fps_counter.c new file mode 100644 index 0000000..32ae0e5 --- /dev/null +++ b/fps_counter.c @@ -0,0 +1,65 @@ +/* + GLFW3 frame rate counter example + Source: https://github.com/IIIypuk/glfw-examples + + Compile: gcc fps_counter.c -lglfw -lGL +*/ +#include +#include "GLFW/glfw3.h" + +int main() +{ + GLFWwindow *window; + if (!glfwInit()) + return -1; + + glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); + window = glfwCreateWindow(400, 400, "FPS Counter", NULL, NULL); + + if (!window) + { + glfwTerminate(); + return -1; + } + + glfwMakeContextCurrent(window); + + int frames = 0; + double t, t0, fps; + char title_string[200]; + + t0 = glfwGetTime(); + + while (!glfwWindowShouldClose(window)) + { + glClearColor(0.2, 0.8, 0.3, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + + glRotatef(1, 0.2, 0.2, 0); + glBegin(GL_POLYGON); + glColor3f(0.4, 0.3, 1.0); + glVertex3f(-0.8, 0.8, 0.0); + glVertex3f( 0.8, 0.8, 0.0); + glVertex3f( 0.8, -0.8, 0.0); + glVertex3f(-0.8, -0.8, 0.0); + glEnd(); + + t = glfwGetTime(); + + if((t - t0) > 1.0 || frames == 0) + { + fps = (double)frames / (t - t0); + sprintf(title_string, "FPS: %.1f FPS", fps); + glfwSetWindowTitle(window, title_string); + t0 = t; + frames = 0; + } + frames ++; + + glfwSwapBuffers(window); + glfwPollEvents(); + } + + glfwTerminate(); + return 0; +}