2010-10-12 22:04:43 -04:00
|
|
|
//========================================================================
|
|
|
|
// Gamma correction test program
|
2016-11-21 10:23:59 -05:00
|
|
|
// Copyright (c) Camilla Löwy <elmindreda@glfw.org>
|
2010-10-12 22:04:43 -04:00
|
|
|
//
|
|
|
|
// This software is provided 'as-is', without any express or implied
|
|
|
|
// warranty. In no event will the authors be held liable for any damages
|
|
|
|
// arising from the use of this software.
|
|
|
|
//
|
|
|
|
// Permission is granted to anyone to use this software for any purpose,
|
|
|
|
// including commercial applications, and to alter it and redistribute it
|
|
|
|
// freely, subject to the following restrictions:
|
|
|
|
//
|
|
|
|
// 1. The origin of this software must not be misrepresented; you must not
|
|
|
|
// claim that you wrote the original software. If you use this software
|
|
|
|
// in a product, an acknowledgment in the product documentation would
|
|
|
|
// be appreciated but is not required.
|
|
|
|
//
|
|
|
|
// 2. Altered source versions must be plainly marked as such, and must not
|
|
|
|
// be misrepresented as being the original software.
|
|
|
|
//
|
|
|
|
// 3. This notice may not be removed or altered from any source
|
|
|
|
// distribution.
|
|
|
|
//
|
|
|
|
//========================================================================
|
|
|
|
//
|
|
|
|
// This program is used to test the gamma correction functionality for
|
2015-01-05 15:55:15 -05:00
|
|
|
// both full screen and windowed mode windows
|
2010-10-12 22:04:43 -04:00
|
|
|
//
|
|
|
|
//========================================================================
|
|
|
|
|
2021-08-24 19:18:03 -04:00
|
|
|
#define GLAD_GL_IMPLEMENTATION
|
2019-04-14 11:34:38 -04:00
|
|
|
#include <glad/gl.h>
|
2019-05-24 11:17:15 -04:00
|
|
|
#define GLFW_INCLUDE_NONE
|
2013-05-22 16:46:34 -04:00
|
|
|
#include <GLFW/glfw3.h>
|
2010-10-12 22:04:43 -04:00
|
|
|
|
2016-09-26 08:57:03 -04:00
|
|
|
#define NK_IMPLEMENTATION
|
|
|
|
#define NK_INCLUDE_FIXED_TYPES
|
|
|
|
#define NK_INCLUDE_FONT_BAKING
|
|
|
|
#define NK_INCLUDE_DEFAULT_FONT
|
|
|
|
#define NK_INCLUDE_DEFAULT_ALLOCATOR
|
|
|
|
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
|
|
|
|
#define NK_INCLUDE_STANDARD_VARARGS
|
2017-11-26 16:12:41 -05:00
|
|
|
#define NK_BUTTON_TRIGGER_ON_RELEASE
|
2016-09-26 08:57:03 -04:00
|
|
|
#include <nuklear.h>
|
|
|
|
|
|
|
|
#define NK_GLFW_GL2_IMPLEMENTATION
|
|
|
|
#include <nuklear_glfw_gl2.h>
|
|
|
|
|
2010-10-12 22:04:43 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2017-11-28 08:20:54 -05:00
|
|
|
#include <string.h>
|
2010-10-12 22:04:43 -04:00
|
|
|
|
2012-12-29 19:42:14 -05:00
|
|
|
static void error_callback(int error, const char* description)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Error: %s\n", description);
|
|
|
|
}
|
|
|
|
|
2013-05-30 11:19:12 -04:00
|
|
|
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
2010-10-12 22:04:43 -04:00
|
|
|
{
|
2016-09-26 08:57:03 -04:00
|
|
|
if (action == GLFW_PRESS && key == GLFW_KEY_ESCAPE)
|
|
|
|
glfwSetWindowShouldClose(window, GLFW_TRUE);
|
|
|
|
}
|
2010-10-12 22:04:43 -04:00
|
|
|
|
2016-09-26 08:57:03 -04:00
|
|
|
static void chart_ramp_array(struct nk_context* nk,
|
|
|
|
struct nk_color color,
|
|
|
|
int count, unsigned short int* values)
|
|
|
|
{
|
|
|
|
if (nk_chart_begin_colored(nk, NK_CHART_LINES,
|
|
|
|
color, nk_rgb(255, 255, 255),
|
|
|
|
count, 0, 65535))
|
2010-10-12 22:04:43 -04:00
|
|
|
{
|
2016-09-26 08:57:03 -04:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < count; i++)
|
2012-02-06 20:29:02 -05:00
|
|
|
{
|
2016-09-26 08:57:03 -04:00
|
|
|
char buffer[1024];
|
|
|
|
if (nk_chart_push(nk, values[i]))
|
|
|
|
{
|
|
|
|
snprintf(buffer, sizeof(buffer), "#%u: %u (%0.5f) ",
|
|
|
|
i, values[i], values[i] / 65535.f);
|
|
|
|
nk_tooltip(nk, buffer);
|
|
|
|
}
|
2012-02-06 20:29:02 -05:00
|
|
|
}
|
|
|
|
|
2016-09-26 08:57:03 -04:00
|
|
|
nk_chart_end(nk);
|
2010-10-12 22:04:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2013-01-05 15:13:28 -05:00
|
|
|
GLFWmonitor* monitor = NULL;
|
|
|
|
GLFWwindow* window;
|
2017-11-26 16:12:41 -05:00
|
|
|
GLFWgammaramp orig_ramp;
|
2016-09-26 08:57:03 -04:00
|
|
|
struct nk_context* nk;
|
|
|
|
struct nk_font_atlas* atlas;
|
|
|
|
float gamma_value = 1.f;
|
2010-10-12 22:04:43 -04:00
|
|
|
|
2013-02-18 19:57:00 -05:00
|
|
|
glfwSetErrorCallback(error_callback);
|
|
|
|
|
|
|
|
if (!glfwInit())
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
2016-09-26 08:57:03 -04:00
|
|
|
monitor = glfwGetPrimaryMonitor();
|
2010-10-12 22:04:43 -04:00
|
|
|
|
2018-08-31 07:33:48 -04:00
|
|
|
glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE);
|
2019-08-20 13:00:59 -04:00
|
|
|
glfwWindowHint(GLFW_WIN32_KEYBOARD_MENU, GLFW_TRUE);
|
2018-08-31 07:33:48 -04:00
|
|
|
|
2016-09-26 08:57:03 -04:00
|
|
|
window = glfwCreateWindow(800, 400, "Gamma Test", NULL, NULL);
|
2010-10-12 22:04:43 -04:00
|
|
|
if (!window)
|
|
|
|
{
|
|
|
|
glfwTerminate();
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2017-11-26 16:12:41 -05:00
|
|
|
{
|
|
|
|
const GLFWgammaramp* ramp = glfwGetGammaRamp(monitor);
|
|
|
|
const size_t array_size = ramp->size * sizeof(short);
|
|
|
|
orig_ramp.size = ramp->size;
|
|
|
|
orig_ramp.red = malloc(array_size);
|
|
|
|
orig_ramp.green = malloc(array_size);
|
|
|
|
orig_ramp.blue = malloc(array_size);
|
|
|
|
memcpy(orig_ramp.red, ramp->red, array_size);
|
|
|
|
memcpy(orig_ramp.green, ramp->green, array_size);
|
|
|
|
memcpy(orig_ramp.blue, ramp->blue, array_size);
|
|
|
|
}
|
|
|
|
|
2012-08-10 09:29:45 -04:00
|
|
|
glfwMakeContextCurrent(window);
|
2019-04-14 11:34:38 -04:00
|
|
|
gladLoadGL(glfwGetProcAddress);
|
2010-10-12 22:04:43 -04:00
|
|
|
glfwSwapInterval(1);
|
2012-08-10 09:29:45 -04:00
|
|
|
|
2016-09-26 08:57:03 -04:00
|
|
|
nk = nk_glfw3_init(window, NK_GLFW3_INSTALL_CALLBACKS);
|
|
|
|
nk_glfw3_font_stash_begin(&atlas);
|
|
|
|
nk_glfw3_font_stash_end();
|
2010-10-12 22:04:43 -04:00
|
|
|
|
2016-09-26 08:57:03 -04:00
|
|
|
glfwSetKeyCallback(window, key_callback);
|
2010-10-12 22:04:43 -04:00
|
|
|
|
2013-03-01 07:45:12 -05:00
|
|
|
while (!glfwWindowShouldClose(window))
|
2010-10-12 22:04:43 -04:00
|
|
|
{
|
2016-09-26 08:57:03 -04:00
|
|
|
int width, height;
|
|
|
|
struct nk_rect area;
|
|
|
|
|
2016-09-28 09:51:05 -04:00
|
|
|
glfwGetWindowSize(window, &width, &height);
|
2016-09-26 08:57:03 -04:00
|
|
|
area = nk_rect(0.f, 0.f, (float) width, (float) height);
|
2017-12-17 13:27:27 -05:00
|
|
|
nk_window_set_bounds(nk, "", area);
|
2016-09-26 08:57:03 -04:00
|
|
|
|
2010-10-12 22:04:43 -04:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2016-09-26 08:57:03 -04:00
|
|
|
nk_glfw3_new_frame();
|
2016-11-27 07:29:07 -05:00
|
|
|
if (nk_begin(nk, "", area, 0))
|
2016-09-26 08:57:03 -04:00
|
|
|
{
|
2017-11-26 16:12:41 -05:00
|
|
|
const GLFWgammaramp* ramp;
|
2016-09-26 08:57:03 -04:00
|
|
|
|
2017-11-26 16:12:41 -05:00
|
|
|
nk_layout_row_dynamic(nk, 30, 3);
|
2016-09-26 08:57:03 -04:00
|
|
|
if (nk_slider_float(nk, 0.1f, &gamma_value, 5.f, 0.1f))
|
|
|
|
glfwSetGamma(monitor, gamma_value);
|
|
|
|
nk_labelf(nk, NK_TEXT_LEFT, "%0.1f", gamma_value);
|
2017-11-26 16:12:41 -05:00
|
|
|
if (nk_button_label(nk, "Revert"))
|
|
|
|
glfwSetGammaRamp(monitor, &orig_ramp);
|
|
|
|
|
|
|
|
ramp = glfwGetGammaRamp(monitor);
|
2016-09-26 08:57:03 -04:00
|
|
|
|
|
|
|
nk_layout_row_dynamic(nk, height - 60.f, 3);
|
|
|
|
chart_ramp_array(nk, nk_rgb(255, 0, 0), ramp->size, ramp->red);
|
|
|
|
chart_ramp_array(nk, nk_rgb(0, 255, 0), ramp->size, ramp->green);
|
2017-12-18 09:47:49 -05:00
|
|
|
chart_ramp_array(nk, nk_rgb(0, 0, 255), ramp->size, ramp->blue);
|
2016-09-26 08:57:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
nk_end(nk);
|
2017-07-30 08:52:26 -04:00
|
|
|
nk_glfw3_render(NK_ANTI_ALIASING_ON);
|
2010-10-12 22:04:43 -04:00
|
|
|
|
2012-08-06 12:13:37 -04:00
|
|
|
glfwSwapBuffers(window);
|
2016-09-26 08:57:03 -04:00
|
|
|
glfwWaitEventsTimeout(1.0);
|
2010-10-12 22:04:43 -04:00
|
|
|
}
|
|
|
|
|
2017-11-26 16:12:41 -05:00
|
|
|
free(orig_ramp.red);
|
|
|
|
free(orig_ramp.green);
|
|
|
|
free(orig_ramp.blue);
|
|
|
|
|
2016-09-26 08:57:03 -04:00
|
|
|
nk_glfw3_shutdown();
|
2010-10-12 22:04:43 -04:00
|
|
|
glfwTerminate();
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|