Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
00037
00038
00039
00040
00041
00042 GLboolean _glfwInitialized = GL_FALSE;
00043 _GLFWlibrary _glfw;
00044
00045
00046
00047
00048 static GLFWerrorfun _glfwErrorCallback = NULL;
00049
00050
00051
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
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