From 62e8d07f4fe35807320f6f3e41c47707dbc1c849 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 9 Feb 2012 00:49:11 +0100 Subject: [PATCH] Added swap interval toggling to tearing test. --- tests/tearing.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/tearing.c b/tests/tearing.c index 10170b0f..4917ca68 100644 --- a/tests/tearing.c +++ b/tests/tearing.c @@ -34,11 +34,30 @@ #include #include +static int swap_interval; + +static void set_swap_interval(int value) +{ + char title[256]; + + swap_interval = value; + glfwSwapInterval(swap_interval); + + sprintf(title, "Tearing detector (interval %i)", swap_interval); + glfwSetWindowTitle(glfwGetCurrentContext(), title); +} + static void window_size_callback(GLFWwindow window, int width, int height) { glViewport(0, 0, width, height); } +static void key_callback(GLFWwindow window, int key, int action) +{ + if (key == GLFW_KEY_SPACE && action == GLFW_PRESS) + set_swap_interval(!swap_interval); +} + int main(void) { float position; @@ -60,7 +79,8 @@ int main(void) } glfwSetWindowSizeCallback(window_size_callback); - glfwSwapInterval(1); + glfwSetKeyCallback(key_callback); + set_swap_interval(1); glMatrixMode(GL_PROJECTION); glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f);