From 530fc5a431ff8e2235ef8ba8385100109ddfb8bf Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 27 May 2015 16:14:15 +0200 Subject: [PATCH] Added full screen support to tearing test. --- tests/CMakeLists.txt | 2 +- tests/tearing.c | 48 ++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 13d5bb76..1f8acc74 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -45,7 +45,7 @@ set_target_properties(empty PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Empty Event") add_executable(sharing WIN32 MACOSX_BUNDLE sharing.c) set_target_properties(sharing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Sharing") -add_executable(tearing WIN32 MACOSX_BUNDLE tearing.c) +add_executable(tearing WIN32 MACOSX_BUNDLE tearing.c ${GETOPT}) set_target_properties(tearing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Tearing") add_executable(threads WIN32 MACOSX_BUNDLE threads.c ${TINYCTHREAD}) diff --git a/tests/tearing.c b/tests/tearing.c index 94865fab..1b65e76d 100644 --- a/tests/tearing.c +++ b/tests/tearing.c @@ -34,9 +34,19 @@ #include #include +#include "getopt.h" + static int swap_interval; static double frame_rate; +static void usage(void) +{ + printf("Usage: iconify [-h] [-f]\n"); + printf("Options:\n"); + printf(" -f create full screen window\n"); + printf(" -h show this help\n"); +} + static void update_window_title(GLFWwindow* window) { char title[256]; @@ -66,23 +76,53 @@ static void framebuffer_size_callback(GLFWwindow* window, int width, int height) static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { - if (key == GLFW_KEY_SPACE && action == GLFW_PRESS) - set_swap_interval(window, 1 - swap_interval); + if (action != GLFW_PRESS) + return; + + switch (key) + { + case GLFW_KEY_SPACE: + set_swap_interval(window, 1 - swap_interval); + break; + case GLFW_KEY_ESCAPE: + glfwSetWindowShouldClose(window, 1); + break; + } } -int main(void) +int main(int argc, char** argv) { + int ch; float position; unsigned long frame_count = 0; double last_time, current_time; + GLboolean fullscreen = GL_FALSE; + GLFWmonitor* monitor = NULL; GLFWwindow* window; + while ((ch = getopt(argc, argv, "fh")) != -1) + { + switch (ch) + { + case 'h': + usage(); + exit(EXIT_SUCCESS); + + case 'f': + fullscreen = GL_TRUE; + break; + } + } + glfwSetErrorCallback(error_callback); if (!glfwInit()) exit(EXIT_FAILURE); - window = glfwCreateWindow(640, 480, "", NULL, NULL); + if (fullscreen) + monitor = glfwGetPrimaryMonitor(); + + window = glfwCreateWindow(640, 480, "", monitor, NULL); if (!window) { glfwTerminate();