Added gamma setting function.

This commit is contained in:
Camilla Berglund 2012-02-07 02:29:02 +01:00
parent 55a34c6967
commit b35ef1ac53

View File

@ -35,6 +35,8 @@
#include "getopt.h" #include "getopt.h"
#define STEP_SIZE 0.1f
static GLfloat gamma = 1.0f; static GLfloat gamma = 1.0f;
static void usage(void) static void usage(void)
@ -42,6 +44,13 @@ static void usage(void)
printf("Usage: gammatest [-h] [-f]\n"); 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) static void key_callback(GLFWwindow window, int key, int action)
{ {
if (action != GLFW_PRESS) if (action != GLFW_PRESS)
@ -50,22 +59,28 @@ static void key_callback(GLFWwindow window, int key, int action)
switch (key) switch (key)
{ {
case GLFW_KEY_ESCAPE: case GLFW_KEY_ESCAPE:
{
glfwCloseWindow(window); glfwCloseWindow(window);
break; break;
}
case GLFW_KEY_KP_ADD: case GLFW_KEY_KP_ADD:
case GLFW_KEY_Q: case GLFW_KEY_Q:
gamma += 0.1f; {
printf("Gamma: %f\n", gamma); set_gamma(gamma + STEP_SIZE);
glfwSetGamma(gamma);
break; break;
}
case GLFW_KEY_KP_SUBTRACT: case GLFW_KEY_KP_SUBTRACT:
case GLFW_KEY_W: case GLFW_KEY_W:
gamma -= 0.1f; {
printf("Gamma: %f\n", gamma); if (gamma - STEP_SIZE > 0.f)
glfwSetGamma(gamma); set_gamma(gamma - STEP_SIZE);
break; break;
} }
} }
}
static void size_callback(GLFWwindow window, int width, int height) static void size_callback(GLFWwindow window, int width, int height)
{ {
@ -124,8 +139,7 @@ int main(int argc, char** argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
glfwSetGamma(gamma); set_gamma(1.f);
printf("Gamma: %f\n", gamma);
glfwSwapInterval(1); glfwSwapInterval(1);
glfwSetKeyCallback(key_callback); glfwSetKeyCallback(key_callback);