examples/third_party/glfw/src/init.c
Go to the documentation of this file.
1 //========================================================================
2 // GLFW 3.1 - www.glfw.org
3 //------------------------------------------------------------------------
4 // Copyright (c) 2002-2006 Marcus Geelnard
5 // Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
6 //
7 // This software is provided 'as-is', without any express or implied
8 // warranty. In no event will the authors be held liable for any damages
9 // arising from the use of this software.
10 //
11 // Permission is granted to anyone to use this software for any purpose,
12 // including commercial applications, and to alter it and redistribute it
13 // freely, subject to the following restrictions:
14 //
15 // 1. The origin of this software must not be misrepresented; you must not
16 // claim that you wrote the original software. If you use this software
17 // in a product, an acknowledgment in the product documentation would
18 // be appreciated but is not required.
19 //
20 // 2. Altered source versions must be plainly marked as such, and must not
21 // be misrepresented as being the original software.
22 //
23 // 3. This notice may not be removed or altered from any source
24 // distribution.
25 //
26 //========================================================================
27 
28 #include "internal.h"
29 
30 #include <string.h>
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <stdarg.h>
34 
35 
36 // The three global variables below comprise all global data in GLFW.
37 // Any other global variable is a bug.
38 
39 // Global state shared between compilation units of GLFW
40 // These are documented in internal.h
41 //
44 
45 // This is outside of _glfw so it can be initialized and usable before
46 // glfwInit is called, which lets that function report errors
47 //
49 
50 
51 // Returns a generic string representation of the specified error
52 //
53 static const char* getErrorString(int error)
54 {
55  switch (error)
56  {
58  return "The GLFW library is not initialized";
60  return "There is no current context";
61  case GLFW_INVALID_ENUM:
62  return "Invalid argument for enum parameter";
63  case GLFW_INVALID_VALUE:
64  return "Invalid value for parameter";
65  case GLFW_OUT_OF_MEMORY:
66  return "Out of memory";
68  return "The requested client API is unavailable";
70  return "The requested client API version is unavailable";
72  return "A platform-specific error occurred";
74  return "The requested format is unavailable";
75  }
76 
77  return "ERROR: UNKNOWN ERROR TOKEN PASSED TO glfwErrorString";
78 }
79 
80 
84 
85 void _glfwInputError(int error, const char* format, ...)
86 {
88  {
89  char buffer[8192];
90  const char* description;
91 
92  if (format)
93  {
94  int count;
95  va_list vl;
96 
97  va_start(vl, format);
98  count = vsnprintf(buffer, sizeof(buffer), format, vl);
99  va_end(vl);
100 
101  if (count < 0)
102  buffer[sizeof(buffer) - 1] = '\0';
103 
104  description = buffer;
105  }
106  else
107  description = getErrorString(error);
108 
109  _glfwErrorCallback(error, description);
110  }
111 }
112 
113 
117 
118 GLFWAPI int glfwInit(void)
119 {
120  if (_glfwInitialized)
121  return GL_TRUE;
122 
123  memset(&_glfw, 0, sizeof(_glfw));
124 
125  if (!_glfwPlatformInit())
126  {
128  return GL_FALSE;
129  }
130 
132  _glfwInitialized = GL_TRUE;
133 
134  // Not all window hints have zero as their default value
136 
137  return GL_TRUE;
138 }
139 
141 {
142  int i;
143 
144  if (!_glfwInitialized)
145  return;
146 
147  memset(&_glfw.callbacks, 0, sizeof(_glfw.callbacks));
148 
149  while (_glfw.windowListHead)
151 
152  while (_glfw.cursorListHead)
154 
155  for (i = 0; i < _glfw.monitorCount; i++)
156  {
157  _GLFWmonitor* monitor = _glfw.monitors[i];
158  if (monitor->originalRamp.size)
159  _glfwPlatformSetGammaRamp(monitor, &monitor->originalRamp);
160  }
161 
163  _glfw.monitors = NULL;
164  _glfw.monitorCount = 0;
165 
167 
168  memset(&_glfw, 0, sizeof(_glfw));
169  _glfwInitialized = GL_FALSE;
170 }
171 
172 GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev)
173 {
174  if (major != NULL)
175  *major = GLFW_VERSION_MAJOR;
176 
177  if (minor != NULL)
178  *minor = GLFW_VERSION_MINOR;
179 
180  if (rev != NULL)
181  *rev = GLFW_VERSION_REVISION;
182 }
183 
184 GLFWAPI const char* glfwGetVersionString(void)
185 {
187 }
188 
190 {
192  return cbfun;
193 }
194 
Library global data.
Definition: internal.h:330
int major(int version)
Definition: rs.cpp:49
#define GLFWAPI
Definition: glfw3.h:185
struct GLFWcursor GLFWcursor
Opaque cursor object.
Definition: glfw3.h:730
struct _GLFWlibrary::@3 callbacks
_GLFWmonitor ** _glfwPlatformGetMonitors(int *count)
Returns the currently connected monitors.
GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun)
Sets the error callback.
void _glfwPlatformSetGammaRamp(_GLFWmonitor *monitor, const GLFWgammaramp *ramp)
Sets the current gamma ramp for the specified monitor.
const char * _glfwPlatformGetVersionString(void)
Returns a string describing the compile-time configuration.
Definition: win32_init.c:370
#define GLFW_API_UNAVAILABLE
GLFW could not find support for the requested client API on the system.
Definition: glfw3.h:539
int _glfwPlatformInit(void)
Initializes the platform-specific part of the library.
Definition: win32_init.c:324
void _glfwPlatformTerminate(void)
Terminates the platform-specific part of the library.
Definition: win32_init.c:354
#define GLFW_FORMAT_UNAVAILABLE
The requested format is not supported or available.
Definition: glfw3.h:589
_GLFWwindow * windowListHead
Definition: internal.h:343
_GLFWlibrary _glfw
All global data protected by _glfwInitialized. This should only be touched after a call to glfwInit t...
GLuint buffer
Definition: glext.h:528
struct GLFWwindow GLFWwindow
Opaque window object.
Definition: glfw3.h:722
Monitor structure.
Definition: internal.h:299
#define _GLFW_SWAP_POINTERS(x, y)
Definition: internal.h:145
_GLFWcursor * cursorListHead
Definition: internal.h:341
#define GLFW_NO_CURRENT_CONTEXT
No context is current for this thread.
Definition: glfw3.h:488
GLFWAPI int glfwInit(void)
Initializes the GLFW library.
static const char * getErrorString(int error)
typedef GLboolean(APIENTRYP PFNGLISQUERYPROC)(GLuint id)
#define GLFW_PLATFORM_ERROR
A platform-specific error occurred that does not match any of the more specific categories.
Definition: glfw3.h:569
GLuint GLuint GLsizei count
Definition: glext.h:111
int monitorCount
Definition: internal.h:347
GLFWAPI const char * glfwGetVersionString(void)
Returns a string describing the compile-time configuration.
GLFWAPI void glfwGetVersion(int *major, int *minor, int *rev)
Retrieves the version of the GLFW library.
GLFWAPI void glfwDefaultWindowHints(void)
Resets all window hints to their default values.
Definition: window.c:235
void _glfwFreeMonitors(_GLFWmonitor **monitors, int count)
Definition: monitor.c:206
unsigned int size
Definition: glfw3.h:1026
#define GLFW_VERSION_UNAVAILABLE
The requested OpenGL or OpenGL ES version is not available.
Definition: glfw3.h:557
GLFWgammaramp originalRamp
Definition: internal.h:310
#define GLFW_INVALID_ENUM
One of the arguments to the function was an invalid enum value.
Definition: glfw3.h:498
#define GLFW_INVALID_VALUE
One of the arguments to the function was an invalid value.
Definition: glfw3.h:510
#define GLFW_VERSION_REVISION
The revision number of the GLFW library.
Definition: glfw3.h:214
GLFWAPI void glfwDestroyCursor(GLFWcursor *cursor)
Destroys a cursor.
Definition: input.c:411
#define GLFW_OUT_OF_MEMORY
A memory allocation failed.
Definition: glfw3.h:519
GLFWAPI void glfwDestroyWindow(GLFWwindow *window)
Destroys the specified window and its context.
Definition: window.c:369
#define GLFW_VERSION_MINOR
The minor version number of the GLFW library.
Definition: glfw3.h:207
#define GLFW_NOT_INITIALIZED
GLFW has not been initialized.
Definition: glfw3.h:477
int minor(int version)
Definition: rs.cpp:53
GLFWAPI void glfwTerminate(void)
Terminates the GLFW library.
void _glfwInputError(int error, const char *format,...)
Notifies shared code of an error.
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: glext.h:112
static GLFWerrorfun _glfwErrorCallback
#define GLFW_VERSION_MAJOR
The major version number of the GLFW library.
Definition: glfw3.h:200
_GLFWmonitor ** monitors
Definition: internal.h:346
void(* GLFWerrorfun)(int, const char *)
The function signature for error callbacks.
Definition: glfw3.h:743
GLboolean _glfwInitialized
Flag indicating whether GLFW has been successfully initialized.


librealsense
Author(s): Sergey Dorodnicov , Mark Horn , Reagan Lopez
autogenerated on Fri Mar 13 2020 03:16:17