opacity.c
Go to the documentation of this file.
1 //========================================================================
2 // Window opacity 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 #include <glad/glad.h>
27 #include <GLFW/glfw3.h>
28 
29 #define NK_IMPLEMENTATION
30 #define NK_INCLUDE_FIXED_TYPES
31 #define NK_INCLUDE_FONT_BAKING
32 #define NK_INCLUDE_DEFAULT_FONT
33 #define NK_INCLUDE_DEFAULT_ALLOCATOR
34 #define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
35 #define NK_INCLUDE_STANDARD_VARARGS
36 #include <nuklear.h>
37 
38 #define NK_GLFW_GL2_IMPLEMENTATION
39 #include <nuklear_glfw_gl2.h>
40 
41 #include <stdio.h>
42 #include <stdlib.h>
43 
44 static void error_callback(int error, const char* description)
45 {
46  fprintf(stderr, "Error: %s\n", description);
47 }
48 
49 int main(int argc, char** argv)
50 {
52  struct nk_context* nk;
53  struct nk_font_atlas* atlas;
54 
56 
57  if (!glfwInit())
58  exit(EXIT_FAILURE);
59 
61 
62  window = glfwCreateWindow(400, 400, "Opacity", NULL, NULL);
63  if (!window)
64  {
65  glfwTerminate();
66  exit(EXIT_FAILURE);
67  }
68 
69  glfwMakeContextCurrent(window);
72 
76 
77  while (!glfwWindowShouldClose(window))
78  {
79  int width, height;
80  struct nk_rect area;
81 
82  glfwGetWindowSize(window, &width, &height);
83  area = nk_rect(0.f, 0.f, (float) width, (float) height);
84 
87  if (nk_begin(nk, "", area, 0))
88  {
89  float opacity = glfwGetWindowOpacity(window);
90  nk_layout_row_dynamic(nk, 30, 2);
91  if (nk_slider_float(nk, 0.f, &opacity, 1.f, 0.001f))
92  glfwSetWindowOpacity(window, opacity);
93  nk_labelf(nk, NK_TEXT_LEFT, "%0.3f", opacity);
94  }
95 
96  nk_end(nk);
98 
99  glfwSwapBuffers(window);
101  }
102 
104  glfwTerminate();
105  exit(EXIT_SUCCESS);
106 }
107 
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
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
GLFWAPI float glfwGetWindowOpacity(GLFWwindow *window)
Returns the opacity of the whole window.
Definition: window.c:696
NK_API void nk_glfw3_shutdown(void)
GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun)
Sets the error callback.
Definition: init.c:309
NK_API void nk_glfw3_render(enum nk_anti_aliasing)
#define GLFW_SCALE_TO_MONITOR
Window content area scaling window window hint.
Definition: glfw3.h:979
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
#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
int main(int argc, char **argv)
Definition: opacity.c:49
GLAPI int gladLoadGLLoader(GLADloadproc)
Definition: glad/glad.c:1697
static const textual_icon exit
Definition: model-views.h:254
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
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
GLFWAPI void glfwSetWindowOpacity(GLFWwindow *window, float opacity)
Sets the opacity of the whole window.
Definition: window.c:705
GLFWAPI void glfwTerminate(void)
Terminates the GLFW library.
Definition: init.c:243
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)
NK_API void nk_end(struct nk_context *ctx)
static void error_callback(int error, const char *description)
Definition: opacity.c:44
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 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:38