Skip to content

Commit

Permalink
Test program swap interval toggling work.
Browse files Browse the repository at this point in the history
  • Loading branch information
elmindreda committed Aug 3, 2012
1 parent 6b46225 commit 13ff3ee
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
27 changes: 25 additions & 2 deletions tests/accuracy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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())
{
Expand Down
15 changes: 9 additions & 6 deletions tests/tearing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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);
Expand Down

0 comments on commit 13ff3ee

Please sign in to comment.