mirror of
https://github.com/glfw/glfw.git
synced 2024-11-25 22:14:34 +00:00
Added error callback.
This commit is contained in:
parent
065c77190d
commit
f1e7d7c0ea
@ -392,6 +392,7 @@ typedef struct
|
|||||||
} GLFWgammaramp;
|
} GLFWgammaramp;
|
||||||
|
|
||||||
/* Function pointer types */
|
/* Function pointer types */
|
||||||
|
typedef void (* GLFWerrorfun)(int,const char*);
|
||||||
typedef void (* GLFWwindowsizefun)(GLFWwindow,int,int);
|
typedef void (* GLFWwindowsizefun)(GLFWwindow,int,int);
|
||||||
typedef int (* GLFWwindowclosefun)(GLFWwindow);
|
typedef int (* GLFWwindowclosefun)(GLFWwindow);
|
||||||
typedef void (* GLFWwindowrefreshfun)(GLFWwindow);
|
typedef void (* GLFWwindowrefreshfun)(GLFWwindow);
|
||||||
@ -417,6 +418,7 @@ GLFWAPI const char* glfwGetVersionString(void);
|
|||||||
/* Error handling */
|
/* Error handling */
|
||||||
GLFWAPI int glfwGetError(void);
|
GLFWAPI int glfwGetError(void);
|
||||||
GLFWAPI const char* glfwErrorString(int error);
|
GLFWAPI const char* glfwErrorString(int error);
|
||||||
|
GLFWAPI void glfwSetErrorCallback(GLFWerrorfun cbfun);
|
||||||
|
|
||||||
/* Video mode functions */
|
/* Video mode functions */
|
||||||
GLFWAPI int glfwGetVideoModes(GLFWvidmode* list, int maxcount);
|
GLFWAPI int glfwGetVideoModes(GLFWvidmode* list, int maxcount);
|
||||||
|
@ -265,6 +265,7 @@ version of GLFW.</p>
|
|||||||
<li>Added <code>glfwIsWindow</code> function for verifying that a given window handle is (still) valid</li>
|
<li>Added <code>glfwIsWindow</code> function for verifying that a given window handle is (still) valid</li>
|
||||||
<li>Added <code>glfwMakeWindowCurrent</code> function for making the context of the specified window current</li>
|
<li>Added <code>glfwMakeWindowCurrent</code> function for making the context of the specified window current</li>
|
||||||
<li>Added <code>glfwGetError</code> and <code>glfwErrorString</code> error reporting functions and a number of error tokens</li>
|
<li>Added <code>glfwGetError</code> and <code>glfwErrorString</code> error reporting functions and a number of error tokens</li>
|
||||||
|
<li>Added <code>glfwSetErrorCallback</code> function and <code>GLFWerrorfun</code> type for receiving more specific and/or nested errors</li>
|
||||||
<li>Added <code>glfwSetWindowUserPointer</code> and <code>glfwGetWindowUserPointer</code> functions for per-window user pointers</li>
|
<li>Added <code>glfwSetWindowUserPointer</code> and <code>glfwGetWindowUserPointer</code> functions for per-window user pointers</li>
|
||||||
<li>Added <code>glfwGetVersionString</code> function for determining which code paths were enabled at compile time</li>
|
<li>Added <code>glfwGetVersionString</code> function for determining which code paths were enabled at compile time</li>
|
||||||
<li>Added <code>glfwGetWindowPos</code> function for querying the position of the specified window</li>
|
<li>Added <code>glfwGetWindowPos</code> function for querying the position of the specified window</li>
|
||||||
|
@ -475,7 +475,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
|||||||
// Fail if OpenGL 3.0 or above was requested
|
// Fail if OpenGL 3.0 or above was requested
|
||||||
if (wndconfig->glMajor > 2)
|
if (wndconfig->glMajor > 2)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE);
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE, "Cocoa/NSOpenGL: Mac OS X does not support OpenGL version 3.0 or above");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -486,7 +486,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
|||||||
_glfwLibrary.NS.delegate = [[GLFWApplicationDelegate alloc] init];
|
_glfwLibrary.NS.delegate = [[GLFWApplicationDelegate alloc] init];
|
||||||
if (_glfwLibrary.NS.delegate == nil)
|
if (_glfwLibrary.NS.delegate == nil)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR);
|
_glfwSetError(GLFW_PLATFORM_ERROR, "Cocoa/NSOpenGL: Failed to create application delegate");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -496,7 +496,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
|||||||
window->NS.delegate = [[GLFWWindowDelegate alloc] initWithGlfwWindow:window];
|
window->NS.delegate = [[GLFWWindowDelegate alloc] initWithGlfwWindow:window];
|
||||||
if (window->NS.delegate == nil)
|
if (window->NS.delegate == nil)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR);
|
_glfwSetError(GLFW_PLATFORM_ERROR, "Cocoa/NSOpenGL: Failed to create window delegate");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -627,7 +627,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
|||||||
[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
|
[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
|
||||||
if (window->NSGL.pixelFormat == nil)
|
if (window->NSGL.pixelFormat == nil)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR);
|
_glfwSetError(GLFW_PLATFORM_ERROR, "Cocoa/NSOpenGL: Failed to create pixel format");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -641,7 +641,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
|||||||
shareContext:share];
|
shareContext:share];
|
||||||
if (window->NSGL.context == nil)
|
if (window->NSGL.context == nil)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR);
|
_glfwSetError(GLFW_PLATFORM_ERROR, "Cocoa/NSOpenGL: Failed to create OpenGL context");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ GLFWAPI void glfwEnable(GLFWwindow window, int token)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,7 +220,7 @@ GLFWAPI void glfwDisable(GLFWwindow window, int token)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
30
src/error.c
30
src/error.c
@ -45,9 +45,17 @@ static int _glfwError = GLFW_NO_ERROR;
|
|||||||
// Sets the current error value
|
// Sets the current error value
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
void _glfwSetError(int error)
|
void _glfwSetError(int error, const char* description)
|
||||||
{
|
{
|
||||||
_glfwError = error;
|
if (_glfwLibrary.errorCallback)
|
||||||
|
{
|
||||||
|
if (!description)
|
||||||
|
description = glfwErrorString(error);
|
||||||
|
|
||||||
|
_glfwLibrary.errorCallback(error, description);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
_glfwError = error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -99,3 +107,21 @@ GLFWAPI const char* glfwErrorString(int error)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//========================================================================
|
||||||
|
// Sets the callback function for GLFW errors
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
|
GLFWAPI void glfwSetErrorCallback(GLFWerrorfun cbfun)
|
||||||
|
{
|
||||||
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
// TODO: Uhm... Hmm...
|
||||||
|
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_glfwLibrary.errorCallback = cbfun;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ GLFWAPI int glfwGetVideoModes(GLFWvidmode* list, int maxcount)
|
|||||||
|
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,13 +132,13 @@ GLFWAPI void glfwGetDesktopMode(GLFWvidmode* mode)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode == NULL)
|
if (mode == NULL)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_INVALID_VALUE);
|
_glfwSetError(GLFW_INVALID_VALUE, "glfwGetDesktopMode: Parameter 'mode' cannot be NULL");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ GLFWAPI void glfwSetGammaFormula(float gamma, float blacklevel, float gain)
|
|||||||
|
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ GLFWAPI void glfwGetGammaRamp(GLFWgammaramp* ramp)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ GLFWAPI void glfwSetGammaRamp(const GLFWgammaramp* ramp)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
src/glext.c
12
src/glext.c
@ -139,14 +139,14 @@ GLFWAPI int glfwExtensionSupported(const char* extension)
|
|||||||
|
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
window = _glfwLibrary.currentWindow;
|
window = _glfwLibrary.currentWindow;
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NO_CURRENT_WINDOW);
|
_glfwSetError(GLFW_NO_CURRENT_WINDOW, NULL);
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,13 +199,13 @@ GLFWAPI void* glfwGetProcAddress(const char* procname)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_glfwLibrary.currentWindow)
|
if (!_glfwLibrary.currentWindow)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NO_CURRENT_WINDOW);
|
_glfwSetError(GLFW_NO_CURRENT_WINDOW, NULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,14 +223,14 @@ GLFWAPI void glfwGetGLVersion(int* major, int* minor, int* rev)
|
|||||||
|
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window = _glfwLibrary.currentWindow;
|
window = _glfwLibrary.currentWindow;
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NO_CURRENT_WINDOW);
|
_glfwSetError(GLFW_NO_CURRENT_WINDOW, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
24
src/input.c
24
src/input.c
@ -43,7 +43,7 @@ GLFWAPI int glfwGetKey(GLFWwindow window, int key)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return GLFW_RELEASE;
|
return GLFW_RELEASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ GLFWAPI int glfwGetKey(GLFWwindow window, int key)
|
|||||||
if (key < 0 || key > GLFW_KEY_LAST)
|
if (key < 0 || key > GLFW_KEY_LAST)
|
||||||
{
|
{
|
||||||
// TODO: Decide whether key is a value or enum
|
// TODO: Decide whether key is a value or enum
|
||||||
_glfwSetError(GLFW_INVALID_VALUE);
|
_glfwSetError(GLFW_INVALID_VALUE, "glfwGetKey: The specified key is invalid");
|
||||||
return GLFW_RELEASE;
|
return GLFW_RELEASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,14 +74,14 @@ GLFWAPI int glfwGetMouseButton(GLFWwindow window, int button)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return GLFW_RELEASE;
|
return GLFW_RELEASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is it a valid mouse button?
|
// Is it a valid mouse button?
|
||||||
if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST)
|
if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_INVALID_ENUM);
|
_glfwSetError(GLFW_INVALID_ENUM, "glfwGetMouseButton: The specified mouse button is invalid");
|
||||||
return GLFW_RELEASE;
|
return GLFW_RELEASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ GLFWAPI void glfwGetMousePos(GLFWwindow window, int* xpos, int* ypos)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ GLFWAPI void glfwSetMousePos(GLFWwindow window, int xpos, int ypos)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +155,7 @@ GLFWAPI void glfwGetScrollOffset(GLFWwindow window, int* x, int* y)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +175,7 @@ GLFWAPI void glfwSetKeyCallback(GLFWkeyfun cbfun)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,7 +191,7 @@ GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,7 +207,7 @@ GLFWAPI void glfwSetMouseButtonCallback(GLFWmousebuttonfun cbfun)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,7 +223,7 @@ GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,7 +250,7 @@ GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,6 +216,7 @@ struct _GLFWlibrary
|
|||||||
_GLFWwindow* activeWindow;
|
_GLFWwindow* activeWindow;
|
||||||
_GLFWwindow* cursorLockWindow;
|
_GLFWwindow* cursorLockWindow;
|
||||||
|
|
||||||
|
GLFWerrorfun errorCallback;
|
||||||
GLFWwindowsizefun windowSizeCallback;
|
GLFWwindowsizefun windowSizeCallback;
|
||||||
GLFWwindowclosefun windowCloseCallback;
|
GLFWwindowclosefun windowCloseCallback;
|
||||||
GLFWwindowrefreshfun windowRefreshCallback;
|
GLFWwindowrefreshfun windowRefreshCallback;
|
||||||
@ -313,7 +314,7 @@ void* _glfwPlatformGetProcAddress(const char* procname);
|
|||||||
void _glfwSplitBPP(int bpp, int* red, int* green, int* blue);
|
void _glfwSplitBPP(int bpp, int* red, int* green, int* blue);
|
||||||
|
|
||||||
// Error handling
|
// Error handling
|
||||||
void _glfwSetError(int error);
|
void _glfwSetError(int error, const char* description);
|
||||||
|
|
||||||
// Window management (window.c)
|
// Window management (window.c)
|
||||||
void _glfwClearWindowHints(void);
|
void _glfwClearWindowHints(void);
|
||||||
|
@ -43,7 +43,7 @@ GLFWAPI int glfwGetJoystickParam(int joy, int param)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ GLFWAPI int glfwGetJoystickPos(int joy, float* pos, int numaxes)
|
|||||||
|
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ GLFWAPI int glfwGetJoystickButtons(int joy,
|
|||||||
|
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ GLFWAPI double glfwGetTime(void)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ GLFWAPI void glfwSetTime(double time)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,14 +184,14 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
|
|||||||
|
|
||||||
if (!count)
|
if (!count)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OPENGL_UNAVAILABLE);
|
_glfwSetError(GLFW_OPENGL_UNAVAILABLE, "Win32/WGL: No pixel formats found");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count);
|
result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OUT_OF_MEMORY);
|
_glfwSetError(GLFW_OUT_OF_MEMORY, "Win32/WGL: Failed to allocate _GLFWfbconfig array");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,13 +324,13 @@ static GLboolean createContext(_GLFWwindow* window,
|
|||||||
|
|
||||||
if (!_glfw_DescribePixelFormat(window->WGL.DC, pixelFormat, sizeof(pfd), &pfd))
|
if (!_glfw_DescribePixelFormat(window->WGL.DC, pixelFormat, sizeof(pfd), &pfd))
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OPENGL_UNAVAILABLE);
|
_glfwSetError(GLFW_OPENGL_UNAVAILABLE, "Win32/WGL: Failed to retrieve PFD for selected pixel format");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_glfw_SetPixelFormat(window->WGL.DC, pixelFormat, &pfd))
|
if (!_glfw_SetPixelFormat(window->WGL.DC, pixelFormat, &pfd))
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OPENGL_UNAVAILABLE);
|
_glfwSetError(GLFW_OPENGL_UNAVAILABLE, "Win32/WGL: Failed to set selected pixel format");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,14 +368,14 @@ static GLboolean createContext(_GLFWwindow* window,
|
|||||||
|
|
||||||
if (!window->WGL.has_WGL_ARB_create_context_profile)
|
if (!window->WGL.has_WGL_ARB_create_context_profile)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE);
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE, "Win32/WGL: OpenGL profile requested but WGL_ARB_create_context_profile is unavailable");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE &&
|
if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE &&
|
||||||
!window->WGL.has_WGL_EXT_create_context_es2_profile)
|
!window->WGL.has_WGL_EXT_create_context_es2_profile)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE);
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE, "Win32/WGL: OpenGL ES 2.x profile requested but WGL_EXT_create_context_es2_profile is unavailable");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,7 +397,7 @@ static GLboolean createContext(_GLFWwindow* window,
|
|||||||
attribs);
|
attribs);
|
||||||
if (!window->WGL.context)
|
if (!window->WGL.context)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE);
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE, "Win32/WGL: Failed to create OpenGL context");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -406,7 +406,7 @@ static GLboolean createContext(_GLFWwindow* window,
|
|||||||
window->WGL.context = wglCreateContext(window->WGL.DC);
|
window->WGL.context = wglCreateContext(window->WGL.DC);
|
||||||
if (!window->WGL.context)
|
if (!window->WGL.context)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR);
|
_glfwSetError(GLFW_PLATFORM_ERROR, "Win32/WGL: Failed to create OpenGL context");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,7 +414,7 @@ static GLboolean createContext(_GLFWwindow* window,
|
|||||||
{
|
{
|
||||||
if (!wglShareLists(share, window->WGL.context))
|
if (!wglShareLists(share, window->WGL.context))
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR);
|
_glfwSetError(GLFW_PLATFORM_ERROR, "Win32/WGL: Failed to enable sharing with specified OpenGL context");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1113,7 +1113,7 @@ static ATOM registerWindowClass(void)
|
|||||||
classAtom = RegisterClass(&wc);
|
classAtom = RegisterClass(&wc);
|
||||||
if (!classAtom)
|
if (!classAtom)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR);
|
_glfwSetError(GLFW_PLATFORM_ERROR, "Win32/WGL: Failed to register window class");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1227,14 +1227,14 @@ static int createWindow(_GLFWwindow* window,
|
|||||||
|
|
||||||
if (!window->Win32.handle)
|
if (!window->Win32.handle)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR);
|
_glfwSetError(GLFW_PLATFORM_ERROR, "Win32/WGL: Failed to create window");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
window->WGL.DC = GetDC(window->Win32.handle);
|
window->WGL.DC = GetDC(window->Win32.handle);
|
||||||
if (!window->WGL.DC)
|
if (!window->WGL.DC)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR);
|
_glfwSetError(GLFW_PLATFORM_ERROR, "Win32/WGL: Failed to retrieve DC for window");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1352,7 +1352,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
|||||||
{
|
{
|
||||||
if (!window->WGL.has_WGL_ARB_create_context)
|
if (!window->WGL.has_WGL_ARB_create_context)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE);
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE, "Win32/WGL: A forward compatible or debug OpenGL context requested but WGL_ARB_create_context is unavailable");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1363,7 +1363,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
|||||||
{
|
{
|
||||||
if (!window->WGL.has_WGL_ARB_create_context_profile)
|
if (!window->WGL.has_WGL_ARB_create_context_profile)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE);
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE, "Win32/WGL: OpenGL profile requested but WGL_ARB_create_context_profile is unavailable");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
76
src/window.c
76
src/window.c
@ -437,14 +437,14 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
|||||||
|
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
window = (_GLFWwindow*) malloc(sizeof(_GLFWwindow));
|
window = (_GLFWwindow*) malloc(sizeof(_GLFWwindow));
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OUT_OF_MEMORY);
|
_glfwSetError(GLFW_OUT_OF_MEMORY, "glfwOpenWindow: Failed to allocate window structure");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,21 +487,21 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
|||||||
{
|
{
|
||||||
// OpenGL 1.x series ended with version 1.5
|
// OpenGL 1.x series ended with version 1.5
|
||||||
glfwCloseWindow(window);
|
glfwCloseWindow(window);
|
||||||
_glfwSetError(GLFW_INVALID_VALUE);
|
_glfwSetError(GLFW_INVALID_VALUE, "glfwOpenWindow: Invalid OpenGL version requested");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
else if (wndconfig.glMajor == 2 && wndconfig.glMinor > 1)
|
else if (wndconfig.glMajor == 2 && wndconfig.glMinor > 1)
|
||||||
{
|
{
|
||||||
// OpenGL 2.x series ended with version 2.1
|
// OpenGL 2.x series ended with version 2.1
|
||||||
glfwCloseWindow(window);
|
glfwCloseWindow(window);
|
||||||
_glfwSetError(GLFW_INVALID_VALUE);
|
_glfwSetError(GLFW_INVALID_VALUE, "glfwOpenWindow: Invalid OpenGL version requested");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
else if (wndconfig.glMajor == 3 && wndconfig.glMinor > 3)
|
else if (wndconfig.glMajor == 3 && wndconfig.glMinor > 3)
|
||||||
{
|
{
|
||||||
// OpenGL 3.x series ended with version 3.3
|
// OpenGL 3.x series ended with version 3.3
|
||||||
glfwCloseWindow(window);
|
glfwCloseWindow(window);
|
||||||
_glfwSetError(GLFW_INVALID_VALUE);
|
_glfwSetError(GLFW_INVALID_VALUE, "glfwOpenWindow: Invalid OpenGL version requested");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -519,7 +519,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
|||||||
// everything 2.x and let the driver report invalid versions
|
// everything 2.x and let the driver report invalid versions
|
||||||
|
|
||||||
glfwCloseWindow(window);
|
glfwCloseWindow(window);
|
||||||
_glfwSetError(GLFW_INVALID_VALUE);
|
_glfwSetError(GLFW_INVALID_VALUE, "glfwOpenWindow: Invalid OpenGL ES 2.x version requested");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -531,7 +531,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
|||||||
// and above
|
// and above
|
||||||
|
|
||||||
glfwCloseWindow(window);
|
glfwCloseWindow(window);
|
||||||
_glfwSetError(GLFW_INVALID_VALUE);
|
_glfwSetError(GLFW_INVALID_VALUE, "glfwOpenWindow: Context profiles only exist for OpenGL version 3.2 and above");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -540,7 +540,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
|||||||
{
|
{
|
||||||
// Forward-compatible contexts are only defined for OpenGL version 3.0 and above
|
// Forward-compatible contexts are only defined for OpenGL version 3.0 and above
|
||||||
glfwCloseWindow(window);
|
glfwCloseWindow(window);
|
||||||
_glfwSetError(GLFW_INVALID_VALUE);
|
_glfwSetError(GLFW_INVALID_VALUE, "glfwOpenWindow: Forward compatibility only exist for OpenGL version 3.0 and above");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -548,7 +548,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
|||||||
{
|
{
|
||||||
// Invalid window mode
|
// Invalid window mode
|
||||||
glfwCloseWindow(window);
|
glfwCloseWindow(window);
|
||||||
_glfwSetError(GLFW_INVALID_ENUM);
|
_glfwSetError(GLFW_INVALID_ENUM, "glfwOpenWindow: Invalid enum for 'mode' parameter");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -601,7 +601,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
|||||||
// The desired OpenGL version is greater than the actual version
|
// The desired OpenGL version is greater than the actual version
|
||||||
// This only happens if the machine lacks {GLX|WGL}_ARB_create_context
|
// This only happens if the machine lacks {GLX|WGL}_ARB_create_context
|
||||||
glfwCloseWindow(window);
|
glfwCloseWindow(window);
|
||||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE);
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE, "glfwOpenWindow: The requested OpenGL version is not available");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -611,7 +611,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
|||||||
if (!window->GetStringi)
|
if (!window->GetStringi)
|
||||||
{
|
{
|
||||||
glfwCloseWindow(window);
|
glfwCloseWindow(window);
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR);
|
_glfwSetError(GLFW_PLATFORM_ERROR, "glfwOpenWindow: Entry point retrieval is broken; see the build documentation for your platform");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -637,7 +637,7 @@ GLFWAPI void glfwMakeWindowCurrent(GLFWwindow window)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -659,7 +659,7 @@ GLFWAPI int glfwIsWindow(GLFWwindow window)
|
|||||||
|
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -684,7 +684,7 @@ GLFWAPI GLFWwindow glfwGetCurrentWindow(void)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -700,7 +700,7 @@ GLFWAPI void glfwOpenWindowHint(int target, int hint)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -780,7 +780,7 @@ GLFWAPI void glfwCloseWindow(GLFWwindow window)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -820,7 +820,7 @@ GLFWAPI void glfwSetWindowTitle(GLFWwindow window, const char* title)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -836,7 +836,7 @@ GLFWAPI void glfwGetWindowSize(GLFWwindow window, int* width, int* height)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -856,7 +856,7 @@ GLFWAPI void glfwSetWindowSize(GLFWwindow window, int width, int height)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -889,7 +889,7 @@ GLFWAPI void glfwGetWindowPos(GLFWwindow window, int* x, int* y)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -909,7 +909,7 @@ GLFWAPI void glfwSetWindowPos(GLFWwindow window, int x, int y)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -931,7 +931,7 @@ GLFWAPI void glfwIconifyWindow(GLFWwindow window)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -950,7 +950,7 @@ GLFWAPI void glfwRestoreWindow(GLFWwindow window)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -973,13 +973,13 @@ GLFWAPI void glfwSwapBuffers(void)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_glfwLibrary.currentWindow)
|
if (!_glfwLibrary.currentWindow)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NO_CURRENT_WINDOW);
|
_glfwSetError(GLFW_NO_CURRENT_WINDOW, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -996,13 +996,13 @@ GLFWAPI void glfwSwapInterval(int interval)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_glfwLibrary.currentWindow)
|
if (!_glfwLibrary.currentWindow)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NO_CURRENT_WINDOW);
|
_glfwSetError(GLFW_NO_CURRENT_WINDOW, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1018,7 +1018,7 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow window, int param)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1071,7 +1071,7 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow window, int param)
|
|||||||
case GLFW_OPENGL_PROFILE:
|
case GLFW_OPENGL_PROFILE:
|
||||||
return window->glProfile;
|
return window->glProfile;
|
||||||
default:
|
default:
|
||||||
_glfwSetError(GLFW_INVALID_ENUM);
|
_glfwSetError(GLFW_INVALID_ENUM, "glfwGetWindowParam: Invalid enum value for 'param' parameter");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1085,7 +1085,7 @@ GLFWAPI void glfwSetWindowUserPointer(GLFWwindow window, void* pointer)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1101,7 +1101,7 @@ GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow window)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1117,7 +1117,7 @@ GLFWAPI void glfwSetWindowSizeCallback(GLFWwindowsizefun cbfun)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1142,7 +1142,7 @@ GLFWAPI void glfwSetWindowCloseCallback(GLFWwindowclosefun cbfun)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1158,7 +1158,7 @@ GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindowrefreshfun cbfun)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1174,7 +1174,7 @@ GLFWAPI void glfwSetWindowFocusCallback(GLFWwindowfocusfun cbfun)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1190,7 +1190,7 @@ GLFWAPI void glfwSetWindowIconifyCallback(GLFWwindowiconifyfun cbfun)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1206,7 +1206,7 @@ GLFWAPI void glfwPollEvents(void)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1226,7 +1226,7 @@ GLFWAPI void glfwWaitEvents(void)
|
|||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_NOT_INITIALIZED);
|
_glfwSetError(GLFW_NOT_INITIALIZED, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,12 +71,11 @@ static GLboolean initDisplay(void)
|
|||||||
_glfwLibrary.X11.display = XOpenDisplay(0);
|
_glfwLibrary.X11.display = XOpenDisplay(0);
|
||||||
if (!_glfwLibrary.X11.display)
|
if (!_glfwLibrary.X11.display)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to open X display\n");
|
_glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11/GLX: Failed to open X display");
|
||||||
_glfwSetError(GLFW_OPENGL_UNAVAILABLE);
|
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// As the API currently doesn't understand multiple display devices, we hardcode
|
// As the API currently doesn't understand multiple display devices, we hard-code
|
||||||
// this choice and hope for the best
|
// this choice and hope for the best
|
||||||
_glfwLibrary.X11.screen = DefaultScreen(_glfwLibrary.X11.display);
|
_glfwLibrary.X11.screen = DefaultScreen(_glfwLibrary.X11.display);
|
||||||
_glfwLibrary.X11.root = RootWindow(_glfwLibrary.X11.display,
|
_glfwLibrary.X11.root = RootWindow(_glfwLibrary.X11.display,
|
||||||
@ -99,11 +98,15 @@ static GLboolean initDisplay(void)
|
|||||||
&_glfwLibrary.X11.RandR.eventBase,
|
&_glfwLibrary.X11.RandR.eventBase,
|
||||||
&_glfwLibrary.X11.RandR.errorBase);
|
&_glfwLibrary.X11.RandR.errorBase);
|
||||||
|
|
||||||
if (!XRRQueryVersion(_glfwLibrary.X11.display,
|
if (_glfwLibrary.X11.RandR.available)
|
||||||
&_glfwLibrary.X11.RandR.majorVersion,
|
|
||||||
&_glfwLibrary.X11.RandR.minorVersion))
|
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Unable to query RandR version number\n");
|
if (!XRRQueryVersion(_glfwLibrary.X11.display,
|
||||||
|
&_glfwLibrary.X11.RandR.majorVersion,
|
||||||
|
&_glfwLibrary.X11.RandR.minorVersion))
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_PLATFORM_ERROR, "X11/GLX: Failed to query RandR version");
|
||||||
|
return GL_FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
_glfwLibrary.X11.RandR.available = GL_FALSE;
|
_glfwLibrary.X11.RandR.available = GL_FALSE;
|
||||||
@ -112,8 +115,7 @@ static GLboolean initDisplay(void)
|
|||||||
// Check if GLX is supported on this display
|
// Check if GLX is supported on this display
|
||||||
if (!glXQueryExtension(_glfwLibrary.X11.display, NULL, NULL))
|
if (!glXQueryExtension(_glfwLibrary.X11.display, NULL, NULL))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "GLX not supported\n");
|
_glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11/GLX: GLX supported not found");
|
||||||
_glfwSetError(GLFW_OPENGL_UNAVAILABLE);
|
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,8 +123,7 @@ static GLboolean initDisplay(void)
|
|||||||
&_glfwLibrary.X11.glxMajor,
|
&_glfwLibrary.X11.glxMajor,
|
||||||
&_glfwLibrary.X11.glxMinor))
|
&_glfwLibrary.X11.glxMinor))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Unable to query GLX version\n");
|
_glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11/GLX: Failed to query GLX version");
|
||||||
_glfwSetError(GLFW_OPENGL_UNAVAILABLE);
|
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,8 +387,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
|
|||||||
{
|
{
|
||||||
if (!window->GLX.has_GLX_SGIX_fbconfig)
|
if (!window->GLX.has_GLX_SGIX_fbconfig)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "GLXFBConfigs are not supported by the X server\n");
|
_glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11/GLX: GLXFBConfig support not found");
|
||||||
_glfwSetError(GLFW_OPENGL_UNAVAILABLE);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -401,8 +400,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
|
|||||||
&count);
|
&count);
|
||||||
if (!count)
|
if (!count)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "No GLXFBConfigs returned\n");
|
_glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11/GLX: No GLXFBConfigs returned");
|
||||||
_glfwSetError(GLFW_OPENGL_UNAVAILABLE);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -411,8 +409,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
|
|||||||
fbconfigs = glXGetFBConfigs(_glfwLibrary.X11.display, _glfwLibrary.X11.screen, &count);
|
fbconfigs = glXGetFBConfigs(_glfwLibrary.X11.display, _glfwLibrary.X11.screen, &count);
|
||||||
if (!count)
|
if (!count)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "No GLXFBConfigs returned\n");
|
_glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11/GLX: No GLXFBConfigs returned");
|
||||||
_glfwSetError(GLFW_OPENGL_UNAVAILABLE);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -420,7 +417,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
|
|||||||
result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count);
|
result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OUT_OF_MEMORY);
|
_glfwSetError(GLFW_OUT_OF_MEMORY, "X11/GLX: Failed to allocate _GLFWfbconfig array");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -521,8 +518,7 @@ static int createContext(_GLFWwindow* window,
|
|||||||
|
|
||||||
if (fbconfig == NULL)
|
if (fbconfig == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Unable to retrieve the selected GLXFBConfig\n");
|
_glfwSetError(GLFW_PLATFORM_ERROR, "X11/GLX: Failed to retrieve the selected GLXFBConfig");
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR);
|
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -543,8 +539,7 @@ static int createContext(_GLFWwindow* window,
|
|||||||
{
|
{
|
||||||
XFree(fbconfig);
|
XFree(fbconfig);
|
||||||
|
|
||||||
fprintf(stderr, "Unable to retrieve visual for GLXFBconfig\n");
|
_glfwSetError(GLFW_PLATFORM_ERROR, "X11/GLX: Failed to retrieve visual for GLXFBConfig");
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR);
|
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -579,18 +574,14 @@ static int createContext(_GLFWwindow* window,
|
|||||||
|
|
||||||
if (!window->GLX.has_GLX_ARB_create_context_profile)
|
if (!window->GLX.has_GLX_ARB_create_context_profile)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "OpenGL profile requested but GLX_ARB_create_context_profile "
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE, "X11/GLX: An OpenGL profile requested but GLX_ARB_create_context_profile is unavailable");
|
||||||
"is unavailable\n");
|
|
||||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE);
|
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE &&
|
if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE &&
|
||||||
!window->GLX.has_GLX_EXT_create_context_es2_profile)
|
!window->GLX.has_GLX_EXT_create_context_es2_profile)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "OpenGL ES2 profile requested but "
|
_glfwSetError(GLFW_VERSION_UNAVAILABLE, "X11/GLX: OpenGL ES 2.x profile requested but GLX_EXT_create_context_es2_profile is unavailable");
|
||||||
"GLX_EXT_create_context_es2_profile is unavailable\n");
|
|
||||||
_glfwSetError(GLFW_VERSION_UNAVAILABLE);
|
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -647,9 +638,9 @@ static int createContext(_GLFWwindow* window,
|
|||||||
|
|
||||||
if (window->GLX.context == NULL)
|
if (window->GLX.context == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Unable to create OpenGL context\n");
|
|
||||||
// TODO: Handle all the various error codes here
|
// TODO: Handle all the various error codes here
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR);
|
|
||||||
|
_glfwSetError(GLFW_PLATFORM_ERROR, "X11/GLX: Failed to create OpenGL context");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -790,7 +781,8 @@ static GLboolean createWindow(_GLFWwindow* window,
|
|||||||
if (!window->X11.handle)
|
if (!window->X11.handle)
|
||||||
{
|
{
|
||||||
// TODO: Handle all the various error codes here
|
// TODO: Handle all the various error codes here
|
||||||
_glfwSetError(GLFW_PLATFORM_ERROR);
|
|
||||||
|
_glfwSetError(GLFW_PLATFORM_ERROR, "X11/GLX: Failed to create window");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -851,7 +843,7 @@ static GLboolean createWindow(_GLFWwindow* window,
|
|||||||
XWMHints* hints = XAllocWMHints();
|
XWMHints* hints = XAllocWMHints();
|
||||||
if (!hints)
|
if (!hints)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OUT_OF_MEMORY);
|
_glfwSetError(GLFW_OUT_OF_MEMORY, "X11/GLX: Failed to allocate WM hints");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -867,7 +859,7 @@ static GLboolean createWindow(_GLFWwindow* window,
|
|||||||
XSizeHints* hints = XAllocSizeHints();
|
XSizeHints* hints = XAllocSizeHints();
|
||||||
if (!hints)
|
if (!hints)
|
||||||
{
|
{
|
||||||
_glfwSetError(GLFW_OUT_OF_MEMORY);
|
_glfwSetError(GLFW_OUT_OF_MEMORY, "X11/GLX: Failed to allocate size hints");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +48,11 @@ static void usage(void)
|
|||||||
printf("available profiles: core compat es2\n");
|
printf("available profiles: core compat es2\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void error_callback(int error, const char* description)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Error: %s in %s\n", glfwErrorString(error), description);
|
||||||
|
}
|
||||||
|
|
||||||
static const char* get_glfw_profile_name(int profile)
|
static const char* get_glfw_profile_name(int profile)
|
||||||
{
|
{
|
||||||
if (profile == GLFW_OPENGL_COMPAT_PROFILE)
|
if (profile == GLFW_OPENGL_COMPAT_PROFILE)
|
||||||
@ -82,10 +87,7 @@ static void list_extensions(int major, int minor)
|
|||||||
{
|
{
|
||||||
PFNGLGETSTRINGIPROC glGetStringi = (PFNGLGETSTRINGIPROC) glfwGetProcAddress("glGetStringi");
|
PFNGLGETSTRINGIPROC glGetStringi = (PFNGLGETSTRINGIPROC) glfwGetProcAddress("glGetStringi");
|
||||||
if (!glGetStringi)
|
if (!glGetStringi)
|
||||||
{
|
|
||||||
fprintf(stderr, "Failed to retrieve glGetStringi entry point: %s\n", glfwErrorString(glfwGetError()));
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
|
||||||
|
|
||||||
glGetIntegerv(GL_NUM_EXTENSIONS, &count);
|
glGetIntegerv(GL_NUM_EXTENSIONS, &count);
|
||||||
|
|
||||||
@ -166,6 +168,8 @@ int main(int argc, char** argv)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glfwSetErrorCallback(error_callback);
|
||||||
|
|
||||||
if (major != 1 || minor != 0)
|
if (major != 1 || minor != 0)
|
||||||
{
|
{
|
||||||
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, major);
|
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, major);
|
||||||
@ -186,12 +190,7 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Version", NULL);
|
window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Version", NULL);
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
|
||||||
glfwTerminate();
|
|
||||||
|
|
||||||
fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError()));
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
|
||||||
|
|
||||||
// Report GLFW version
|
// Report GLFW version
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user