mirror of
https://github.com/glfw/glfw.git
synced 2024-11-10 00:51:47 +00:00
Test program swap interval toggling work.
This commit is contained in:
parent
6b46225e33
commit
13ff3eeca9
@ -37,6 +37,21 @@
|
|||||||
|
|
||||||
static int cursor_x = 0, cursor_y = 0;
|
static int cursor_x = 0, cursor_y = 0;
|
||||||
static int window_width = 640, window_height = 480;
|
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)
|
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;
|
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)
|
int main(void)
|
||||||
{
|
{
|
||||||
GLFWwindow window;
|
GLFWwindow window;
|
||||||
@ -66,7 +87,7 @@ int main(void)
|
|||||||
exit(EXIT_FAILURE);
|
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)
|
if (!window)
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
@ -75,9 +96,11 @@ int main(void)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set_swap_interval(window, swap_interval);
|
||||||
|
|
||||||
glfwSetCursorPosCallback(cursor_position_callback);
|
glfwSetCursorPosCallback(cursor_position_callback);
|
||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
glfwSwapInterval(1);
|
glfwSetKeyCallback(key_callback);
|
||||||
|
|
||||||
while (glfwGetCurrentContext())
|
while (glfwGetCurrentContext())
|
||||||
{
|
{
|
||||||
|
@ -36,15 +36,18 @@
|
|||||||
|
|
||||||
static int swap_interval;
|
static int swap_interval;
|
||||||
|
|
||||||
static void set_swap_interval(int value)
|
static void set_swap_interval(GLFWwindow window, int interval)
|
||||||
{
|
{
|
||||||
char title[256];
|
char title[256];
|
||||||
|
|
||||||
swap_interval = value;
|
swap_interval = interval;
|
||||||
glfwSwapInterval(swap_interval);
|
glfwSwapInterval(swap_interval);
|
||||||
|
|
||||||
sprintf(title, "Tearing detector (interval %i)", swap_interval);
|
snprintf(title, sizeof(title),
|
||||||
glfwSetWindowTitle(glfwGetCurrentContext(), title);
|
"Tearing detector (interval %i)",
|
||||||
|
swap_interval);
|
||||||
|
|
||||||
|
glfwSetWindowTitle(window, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void window_size_callback(GLFWwindow window, int width, int height)
|
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)
|
static void key_callback(GLFWwindow window, int key, int action)
|
||||||
{
|
{
|
||||||
if (key == GLFW_KEY_SPACE && action == GLFW_PRESS)
|
if (key == GLFW_KEY_SPACE && action == GLFW_PRESS)
|
||||||
set_swap_interval(!swap_interval);
|
set_swap_interval(window, 1 - swap_interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
@ -78,7 +81,7 @@ int main(void)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
set_swap_interval(1);
|
set_swap_interval(window, swap_interval);
|
||||||
|
|
||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
glfwSetKeyCallback(key_callback);
|
glfwSetKeyCallback(key_callback);
|
||||||
|
Loading…
Reference in New Issue
Block a user