init.c
Go to the documentation of this file.
00001 //========================================================================
00002 // GLFW 3.1 - www.glfw.org
00003 //------------------------------------------------------------------------
00004 // Copyright (c) 2002-2006 Marcus Geelnard
00005 // Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
00006 //
00007 // This software is provided 'as-is', without any express or implied
00008 // warranty. In no event will the authors be held liable for any damages
00009 // arising from the use of this software.
00010 //
00011 // Permission is granted to anyone to use this software for any purpose,
00012 // including commercial applications, and to alter it and redistribute it
00013 // freely, subject to the following restrictions:
00014 //
00015 // 1. The origin of this software must not be misrepresented; you must not
00016 //    claim that you wrote the original software. If you use this software
00017 //    in a product, an acknowledgment in the product documentation would
00018 //    be appreciated but is not required.
00019 //
00020 // 2. Altered source versions must be plainly marked as such, and must not
00021 //    be misrepresented as being the original software.
00022 //
00023 // 3. This notice may not be removed or altered from any source
00024 //    distribution.
00025 //
00026 //========================================================================
00027 
00028 #include "internal.h"
00029 
00030 #include <string.h>
00031 #include <stdlib.h>
00032 #include <stdio.h>
00033 #include <stdarg.h>
00034 
00035 
00036 // The three global variables below comprise all global data in GLFW.
00037 // Any other global variable is a bug.
00038 
00039 // Global state shared between compilation units of GLFW
00040 // These are documented in internal.h
00041 //
00042 GLboolean _glfwInitialized = GL_FALSE;
00043 _GLFWlibrary _glfw;
00044 
00045 // This is outside of _glfw so it can be initialized and usable before
00046 // glfwInit is called, which lets that function report errors
00047 //
00048 static GLFWerrorfun _glfwErrorCallback = NULL;
00049 
00050 
00051 // Returns a generic string representation of the specified error
00052 //
00053 static const char* getErrorString(int error)
00054 {
00055     switch (error)
00056     {
00057         case GLFW_NOT_INITIALIZED:
00058             return "The GLFW library is not initialized";
00059         case GLFW_NO_CURRENT_CONTEXT:
00060             return "There is no current context";
00061         case GLFW_INVALID_ENUM:
00062             return "Invalid argument for enum parameter";
00063         case GLFW_INVALID_VALUE:
00064             return "Invalid value for parameter";
00065         case GLFW_OUT_OF_MEMORY:
00066             return "Out of memory";
00067         case GLFW_API_UNAVAILABLE:
00068             return "The requested client API is unavailable";
00069         case GLFW_VERSION_UNAVAILABLE:
00070             return "The requested client API version is unavailable";
00071         case GLFW_PLATFORM_ERROR:
00072             return "A platform-specific error occurred";
00073         case GLFW_FORMAT_UNAVAILABLE:
00074             return "The requested format is unavailable";
00075     }
00076 
00077     return "ERROR: UNKNOWN ERROR TOKEN PASSED TO glfwErrorString";
00078 }
00079 
00080 
00084 
00085 void _glfwInputError(int error, const char* format, ...)
00086 {
00087     if (_glfwErrorCallback)
00088     {
00089         char buffer[8192];
00090         const char* description;
00091 
00092         if (format)
00093         {
00094             int count;
00095             va_list vl;
00096 
00097             va_start(vl, format);
00098             count = vsnprintf(buffer, sizeof(buffer), format, vl);
00099             va_end(vl);
00100 
00101             if (count < 0)
00102                 buffer[sizeof(buffer) - 1] = '\0';
00103 
00104             description = buffer;
00105         }
00106         else
00107             description = getErrorString(error);
00108 
00109         _glfwErrorCallback(error, description);
00110     }
00111 }
00112 
00113 
00117 
00118 GLFWAPI int glfwInit(void)
00119 {
00120     if (_glfwInitialized)
00121         return GL_TRUE;
00122 
00123     memset(&_glfw, 0, sizeof(_glfw));
00124 
00125     if (!_glfwPlatformInit())
00126     {
00127         _glfwPlatformTerminate();
00128         return GL_FALSE;
00129     }
00130 
00131     _glfw.monitors = _glfwPlatformGetMonitors(&_glfw.monitorCount);
00132     _glfwInitialized = GL_TRUE;
00133 
00134     // Not all window hints have zero as their default value
00135     glfwDefaultWindowHints();
00136 
00137     return GL_TRUE;
00138 }
00139 
00140 GLFWAPI void glfwTerminate(void)
00141 {
00142     int i;
00143 
00144     if (!_glfwInitialized)
00145         return;
00146 
00147     memset(&_glfw.callbacks, 0, sizeof(_glfw.callbacks));
00148 
00149     while (_glfw.windowListHead)
00150         glfwDestroyWindow((GLFWwindow*) _glfw.windowListHead);
00151 
00152     while (_glfw.cursorListHead)
00153         glfwDestroyCursor((GLFWcursor*) _glfw.cursorListHead);
00154 
00155     for (i = 0;  i < _glfw.monitorCount;  i++)
00156     {
00157         _GLFWmonitor* monitor = _glfw.monitors[i];
00158         if (monitor->originalRamp.size)
00159             _glfwPlatformSetGammaRamp(monitor, &monitor->originalRamp);
00160     }
00161 
00162     _glfwFreeMonitors(_glfw.monitors, _glfw.monitorCount);
00163     _glfw.monitors = NULL;
00164     _glfw.monitorCount = 0;
00165 
00166     _glfwPlatformTerminate();
00167 
00168     memset(&_glfw, 0, sizeof(_glfw));
00169     _glfwInitialized = GL_FALSE;
00170 }
00171 
00172 GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev)
00173 {
00174     if (major != NULL)
00175         *major = GLFW_VERSION_MAJOR;
00176 
00177     if (minor != NULL)
00178         *minor = GLFW_VERSION_MINOR;
00179 
00180     if (rev != NULL)
00181         *rev = GLFW_VERSION_REVISION;
00182 }
00183 
00184 GLFWAPI const char* glfwGetVersionString(void)
00185 {
00186     return _glfwPlatformGetVersionString();
00187 }
00188 
00189 GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun cbfun)
00190 {
00191     _GLFW_SWAP_POINTERS(_glfwErrorCallback, cbfun);
00192     return cbfun;
00193 }
00194 


librealsense
Author(s): Sergey Dorodnicov , Mark Horn , Reagan Lopez
autogenerated on Tue Jun 25 2019 19:54:39