mirror of
https://github.com/glfw/glfw.git
synced 2024-11-25 22:14:34 +00:00
Added refresh rate calculation to tearing test.
This commit is contained in:
parent
19cfc5e6f2
commit
f966ff894a
@ -35,19 +35,25 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
static int swap_interval;
|
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];
|
char title[256];
|
||||||
|
|
||||||
swap_interval = interval;
|
sprintf(title, "Tearing detector (interval %i, %0.1f Hz)",
|
||||||
glfwSwapInterval(swap_interval);
|
swap_interval, frame_rate);
|
||||||
|
|
||||||
sprintf(title, "Tearing detector (interval %i)", swap_interval);
|
|
||||||
|
|
||||||
glfwSetWindowTitle(window, title);
|
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)
|
static void error_callback(int error, const char* description)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Error: %s\n", description);
|
fprintf(stderr, "Error: %s\n", description);
|
||||||
@ -67,6 +73,8 @@ static void key_callback(GLFWwindow* window, int key, int action)
|
|||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
float position;
|
float position;
|
||||||
|
unsigned long frame_count = 0;
|
||||||
|
double last_time, current_time;
|
||||||
GLFWwindow* window;
|
GLFWwindow* window;
|
||||||
|
|
||||||
glfwSetErrorCallback(error_callback);
|
glfwSetErrorCallback(error_callback);
|
||||||
@ -82,7 +90,10 @@ int main(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
glfwMakeContextCurrent(window);
|
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);
|
glfwSetWindowSizeCallback(window, window_size_callback);
|
||||||
glfwSetKeyCallback(window, key_callback);
|
glfwSetKeyCallback(window, key_callback);
|
||||||
@ -100,6 +111,17 @@ int main(void)
|
|||||||
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
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();
|
glfwTerminate();
|
||||||
|
Loading…
Reference in New Issue
Block a user