1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-23 02:38:52 -05:00

Added refresh rate calculation to tearing test.

This commit is contained in:
Camilla Berglund 2013-05-19 19:18:18 +02:00
parent 19cfc5e6f2
commit f966ff894a

View File

@ -35,19 +35,25 @@
#include <math.h>
static int swap_interval;
static double frame_rate;
static void set_swap_interval(GLFWwindow* window, int interval)
static void update_window_title(GLFWwindow* window)
{
char title[256];
swap_interval = interval;
glfwSwapInterval(swap_interval);
sprintf(title, "Tearing detector (interval %i)", swap_interval);
sprintf(title, "Tearing detector (interval %i, %0.1f Hz)",
swap_interval, frame_rate);
glfwSetWindowTitle(window, title);
}
static void set_swap_interval(GLFWwindow* window, int interval)
{
swap_interval = interval;
glfwSwapInterval(swap_interval);
update_window_title(window);
}
static void error_callback(int error, const char* description)
{
fprintf(stderr, "Error: %s\n", description);
@ -67,6 +73,8 @@ static void key_callback(GLFWwindow* window, int key, int action)
int main(void)
{
float position;
unsigned long frame_count = 0;
double last_time, current_time;
GLFWwindow* window;
glfwSetErrorCallback(error_callback);
@ -82,7 +90,10 @@ int main(void)
}
glfwMakeContextCurrent(window);
set_swap_interval(window, swap_interval);
set_swap_interval(window, 0);
last_time = glfwGetTime();
frame_rate = 0.0;
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSetKeyCallback(window, key_callback);
@ -100,6 +111,17 @@ int main(void)
glfwSwapBuffers(window);
glfwPollEvents();
frame_count++;
current_time = glfwGetTime();
if (current_time - last_time > 1.0)
{
frame_rate = frame_count / (current_time - last_time);
frame_count = 0;
last_time = current_time;
update_window_title(window);
}
}
glfwTerminate();