mirror of
https://github.com/glfw/glfw.git
synced 2024-11-22 13:04:35 +00:00
Added basic error reporting to shared code.
This commit is contained in:
parent
2c091571d8
commit
922cd1011a
@ -184,7 +184,10 @@ static void disableKeyRepeat(_GLFWwindow* window)
|
|||||||
GLFWAPI void glfwEnable(GLFWwindow window, int token)
|
GLFWAPI void glfwEnable(GLFWwindow window, int token)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (token)
|
switch (token)
|
||||||
{
|
{
|
||||||
@ -216,7 +219,10 @@ GLFWAPI void glfwEnable(GLFWwindow window, int token)
|
|||||||
GLFWAPI void glfwDisable(GLFWwindow window, int token)
|
GLFWAPI void glfwDisable(GLFWwindow window, int token)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (token)
|
switch (token)
|
||||||
{
|
{
|
||||||
|
@ -44,8 +44,17 @@ GLFWAPI int glfwGetVideoModes(GLFWvidmode* list, int maxcount)
|
|||||||
int count, i, swap, res1, res2, depth1, depth2;
|
int count, i, swap, res1, res2, depth1, depth2;
|
||||||
GLFWvidmode vm;
|
GLFWvidmode vm;
|
||||||
|
|
||||||
if (!_glfwInitialized || maxcount <= 0 || list == NULL)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxcount <= 0 || list == NULL)
|
||||||
|
{
|
||||||
|
// TODO: Figure out if this is an error
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Get list of video modes
|
// Get list of video modes
|
||||||
count = _glfwPlatformGetVideoModes(list, maxcount);
|
count = _glfwPlatformGetVideoModes(list, maxcount);
|
||||||
@ -83,8 +92,17 @@ GLFWAPI int glfwGetVideoModes(GLFWvidmode* list, int maxcount)
|
|||||||
|
|
||||||
GLFWAPI void glfwGetDesktopMode(GLFWvidmode* mode)
|
GLFWAPI void glfwGetDesktopMode(GLFWvidmode* mode)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized || mode == NULL)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode == NULL)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_INVALID_VALUE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_glfwPlatformGetDesktopMode(mode);
|
_glfwPlatformGetDesktopMode(mode);
|
||||||
}
|
}
|
||||||
|
37
src/glext.c
37
src/glext.c
@ -132,10 +132,19 @@ GLFWAPI int glfwExtensionSupported(const char* extension)
|
|||||||
GLint count;
|
GLint count;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!_glfwInitialized || !_glfwLibrary.window)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
_GLFWwindow* window = _glfwLibrary.window;
|
if (!_glfwLibrary.currentWindow)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NO_CURRENT_WINDOW);
|
||||||
|
return GL_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
_GLFWwindow* window = _glfwLibrary.currentWindow;
|
||||||
|
|
||||||
// Extension names should not have spaces
|
// Extension names should not have spaces
|
||||||
where = (GLubyte*) strchr(extension, ' ');
|
where = (GLubyte*) strchr(extension, ' ');
|
||||||
@ -184,8 +193,17 @@ GLFWAPI int glfwExtensionSupported(const char* extension)
|
|||||||
|
|
||||||
GLFWAPI void* glfwGetProcAddress(const char* procname)
|
GLFWAPI void* glfwGetProcAddress(const char* procname)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized || !_glfwLibrary.window)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_glfwLibrary.currentWindow)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NO_CURRENT_WINDOW);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return _glfwPlatformGetProcAddress(procname);
|
return _glfwPlatformGetProcAddress(procname);
|
||||||
}
|
}
|
||||||
@ -197,10 +215,19 @@ GLFWAPI void* glfwGetProcAddress(const char* procname)
|
|||||||
|
|
||||||
GLFWAPI void glfwGetGLVersion(int* major, int* minor, int* rev)
|
GLFWAPI void glfwGetGLVersion(int* major, int* minor, int* rev)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized || !_glfwLibrary.window)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_GLFWwindow* window = _glfwLibrary.window;
|
if (!_glfwLibrary.currentWindow)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NO_CURRENT_WINDOW);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_GLFWwindow* window = _glfwLibrary.currentWindow;
|
||||||
|
|
||||||
if (major != NULL)
|
if (major != NULL)
|
||||||
*major = window->glMajor;
|
*major = window->glMajor;
|
||||||
|
46
src/input.c
46
src/input.c
@ -42,11 +42,18 @@
|
|||||||
GLFWAPI int glfwGetKey(GLFWwindow window, int key)
|
GLFWAPI int glfwGetKey(GLFWwindow window, int key)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return GLFW_RELEASE;
|
return GLFW_RELEASE;
|
||||||
|
}
|
||||||
|
|
||||||
// Is it a valid key?
|
// Is it a valid key?
|
||||||
if (key < 0 || key > GLFW_KEY_LAST)
|
if (key < 0 || key > GLFW_KEY_LAST)
|
||||||
|
{
|
||||||
|
// TODO: Decide whether key is a value or enum
|
||||||
|
_glfwSetError(GLFW_INVALID_VALUE);
|
||||||
return GLFW_RELEASE;
|
return GLFW_RELEASE;
|
||||||
|
}
|
||||||
|
|
||||||
if (window->key[key] == GLFW_STICK)
|
if (window->key[key] == GLFW_STICK)
|
||||||
{
|
{
|
||||||
@ -66,11 +73,17 @@ GLFWAPI int glfwGetKey(GLFWwindow window, int key)
|
|||||||
GLFWAPI int glfwGetMouseButton(GLFWwindow window, int button)
|
GLFWAPI int glfwGetMouseButton(GLFWwindow window, int button)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
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);
|
||||||
return GLFW_RELEASE;
|
return GLFW_RELEASE;
|
||||||
|
}
|
||||||
|
|
||||||
if (window->mouseButton[button] == GLFW_STICK)
|
if (window->mouseButton[button] == GLFW_STICK)
|
||||||
{
|
{
|
||||||
@ -90,7 +103,10 @@ GLFWAPI int glfwGetMouseButton(GLFWwindow window, int button)
|
|||||||
GLFWAPI void glfwGetMousePos(GLFWwindow window, int* xpos, int* ypos)
|
GLFWAPI void glfwGetMousePos(GLFWwindow window, int* xpos, int* ypos)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Return mouse position
|
// Return mouse position
|
||||||
if (xpos != NULL)
|
if (xpos != NULL)
|
||||||
@ -109,7 +125,10 @@ GLFWAPI void glfwGetMousePos(GLFWwindow window, int* xpos, int* ypos)
|
|||||||
GLFWAPI void glfwSetMousePos(GLFWwindow window, int xpos, int ypos)
|
GLFWAPI void glfwSetMousePos(GLFWwindow window, int xpos, int ypos)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Don't do anything if the mouse position did not change
|
// Don't do anything if the mouse position did not change
|
||||||
if (xpos == window->mousePosX && ypos == window->mousePosY)
|
if (xpos == window->mousePosX && ypos == window->mousePosY)
|
||||||
@ -120,7 +139,7 @@ GLFWAPI void glfwSetMousePos(GLFWwindow window, int xpos, int ypos)
|
|||||||
window->mousePosY = ypos;
|
window->mousePosY = ypos;
|
||||||
|
|
||||||
// If we have a locked mouse, do not change cursor position
|
// If we have a locked mouse, do not change cursor position
|
||||||
if (_glfwLibrary.cursorLockWindow)
|
if (_glfwLibrary.cursorLockWindow == window)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Update physical cursor position
|
// Update physical cursor position
|
||||||
@ -135,7 +154,10 @@ GLFWAPI void glfwSetMousePos(GLFWwindow window, int xpos, int ypos)
|
|||||||
GLFWAPI int glfwGetMouseWheel(GLFWwindow window)
|
GLFWAPI int glfwGetMouseWheel(GLFWwindow window)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return window->wheelPos;
|
return window->wheelPos;
|
||||||
}
|
}
|
||||||
@ -148,7 +170,10 @@ GLFWAPI int glfwGetMouseWheel(GLFWwindow window)
|
|||||||
GLFWAPI void glfwSetMouseWheel(GLFWwindow window, int pos)
|
GLFWAPI void glfwSetMouseWheel(GLFWwindow window, int pos)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
window->wheelPos = pos;
|
window->wheelPos = pos;
|
||||||
}
|
}
|
||||||
@ -161,7 +186,10 @@ GLFWAPI void glfwSetMouseWheel(GLFWwindow window, int pos)
|
|||||||
GLFWAPI void glfwSetKeyCallback(GLFWwindow window, GLFWkeyfun cbfun)
|
GLFWAPI void glfwSetKeyCallback(GLFWwindow window, GLFWkeyfun cbfun)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
window->keyCallback = cbfun;
|
window->keyCallback = cbfun;
|
||||||
}
|
}
|
||||||
@ -174,7 +202,10 @@ GLFWAPI void glfwSetKeyCallback(GLFWwindow window, GLFWkeyfun cbfun)
|
|||||||
GLFWAPI void glfwSetCharCallback(GLFWwindow window, GLFWcharfun cbfun)
|
GLFWAPI void glfwSetCharCallback(GLFWwindow window, GLFWcharfun cbfun)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
window->charCallback = cbfun;
|
window->charCallback = cbfun;
|
||||||
}
|
}
|
||||||
@ -187,7 +218,10 @@ GLFWAPI void glfwSetCharCallback(GLFWwindow window, GLFWcharfun cbfun)
|
|||||||
GLFWAPI void glfwSetMouseButtonCallback(GLFWwindow window, GLFWmousebuttonfun cbfun)
|
GLFWAPI void glfwSetMouseButtonCallback(GLFWwindow window, GLFWmousebuttonfun cbfun)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
window->mouseButtonCallback = cbfun;
|
window->mouseButtonCallback = cbfun;
|
||||||
}
|
}
|
||||||
@ -199,11 +233,14 @@ GLFWAPI void glfwSetMouseButtonCallback(GLFWwindow window, GLFWmousebuttonfun cb
|
|||||||
|
|
||||||
GLFWAPI void glfwSetMousePosCallback(GLFWwindow window, GLFWmouseposfun cbfun)
|
GLFWAPI void glfwSetMousePosCallback(GLFWwindow window, GLFWmouseposfun cbfun)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized || !_glfwLibrary.window)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Set callback function
|
// Set callback function
|
||||||
_glfwLibrary.window->mousePosCallback = cbfun;
|
window->mousePosCallback = cbfun;
|
||||||
|
|
||||||
// Call the callback function to let the application know the current
|
// Call the callback function to let the application know the current
|
||||||
// mouse position
|
// mouse position
|
||||||
@ -219,7 +256,10 @@ GLFWAPI void glfwSetMousePosCallback(GLFWwindow window, GLFWmouseposfun cbfun)
|
|||||||
GLFWAPI void glfwSetMouseWheelCallback(GLFWwindow window, GLFWmousewheelfun cbfun)
|
GLFWAPI void glfwSetMouseWheelCallback(GLFWwindow window, GLFWmousewheelfun cbfun)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Set callback function
|
// Set callback function
|
||||||
window->mouseWheelCallback = cbfun;
|
window->mouseWheelCallback = cbfun;
|
||||||
|
@ -42,7 +42,10 @@
|
|||||||
GLFWAPI int glfwGetJoystickParam(int joy, int param)
|
GLFWAPI int glfwGetJoystickParam(int joy, int param)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return _glfwPlatformGetJoystickParam(joy, param);
|
return _glfwPlatformGetJoystickParam(joy, param);
|
||||||
}
|
}
|
||||||
@ -57,7 +60,10 @@ GLFWAPI int glfwGetJoystickPos(int joy, float* pos, int numaxes)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Clear positions
|
// Clear positions
|
||||||
for (i = 0; i < numaxes; i++)
|
for (i = 0; i < numaxes; i++)
|
||||||
@ -78,7 +84,10 @@ GLFWAPI int glfwGetJoystickButtons(int joy,
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Clear button states
|
// Clear button states
|
||||||
for (i = 0; i < numbuttons; i++)
|
for (i = 0; i < numbuttons; i++)
|
||||||
|
@ -42,7 +42,10 @@
|
|||||||
GLFWAPI double glfwGetTime(void)
|
GLFWAPI double glfwGetTime(void)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return 0.0;
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
return _glfwPlatformGetTime();
|
return _glfwPlatformGetTime();
|
||||||
}
|
}
|
||||||
@ -55,7 +58,10 @@ GLFWAPI double glfwGetTime(void)
|
|||||||
GLFWAPI void glfwSetTime(double time)
|
GLFWAPI void glfwSetTime(double time)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_glfwPlatformSetTime(time);
|
_glfwPlatformSetTime(time);
|
||||||
}
|
}
|
||||||
|
112
src/window.c
112
src/window.c
@ -375,12 +375,25 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, int mode)
|
|||||||
_GLFWwndconfig wndconfig;
|
_GLFWwndconfig wndconfig;
|
||||||
_GLFWwindow* window;
|
_GLFWwindow* window;
|
||||||
|
|
||||||
if (!_glfwInitialized || _glfwLibrary.window)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_glfwLibrary.window)
|
||||||
|
{
|
||||||
|
// TODO: Remove this once multi-window is completed
|
||||||
|
_glfwSetError(GLFW_INTERNAL_ERROR);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
window = (_GLFWwindow*) malloc(sizeof(_GLFWwindow));
|
window = (_GLFWwindow*) malloc(sizeof(_GLFWwindow));
|
||||||
if (!window)
|
if (!window)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_OUT_OF_MEMORY);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
_glfwLibrary.window = window;
|
_glfwLibrary.window = window;
|
||||||
|
|
||||||
@ -418,18 +431,21 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, int mode)
|
|||||||
{
|
{
|
||||||
// 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);
|
||||||
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);
|
||||||
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);
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -442,6 +458,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, int mode)
|
|||||||
{
|
{
|
||||||
// Context profiles are only defined for OpenGL version 3.2 and above
|
// Context profiles are only defined for OpenGL version 3.2 and above
|
||||||
glfwCloseWindow(window);
|
glfwCloseWindow(window);
|
||||||
|
_glfwSetError(GLFW_INVALID_VALUE);
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -449,6 +466,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, int mode)
|
|||||||
{
|
{
|
||||||
// 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);
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -456,6 +474,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, int mode)
|
|||||||
{
|
{
|
||||||
// Invalid window mode
|
// Invalid window mode
|
||||||
glfwCloseWindow(window);
|
glfwCloseWindow(window);
|
||||||
|
_glfwSetError(GLFW_INVALID_ENUM);
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -506,6 +525,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, int mode)
|
|||||||
// 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_UNAVAILABLE_VERSION);
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -515,6 +535,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, int mode)
|
|||||||
if (!window->GetStringi)
|
if (!window->GetStringi)
|
||||||
{
|
{
|
||||||
glfwCloseWindow(window);
|
glfwCloseWindow(window);
|
||||||
|
_glfwSetError(GLFW_INTERNAL_ERROR);
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -538,7 +559,13 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, int mode)
|
|||||||
|
|
||||||
GLFWAPI void glfwMakeWindowCurrent(GLFWwindow window)
|
GLFWAPI void glfwMakeWindowCurrent(GLFWwindow window)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized || _glfwLibrary.currentWindow == window)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_glfwLibrary.currentWindow == window)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_glfwPlatformMakeWindowCurrent(window);
|
_glfwPlatformMakeWindowCurrent(window);
|
||||||
@ -553,7 +580,10 @@ GLFWAPI void glfwMakeWindowCurrent(GLFWwindow window)
|
|||||||
GLFWAPI int glfwIsWindow(GLFWwindow window)
|
GLFWAPI int glfwIsWindow(GLFWwindow window)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
@ -569,7 +599,10 @@ GLFWAPI int glfwIsWindow(GLFWwindow window)
|
|||||||
GLFWAPI void glfwOpenWindowHint(int target, int hint)
|
GLFWAPI void glfwOpenWindowHint(int target, int hint)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (target)
|
switch (target)
|
||||||
{
|
{
|
||||||
@ -646,7 +679,10 @@ GLFWAPI void glfwOpenWindowHint(int target, int hint)
|
|||||||
GLFWAPI void glfwCloseWindow(GLFWwindow window)
|
GLFWAPI void glfwCloseWindow(GLFWwindow window)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Show mouse pointer again (if hidden)
|
// Show mouse pointer again (if hidden)
|
||||||
if (window == _glfwLibrary.cursorLockWindow)
|
if (window == _glfwLibrary.cursorLockWindow)
|
||||||
@ -671,7 +707,10 @@ GLFWAPI void glfwCloseWindow(GLFWwindow window)
|
|||||||
GLFWAPI void glfwSetWindowTitle(GLFWwindow window, const char* title)
|
GLFWAPI void glfwSetWindowTitle(GLFWwindow window, const char* title)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_glfwPlatformSetWindowTitle(window, title);
|
_glfwPlatformSetWindowTitle(window, title);
|
||||||
}
|
}
|
||||||
@ -684,7 +723,10 @@ GLFWAPI void glfwSetWindowTitle(GLFWwindow window, const char* title)
|
|||||||
GLFWAPI void glfwGetWindowSize(GLFWwindow window, int* width, int* height)
|
GLFWAPI void glfwGetWindowSize(GLFWwindow window, int* width, int* height)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (width != NULL)
|
if (width != NULL)
|
||||||
*width = window->width;
|
*width = window->width;
|
||||||
@ -700,8 +742,17 @@ GLFWAPI void glfwGetWindowSize(GLFWwindow window, int* width, int* height)
|
|||||||
|
|
||||||
GLFWAPI void glfwSetWindowSize(GLFWwindow window, int width, int height)
|
GLFWAPI void glfwSetWindowSize(GLFWwindow window, int width, int height)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized || window->iconified)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window->iconified)
|
||||||
|
{
|
||||||
|
// TODO: Figure out if this is an error
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Don't do anything if the window size did not change
|
// Don't do anything if the window size did not change
|
||||||
if (width == window->width && height == window->height)
|
if (width == window->width && height == window->height)
|
||||||
@ -724,8 +775,15 @@ GLFWAPI void glfwSetWindowSize(GLFWwindow window, int width, int height)
|
|||||||
|
|
||||||
GLFWAPI void glfwSetWindowPos(GLFWwindow window, int x, int y)
|
GLFWAPI void glfwSetWindowPos(GLFWwindow window, int x, int y)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized || window->mode == GLFW_FULLSCREEN || window->iconified)
|
if (!_glfwInitialized)
|
||||||
{
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window->mode == GLFW_FULLSCREEN || window->iconified)
|
||||||
|
{
|
||||||
|
// TODO: Figure out if this is an error
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -739,7 +797,13 @@ GLFWAPI void glfwSetWindowPos(GLFWwindow window, int x, int y)
|
|||||||
|
|
||||||
GLFWAPI void glfwIconifyWindow(GLFWwindow window)
|
GLFWAPI void glfwIconifyWindow(GLFWwindow window)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized || window->iconified)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window->iconified)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_glfwPlatformIconifyWindow(window);
|
_glfwPlatformIconifyWindow(window);
|
||||||
@ -752,7 +816,13 @@ GLFWAPI void glfwIconifyWindow(GLFWwindow window)
|
|||||||
|
|
||||||
GLFWAPI void glfwRestoreWindow(GLFWwindow window)
|
GLFWAPI void glfwRestoreWindow(GLFWwindow window)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized || !window->iconified)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!window->iconified)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Restore iconified window
|
// Restore iconified window
|
||||||
@ -770,7 +840,16 @@ GLFWAPI void glfwRestoreWindow(GLFWwindow window)
|
|||||||
GLFWAPI void glfwSwapBuffers(void)
|
GLFWAPI void glfwSwapBuffers(void)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_glfwLibrary.currentWindow)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NO_CURRENT_WINDOW);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (_glfwLibrary.currentWindow)
|
if (_glfwLibrary.currentWindow)
|
||||||
_glfwPlatformSwapBuffers();
|
_glfwPlatformSwapBuffers();
|
||||||
@ -784,7 +863,10 @@ GLFWAPI void glfwSwapBuffers(void)
|
|||||||
GLFWAPI void glfwSwapInterval(int interval)
|
GLFWAPI void glfwSwapInterval(int interval)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_glfwPlatformSwapInterval(interval);
|
_glfwPlatformSwapInterval(interval);
|
||||||
}
|
}
|
||||||
@ -797,7 +879,10 @@ GLFWAPI void glfwSwapInterval(int interval)
|
|||||||
GLFWAPI int glfwGetWindowParam(GLFWwindow window, int param)
|
GLFWAPI int glfwGetWindowParam(GLFWwindow window, int param)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
switch (param)
|
switch (param)
|
||||||
{
|
{
|
||||||
@ -860,7 +945,10 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow window, int param)
|
|||||||
GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow window, GLFWwindowsizefun cbfun)
|
GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow window, GLFWwindowsizefun cbfun)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
window->windowSizeCallback = cbfun;
|
window->windowSizeCallback = cbfun;
|
||||||
|
|
||||||
@ -877,7 +965,10 @@ GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow window, GLFWwindowsizefun cbfu
|
|||||||
GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow window, GLFWwindowclosefun cbfun)
|
GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow window, GLFWwindowclosefun cbfun)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
window->windowCloseCallback = cbfun;
|
window->windowCloseCallback = cbfun;
|
||||||
}
|
}
|
||||||
@ -890,7 +981,10 @@ GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow window, GLFWwindowclosefun cb
|
|||||||
GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow window, GLFWwindowrefreshfun cbfun)
|
GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow window, GLFWwindowrefreshfun cbfun)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
window->windowRefreshCallback = cbfun;
|
window->windowRefreshCallback = cbfun;
|
||||||
}
|
}
|
||||||
@ -903,7 +997,10 @@ GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow window, GLFWwindowrefreshfu
|
|||||||
GLFWAPI void glfwPollEvents(void)
|
GLFWAPI void glfwPollEvents(void)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_glfwPlatformPollEvents();
|
_glfwPlatformPollEvents();
|
||||||
}
|
}
|
||||||
@ -916,7 +1013,10 @@ GLFWAPI void glfwPollEvents(void)
|
|||||||
GLFWAPI void glfwWaitEvents(void)
|
GLFWAPI void glfwWaitEvents(void)
|
||||||
{
|
{
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_NOT_INITIALIZED);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_glfwPlatformWaitEvents();
|
_glfwPlatformWaitEvents();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user