diff --git a/tests/accuracy.c b/tests/accuracy.c index 614f270f..4a3a2b04 100644 --- a/tests/accuracy.c +++ b/tests/accuracy.c @@ -37,6 +37,21 @@ static int cursor_x = 0, cursor_y = 0; static int window_width = 640, window_height = 480; +static int swap_interval = 1; + +static void set_swap_interval(GLFWwindow window, int interval) +{ + char title[256]; + + swap_interval = interval; + glfwSwapInterval(swap_interval); + + snprintf(title, sizeof(title), + "Cursor Inaccuracy Detector (interval %i)", + swap_interval); + + glfwSetWindowTitle(window, title); +} static void window_size_callback(GLFWwindow window, int width, int height) { @@ -56,6 +71,12 @@ static void cursor_position_callback(GLFWwindow window, int x, int y) cursor_y = y; } +static void key_callback(GLFWwindow window, int key, int action) +{ + if (key == GLFW_KEY_SPACE && action == GLFW_PRESS) + set_swap_interval(window, 1 - swap_interval); +} + int main(void) { GLFWwindow window; @@ -66,7 +87,7 @@ int main(void) exit(EXIT_FAILURE); } - window = glfwOpenWindow(window_width, window_height, GLFW_WINDOWED, "Cursor Inaccuracy Detector", NULL); + window = glfwOpenWindow(window_width, window_height, GLFW_WINDOWED, "", NULL); if (!window) { glfwTerminate(); @@ -75,9 +96,11 @@ int main(void) exit(EXIT_FAILURE); } + set_swap_interval(window, swap_interval); + glfwSetCursorPosCallback(cursor_position_callback); glfwSetWindowSizeCallback(window_size_callback); - glfwSwapInterval(1); + glfwSetKeyCallback(key_callback); while (glfwGetCurrentContext()) { diff --git a/tests/tearing.c b/tests/tearing.c index 64819c17..de60f3c7 100644 --- a/tests/tearing.c +++ b/tests/tearing.c @@ -36,15 +36,18 @@ static int swap_interval; -static void set_swap_interval(int value) +static void set_swap_interval(GLFWwindow window, int interval) { char title[256]; - swap_interval = value; + swap_interval = interval; glfwSwapInterval(swap_interval); - sprintf(title, "Tearing detector (interval %i)", swap_interval); - glfwSetWindowTitle(glfwGetCurrentContext(), title); + snprintf(title, sizeof(title), + "Tearing detector (interval %i)", + swap_interval); + + glfwSetWindowTitle(window, title); } static void window_size_callback(GLFWwindow window, int width, int height) @@ -55,7 +58,7 @@ static void window_size_callback(GLFWwindow window, int width, int height) static void key_callback(GLFWwindow window, int key, int action) { if (key == GLFW_KEY_SPACE && action == GLFW_PRESS) - set_swap_interval(!swap_interval); + set_swap_interval(window, 1 - swap_interval); } int main(void) @@ -78,7 +81,7 @@ int main(void) exit(EXIT_FAILURE); } - set_swap_interval(1); + set_swap_interval(window, swap_interval); glfwSetWindowSizeCallback(window_size_callback); glfwSetKeyCallback(key_callback);