gamma.c
Go to the documentation of this file.
1 //========================================================================
2 // Gamma correction test program
3 // Copyright (c) Camilla Löwy <elmindreda@glfw.org>
4 //
5 // This software is provided 'as-is', without any express or implied
6 // warranty. In no event will the authors be held liable for any damages
7 // arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it
11 // freely, subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented; you must not
14 // claim that you wrote the original software. If you use this software
15 // in a product, an acknowledgment in the product documentation would
16 // be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such, and must not
19 // be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source
22 // distribution.
23 //
24 //========================================================================
25 //
26 // This program is used to test the gamma correction functionality for
27 // both full screen and windowed mode windows
28 //
29 //========================================================================
30 
31 #include <glad/glad.h>
32 #include <GLFW/glfw3.h>
33 
34 #define NK_IMPLEMENTATION
35 #define NK_INCLUDE_FIXED_TYPES
36 #define NK_INCLUDE_FONT_BAKING
37 #define NK_INCLUDE_DEFAULT_FONT
38 #define NK_INCLUDE_DEFAULT_ALLOCATOR
39 #define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
40 #define NK_INCLUDE_STANDARD_VARARGS
41 #define NK_BUTTON_TRIGGER_ON_RELEASE
42 #include <nuklear.h>
43 
44 #define NK_GLFW_GL2_IMPLEMENTATION
45 #include <nuklear_glfw_gl2.h>
46 
47 #include <stdio.h>
48 #include <stdlib.h>
49 #include <string.h>
50 
51 static void error_callback(int error, const char* description)
52 {
53  fprintf(stderr, "Error: %s\n", description);
54 }
55 
56 static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
57 {
58  if (action == GLFW_PRESS && key == GLFW_KEY_ESCAPE)
60 }
61 
62 static void chart_ramp_array(struct nk_context* nk,
63  struct nk_color color,
64  int count, unsigned short int* values)
65 {
67  color, nk_rgb(255, 255, 255),
68  count, 0, 65535))
69  {
70  int i;
71  for (i = 0; i < count; i++)
72  {
73  char buffer[1024];
74  if (nk_chart_push(nk, values[i]))
75  {
76  snprintf(buffer, sizeof(buffer), "#%u: %u (%0.5f) ",
77  i, values[i], values[i] / 65535.f);
78  nk_tooltip(nk, buffer);
79  }
80  }
81 
82  nk_chart_end(nk);
83  }
84 }
85 
86 int main(int argc, char** argv)
87 {
88  GLFWmonitor* monitor = NULL;
90  GLFWgammaramp orig_ramp;
91  struct nk_context* nk;
92  struct nk_font_atlas* atlas;
93  float gamma_value = 1.f;
94 
96 
97  if (!glfwInit())
98  exit(EXIT_FAILURE);
99 
100  monitor = glfwGetPrimaryMonitor();
101 
103 
104  window = glfwCreateWindow(800, 400, "Gamma Test", NULL, NULL);
105  if (!window)
106  {
107  glfwTerminate();
108  exit(EXIT_FAILURE);
109  }
110 
111  {
112  const GLFWgammaramp* ramp = glfwGetGammaRamp(monitor);
113  const size_t array_size = ramp->size * sizeof(short);
114  orig_ramp.size = ramp->size;
115  orig_ramp.red = malloc(array_size);
116  orig_ramp.green = malloc(array_size);
117  orig_ramp.blue = malloc(array_size);
118  memcpy(orig_ramp.red, ramp->red, array_size);
119  memcpy(orig_ramp.green, ramp->green, array_size);
120  memcpy(orig_ramp.blue, ramp->blue, array_size);
121  }
122 
123  glfwMakeContextCurrent(window);
125  glfwSwapInterval(1);
126 
130 
132 
133  while (!glfwWindowShouldClose(window))
134  {
135  int width, height;
136  struct nk_rect area;
137 
138  glfwGetWindowSize(window, &width, &height);
139  area = nk_rect(0.f, 0.f, (float) width, (float) height);
140  nk_window_set_bounds(nk, "", area);
141 
144  if (nk_begin(nk, "", area, 0))
145  {
146  const GLFWgammaramp* ramp;
147 
148  nk_layout_row_dynamic(nk, 30, 3);
149  if (nk_slider_float(nk, 0.1f, &gamma_value, 5.f, 0.1f))
150  glfwSetGamma(monitor, gamma_value);
151  nk_labelf(nk, NK_TEXT_LEFT, "%0.1f", gamma_value);
152  if (nk_button_label(nk, "Revert"))
153  glfwSetGammaRamp(monitor, &orig_ramp);
154 
155  ramp = glfwGetGammaRamp(monitor);
156 
157  nk_layout_row_dynamic(nk, height - 60.f, 3);
158  chart_ramp_array(nk, nk_rgb(255, 0, 0), ramp->size, ramp->red);
159  chart_ramp_array(nk, nk_rgb(0, 255, 0), ramp->size, ramp->green);
160  chart_ramp_array(nk, nk_rgb(0, 0, 255), ramp->size, ramp->blue);
161  }
162 
163  nk_end(nk);
165 
166  glfwSwapBuffers(window);
168  }
169 
170  free(orig_ramp.red);
171  free(orig_ramp.green);
172  free(orig_ramp.blue);
173 
175  glfwTerminate();
176  exit(EXIT_SUCCESS);
177 }
178 
NK_API int nk_begin(struct nk_context *ctx, const char *title, struct nk_rect bounds, nk_flags flags)
GLFWAPI void glfwGetWindowSize(GLFWwindow *window, int *width, int *height)
Retrieves the size of the client area of the specified window.
Definition: window.c:544
GLFWAPI void glfwSetGamma(GLFWmonitor *monitor, float gamma)
Generates a gamma ramp and sets it for the specified monitor.
Definition: monitor.c:428
The header of the GLFW 3 API.
GLFWAPI GLFWglproc glfwGetProcAddress(const char *procname)
Returns the address of the specified function for the current context.
Definition: context.c:741
void *(* GLADloadproc)(const char *name)
static GLFWwindow * window
Definition: joysticks.c:55
static void error_callback(int error, const char *description)
Definition: gamma.c:51
GLuint color
struct GLFWmonitor GLFWmonitor
NK_API void nk_glfw3_shutdown(void)
GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun)
Sets the error callback.
Definition: init.c:309
unsigned short * red
Definition: glfw3.h:1563
GLenum GLfloat * buffer
unsigned short * green
Definition: glfw3.h:1566
NK_API void nk_glfw3_render(enum nk_anti_aliasing)
NK_API struct nk_color nk_rgb(int r, int g, int b)
#define GLFW_SCALE_TO_MONITOR
Window content area scaling window window hint.
Definition: glfw3.h:979
std::size_t array_size(T BOOST_RANGE_ARRAY_REF()[sz])
GLuint64 key
Definition: glext.h:8966
GLFWAPI int glfwInit(void)
Initializes the GLFW library.
Definition: init.c:198
GLdouble f
NK_API void nk_layout_row_dynamic(struct nk_context *ctx, float height, int cols)
#define GL_COLOR_BUFFER_BIT
NK_API void nk_glfw3_new_frame(void)
NK_API struct nk_rect nk_rect(float x, float y, float w, float h)
NK_API struct nk_context * nk_glfw3_init(GLFWwindow *win, enum nk_glfw_init_state)
GLFWAPI void glfwSwapInterval(int interval)
Sets the swap interval for the current context.
Definition: context.c:658
int main(int argc, char **argv)
Definition: gamma.c:86
NK_API int nk_chart_begin_colored(struct nk_context *, enum nk_chart_type, struct nk_color, struct nk_color active, int num, float min, float max)
#define GLFW_KEY_ESCAPE
Definition: glfw3.h:412
#define glClear
GLint GLsizei GLsizei height
GLFWAPI void glfwSwapBuffers(GLFWwindow *window)
Swaps the front and back buffers of the specified window.
Definition: context.c:641
GLFWAPI void glfwMakeContextCurrent(GLFWwindow *window)
Makes the context of the specified window current for the calling thread.
Definition: context.c:611
unsigned int size
Definition: glfw3.h:1572
GLFWAPI const GLFWgammaramp * glfwGetGammaRamp(GLFWmonitor *monitor)
Returns the current gamma ramp for the specified monitor.
Definition: monitor.c:470
NK_API void nk_tooltip(struct nk_context *, const char *)
action
Definition: enums.py:62
GLAPI int gladLoadGLLoader(GLADloadproc)
Definition: glad/glad.c:1697
static const textual_icon exit
Definition: model-views.h:254
GLFWAPI void glfwSetWindowShouldClose(GLFWwindow *window, int value)
Sets the close flag of the specified window.
Definition: window.c:486
NK_API int nk_slider_float(struct nk_context *, float min, float *val, float max, float step)
GLFWAPI GLFWwindow * glfwCreateWindow(int width, int height, const char *title, GLFWmonitor *monitor, GLFWwindow *share)
Creates a window and its associated context.
Definition: window.c:151
GLsizei const GLfloat * values
GLFWAPI void glfwWaitEventsTimeout(double timeout)
Waits with timeout until events are queued and processes them.
Definition: window.c:1088
#define GLFW_TRUE
One.
Definition: glfw3.h:279
Gamma ramp.
Definition: glfw3.h:1559
unsigned short * blue
Definition: glfw3.h:1569
static void chart_ramp_array(struct nk_context *nk, struct nk_color color, int count, unsigned short int *values)
Definition: gamma.c:62
GLFWAPI GLFWmonitor * glfwGetPrimaryMonitor(void)
Returns the primary monitor.
Definition: monitor.c:308
GLint GLsizei count
GLFWAPI void glfwTerminate(void)
Terminates the GLFW library.
Definition: init.c:243
NK_API nk_flags nk_chart_push(struct nk_context *, float)
GLFWAPI GLFWkeyfun glfwSetKeyCallback(GLFWwindow *window, GLFWkeyfun cbfun)
Sets the key callback.
Definition: input.c:791
NK_API void nk_window_set_bounds(struct nk_context *, const char *name, struct nk_rect bounds)
NK_API void nk_glfw3_font_stash_end(void)
#define NULL
Definition: tinycthread.c:47
NK_API void nk_glfw3_font_stash_begin(struct nk_font_atlas **atlas)
int i
NK_API void nk_end(struct nk_context *ctx)
static void key_callback(GLFWwindow *window, int key, int scancode, int action, int mods)
Definition: gamma.c:56
NK_API int nk_button_label(struct nk_context *, const char *title)
#define GLFW_PRESS
The key or mouse button was pressed.
Definition: glfw3.h:304
struct GLFWwindow GLFWwindow
GLFWAPI void glfwWindowHint(int hint, int value)
Sets the specified window hint to the desired value.
Definition: window.c:291
GLint GLsizei width
GLFWAPI void glfwSetGammaRamp(GLFWmonitor *monitor, const GLFWgammaramp *ramp)
Sets the current gamma ramp for the specified monitor.
Definition: monitor.c:483
NK_API void nk_chart_end(struct nk_context *)
GLFWAPI int glfwWindowShouldClose(GLFWwindow *window)
Checks the close flag of the specified window.
Definition: window.c:477


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:15