From b35ef1ac5316237cb6de61634f2aa92672b5b336 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 7 Feb 2012 02:29:02 +0100 Subject: [PATCH] Added gamma setting function. --- tests/gamma.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/tests/gamma.c b/tests/gamma.c index 33db05e1..d6bb17f4 100644 --- a/tests/gamma.c +++ b/tests/gamma.c @@ -35,6 +35,8 @@ #include "getopt.h" +#define STEP_SIZE 0.1f + static GLfloat gamma = 1.0f; static void usage(void) @@ -42,6 +44,13 @@ static void usage(void) printf("Usage: gammatest [-h] [-f]\n"); } +static void set_gamma(float value) +{ + gamma = value; + printf("Gamma: %f\n", gamma); + glfwSetGamma(gamma); +} + static void key_callback(GLFWwindow window, int key, int action) { if (action != GLFW_PRESS) @@ -50,20 +59,26 @@ static void key_callback(GLFWwindow window, int key, int action) switch (key) { case GLFW_KEY_ESCAPE: + { glfwCloseWindow(window); break; + } + case GLFW_KEY_KP_ADD: case GLFW_KEY_Q: - gamma += 0.1f; - printf("Gamma: %f\n", gamma); - glfwSetGamma(gamma); + { + set_gamma(gamma + STEP_SIZE); break; + } + case GLFW_KEY_KP_SUBTRACT: case GLFW_KEY_W: - gamma -= 0.1f; - printf("Gamma: %f\n", gamma); - glfwSetGamma(gamma); + { + if (gamma - STEP_SIZE > 0.f) + set_gamma(gamma - STEP_SIZE); + break; + } } } @@ -124,8 +139,7 @@ int main(int argc, char** argv) exit(EXIT_FAILURE); } - glfwSetGamma(gamma); - printf("Gamma: %f\n", gamma); + set_gamma(1.f); glfwSwapInterval(1); glfwSetKeyCallback(key_callback);