mirror of
https://github.com/glfw/glfw.git
synced 2024-11-10 00:51:47 +00:00
Initial pass for multi-window support.
This commit is contained in:
parent
8247a6b3eb
commit
135194a960
@ -306,7 +306,6 @@ extern "C" {
|
||||
#define GLFW_FULLSCREEN 0x00010002
|
||||
|
||||
/* glfwGetWindowParam tokens */
|
||||
#define GLFW_OPENED 0x00020001
|
||||
#define GLFW_ACTIVE 0x00020002
|
||||
#define GLFW_ICONIFIED 0x00020003
|
||||
#define GLFW_ACCELERATED 0x00020004
|
||||
@ -356,6 +355,8 @@ extern "C" {
|
||||
* Typedefs
|
||||
*************************************************************************/
|
||||
|
||||
typedef struct _GLFWwindow* GLFWwindow;
|
||||
|
||||
/* The video mode structure used by glfwGetVideoModes() */
|
||||
typedef struct {
|
||||
int width, height;
|
||||
@ -382,41 +383,42 @@ GLFWAPI int glfwInit(void);
|
||||
GLFWAPI void glfwTerminate(void);
|
||||
GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev);
|
||||
|
||||
/* Window handling */
|
||||
GLFWAPI int glfwOpenWindow(int width, int height, int redbits, int greenbits, int bluebits, int alphabits, int depthbits, int stencilbits, int mode);
|
||||
GLFWAPI void glfwOpenWindowHint(int target, int hint);
|
||||
GLFWAPI void glfwCloseWindow(void);
|
||||
GLFWAPI void glfwSetWindowTitle(const char* title);
|
||||
GLFWAPI void glfwGetWindowSize(int* width, int* height);
|
||||
GLFWAPI void glfwSetWindowSize(int width, int height);
|
||||
GLFWAPI void glfwSetWindowPos(int x, int y);
|
||||
GLFWAPI void glfwIconifyWindow(void);
|
||||
GLFWAPI void glfwRestoreWindow(void);
|
||||
GLFWAPI void glfwSwapBuffers(void);
|
||||
GLFWAPI void glfwSwapInterval(int interval);
|
||||
GLFWAPI int glfwGetWindowParam(int param);
|
||||
GLFWAPI void glfwSetWindowSizeCallback(GLFWwindowsizefun cbfun);
|
||||
GLFWAPI void glfwSetWindowCloseCallback(GLFWwindowclosefun cbfun);
|
||||
GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindowrefreshfun cbfun);
|
||||
|
||||
/* Video mode functions */
|
||||
GLFWAPI int glfwGetVideoModes(GLFWvidmode* list, int maxcount);
|
||||
GLFWAPI void glfwGetDesktopMode(GLFWvidmode* mode);
|
||||
|
||||
/* Input handling */
|
||||
/* Window handling */
|
||||
GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, int redbits, int greenbits, int bluebits, int alphabits, int depthbits, int stencilbits, int mode);
|
||||
GLFWAPI void glfwOpenWindowHint(int target, int hint);
|
||||
GLFWAPI void glfwMakeWindowCurrent(GLFWwindow window);
|
||||
GLFWAPI void glfwCloseWindow(GLFWwindow window);
|
||||
GLFWAPI void glfwSetWindowTitle(GLFWwindow, const char* title);
|
||||
GLFWAPI void glfwGetWindowSize(GLFWwindow, int* width, int* height);
|
||||
GLFWAPI void glfwSetWindowSize(GLFWwindow, int width, int height);
|
||||
GLFWAPI void glfwSetWindowPos(GLFWwindow, int x, int y);
|
||||
GLFWAPI void glfwIconifyWindow(GLFWwindow window);
|
||||
GLFWAPI void glfwRestoreWindow(GLFWwindow window);
|
||||
GLFWAPI int glfwGetWindowParam(GLFWwindow window, int param);
|
||||
GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow window, GLFWwindowsizefun cbfun);
|
||||
GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow window, GLFWwindowclosefun cbfun);
|
||||
GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow window, GLFWwindowrefreshfun cbfun);
|
||||
|
||||
/* Event handling */
|
||||
GLFWAPI void glfwPollEvents(void);
|
||||
GLFWAPI void glfwWaitEvents(void);
|
||||
GLFWAPI int glfwGetKey(int key);
|
||||
GLFWAPI int glfwGetMouseButton(int button);
|
||||
GLFWAPI void glfwGetMousePos(int* xpos, int* ypos);
|
||||
GLFWAPI void glfwSetMousePos(int xpos, int ypos);
|
||||
GLFWAPI int glfwGetMouseWheel(void);
|
||||
GLFWAPI void glfwSetMouseWheel(int pos);
|
||||
GLFWAPI void glfwSetKeyCallback(GLFWkeyfun cbfun);
|
||||
GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun);
|
||||
GLFWAPI void glfwSetMouseButtonCallback(GLFWmousebuttonfun cbfun);
|
||||
GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun);
|
||||
GLFWAPI void glfwSetMouseWheelCallback(GLFWmousewheelfun cbfun);
|
||||
|
||||
/* Input handling */
|
||||
GLFWAPI int glfwGetKey(GLFWwindow window, int key);
|
||||
GLFWAPI int glfwGetMouseButton(GLFWwindow window, int button);
|
||||
GLFWAPI void glfwGetMousePos(GLFWwindow window, int* xpos, int* ypos);
|
||||
GLFWAPI void glfwSetMousePos(GLFWwindow window, int xpos, int ypos);
|
||||
GLFWAPI int glfwGetMouseWheel(GLFWwindow window);
|
||||
GLFWAPI void glfwSetMouseWheel(GLFWwindow window, int pos);
|
||||
GLFWAPI void glfwSetKeyCallback(GLFWwindow window, GLFWkeyfun cbfun);
|
||||
GLFWAPI void glfwSetCharCallback(GLFWwindow window, GLFWcharfun cbfun);
|
||||
GLFWAPI void glfwSetMouseButtonCallback(GLFWwindow window, GLFWmousebuttonfun cbfun);
|
||||
GLFWAPI void glfwSetMousePosCallback(GLFWwindow window, GLFWmouseposfun cbfun);
|
||||
GLFWAPI void glfwSetMouseWheelCallback(GLFWwindow window, GLFWmousewheelfun cbfun);
|
||||
|
||||
/* Joystick input */
|
||||
GLFWAPI int glfwGetJoystickParam(int joy, int param);
|
||||
@ -427,14 +429,16 @@ GLFWAPI int glfwGetJoystickButtons(int joy, unsigned char* buttons, int numbutto
|
||||
GLFWAPI double glfwGetTime(void);
|
||||
GLFWAPI void glfwSetTime(double time);
|
||||
|
||||
/* Extension support */
|
||||
/* OpenGL support */
|
||||
GLFWAPI void glfwSwapBuffers(void);
|
||||
GLFWAPI void glfwSwapInterval(int interval);
|
||||
GLFWAPI int glfwExtensionSupported(const char* extension);
|
||||
GLFWAPI void* glfwGetProcAddress(const char* procname);
|
||||
GLFWAPI void glfwGetGLVersion(int* major, int* minor, int* rev);
|
||||
|
||||
/* Enable/disable functions */
|
||||
GLFWAPI void glfwEnable(int token);
|
||||
GLFWAPI void glfwDisable(int token);
|
||||
GLFWAPI void glfwEnable(GLFWwindow window, int token);
|
||||
GLFWAPI void glfwDisable(GLFWwindow window, int token);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
115
lib/enable.c
115
lib/enable.c
@ -39,55 +39,56 @@
|
||||
// Enable (show) mouse cursor
|
||||
//========================================================================
|
||||
|
||||
static void enableMouseCursor(void)
|
||||
static void enableMouseCursor(_GLFWwindow* window)
|
||||
{
|
||||
int centerPosX, centerPosY;
|
||||
|
||||
if (!_glfwWin.opened || !_glfwWin.mouseLock)
|
||||
if (_glfwLibrary.cursorLockWindow != window)
|
||||
return;
|
||||
|
||||
// Show mouse cursor
|
||||
_glfwPlatformShowMouseCursor();
|
||||
_glfwPlatformShowMouseCursor(window);
|
||||
|
||||
centerPosX = _glfwWin.width / 2;
|
||||
centerPosY = _glfwWin.height / 2;
|
||||
centerPosX = window->width / 2;
|
||||
centerPosY = window->height / 2;
|
||||
|
||||
if (centerPosX != _glfwInput.MousePosX || centerPosY != _glfwInput.MousePosY)
|
||||
if (centerPosX != window->mousePosX || centerPosY != window->mousePosY)
|
||||
{
|
||||
_glfwPlatformSetMouseCursorPos(centerPosX, centerPosY);
|
||||
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
|
||||
|
||||
_glfwInput.MousePosX = centerPosX;
|
||||
_glfwInput.MousePosY = centerPosY;
|
||||
window->mousePosX = centerPosX;
|
||||
window->mousePosY = centerPosY;
|
||||
|
||||
if (_glfwWin.mousePosCallback)
|
||||
if (window->mousePosCallback)
|
||||
{
|
||||
_glfwWin.mousePosCallback(_glfwInput.MousePosX,
|
||||
_glfwInput.MousePosY);
|
||||
window->mousePosCallback(window->mousePosX,
|
||||
window->mousePosY);
|
||||
}
|
||||
}
|
||||
|
||||
// From now on the mouse is unlocked
|
||||
_glfwWin.mouseLock = GL_FALSE;
|
||||
_glfwLibrary.cursorLockWindow = NULL;
|
||||
}
|
||||
|
||||
//========================================================================
|
||||
// Disable (hide) mouse cursor
|
||||
//========================================================================
|
||||
|
||||
static void disableMouseCursor(void)
|
||||
static void disableMouseCursor(_GLFWwindow* window)
|
||||
{
|
||||
if (!_glfwWin.opened || _glfwWin.mouseLock)
|
||||
if (_glfwLibrary.cursorLockWindow)
|
||||
return;
|
||||
|
||||
// Hide mouse cursor
|
||||
_glfwPlatformHideMouseCursor();
|
||||
_glfwPlatformHideMouseCursor(window);
|
||||
|
||||
// Move cursor to the middle of the window
|
||||
_glfwPlatformSetMouseCursorPos(_glfwWin.width >> 1,
|
||||
_glfwWin.height >> 1);
|
||||
_glfwPlatformSetMouseCursorPos(window,
|
||||
window->width / 2,
|
||||
window->height / 2);
|
||||
|
||||
// From now on the mouse is locked
|
||||
_glfwWin.mouseLock = GL_TRUE;
|
||||
_glfwLibrary.cursorLockWindow = window;
|
||||
}
|
||||
|
||||
|
||||
@ -95,26 +96,26 @@ static void disableMouseCursor(void)
|
||||
// Enable sticky keys
|
||||
//========================================================================
|
||||
|
||||
static void enableStickyKeys(void)
|
||||
static void enableStickyKeys(_GLFWwindow* window)
|
||||
{
|
||||
_glfwInput.StickyKeys = 1;
|
||||
window->stickyKeys = GL_TRUE;
|
||||
}
|
||||
|
||||
//========================================================================
|
||||
// Disable sticky keys
|
||||
//========================================================================
|
||||
|
||||
static void disableStickyKeys(void)
|
||||
static void disableStickyKeys(_GLFWwindow* window)
|
||||
{
|
||||
int i;
|
||||
|
||||
_glfwInput.StickyKeys = 0;
|
||||
window->stickyKeys = GL_FALSE;
|
||||
|
||||
// Release all sticky keys
|
||||
for (i = 0; i <= GLFW_KEY_LAST; i++)
|
||||
{
|
||||
if (_glfwInput.Key[i] == 2)
|
||||
_glfwInput.Key[i] = 0;
|
||||
if (window->key[i] == GLFW_STICK)
|
||||
window->key[i] = GLFW_RELEASE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,26 +124,26 @@ static void disableStickyKeys(void)
|
||||
// Enable sticky mouse buttons
|
||||
//========================================================================
|
||||
|
||||
static void enableStickyMouseButtons(void)
|
||||
static void enableStickyMouseButtons(_GLFWwindow* window)
|
||||
{
|
||||
_glfwInput.StickyMouseButtons = 1;
|
||||
window->stickyMouseButtons = GL_TRUE;
|
||||
}
|
||||
|
||||
//========================================================================
|
||||
// Disable sticky mouse buttons
|
||||
//========================================================================
|
||||
|
||||
static void disableStickyMouseButtons(void)
|
||||
static void disableStickyMouseButtons(_GLFWwindow* window)
|
||||
{
|
||||
int i;
|
||||
|
||||
_glfwInput.StickyMouseButtons = 0;
|
||||
window->stickyMouseButtons = GL_FALSE;
|
||||
|
||||
// Release all sticky mouse buttons
|
||||
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
|
||||
{
|
||||
if (_glfwInput.MouseButton[i] == 2)
|
||||
_glfwInput.MouseButton[i] = 0;
|
||||
if (window->mouseButton[i] == GLFW_STICK)
|
||||
window->mouseButton[i] = GLFW_RELEASE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,30 +152,30 @@ static void disableStickyMouseButtons(void)
|
||||
// Enable system keys
|
||||
//========================================================================
|
||||
|
||||
static void enableSystemKeys(void)
|
||||
static void enableSystemKeys(_GLFWwindow* window)
|
||||
{
|
||||
if (!_glfwWin.sysKeysDisabled)
|
||||
if (!window->sysKeysDisabled)
|
||||
return;
|
||||
|
||||
_glfwPlatformEnableSystemKeys();
|
||||
_glfwPlatformEnableSystemKeys(window);
|
||||
|
||||
// Indicate that system keys are no longer disabled
|
||||
_glfwWin.sysKeysDisabled = GL_FALSE;
|
||||
window->sysKeysDisabled = GL_FALSE;
|
||||
}
|
||||
|
||||
//========================================================================
|
||||
// Disable system keys
|
||||
//========================================================================
|
||||
|
||||
static void disableSystemKeys(void)
|
||||
static void disableSystemKeys(_GLFWwindow* window)
|
||||
{
|
||||
if (_glfwWin.sysKeysDisabled)
|
||||
if (window->sysKeysDisabled)
|
||||
return;
|
||||
|
||||
_glfwPlatformDisableSystemKeys();
|
||||
_glfwPlatformDisableSystemKeys(window);
|
||||
|
||||
// Indicate that system keys are now disabled
|
||||
_glfwWin.sysKeysDisabled = GL_TRUE;
|
||||
window->sysKeysDisabled = GL_TRUE;
|
||||
}
|
||||
|
||||
|
||||
@ -182,18 +183,18 @@ static void disableSystemKeys(void)
|
||||
// Enable key repeat
|
||||
//========================================================================
|
||||
|
||||
static void enableKeyRepeat(void)
|
||||
static void enableKeyRepeat(_GLFWwindow* window)
|
||||
{
|
||||
_glfwInput.KeyRepeat = 1;
|
||||
window->keyRepeat = GL_TRUE;
|
||||
}
|
||||
|
||||
//========================================================================
|
||||
// Disable key repeat
|
||||
//========================================================================
|
||||
|
||||
static void disableKeyRepeat(void)
|
||||
static void disableKeyRepeat(_GLFWwindow* window)
|
||||
{
|
||||
_glfwInput.KeyRepeat = 0;
|
||||
window->keyRepeat = GL_FALSE;
|
||||
}
|
||||
|
||||
|
||||
@ -202,10 +203,10 @@ static void disableKeyRepeat(void)
|
||||
//************************************************************************
|
||||
|
||||
//========================================================================
|
||||
// Enable certain GLFW/window/system functions.
|
||||
// Enable certain GLFW/window/system functions
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwEnable(int token)
|
||||
GLFWAPI void glfwEnable(GLFWwindow window, int token)
|
||||
{
|
||||
if (!_glfwInitialized)
|
||||
return;
|
||||
@ -213,19 +214,19 @@ GLFWAPI void glfwEnable(int token)
|
||||
switch (token)
|
||||
{
|
||||
case GLFW_MOUSE_CURSOR:
|
||||
enableMouseCursor();
|
||||
enableMouseCursor(window);
|
||||
break;
|
||||
case GLFW_STICKY_KEYS:
|
||||
enableStickyKeys();
|
||||
enableStickyKeys(window);
|
||||
break;
|
||||
case GLFW_STICKY_MOUSE_BUTTONS:
|
||||
enableStickyMouseButtons();
|
||||
enableStickyMouseButtons(window);
|
||||
break;
|
||||
case GLFW_SYSTEM_KEYS:
|
||||
enableSystemKeys();
|
||||
enableSystemKeys(window);
|
||||
break;
|
||||
case GLFW_KEY_REPEAT:
|
||||
enableKeyRepeat();
|
||||
enableKeyRepeat(window);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -234,10 +235,10 @@ GLFWAPI void glfwEnable(int token)
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Disable certain GLFW/window/system functions.
|
||||
// Disable certain GLFW/window/system functions
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwDisable(int token)
|
||||
GLFWAPI void glfwDisable(GLFWwindow window, int token)
|
||||
{
|
||||
if (!_glfwInitialized)
|
||||
return;
|
||||
@ -245,19 +246,19 @@ GLFWAPI void glfwDisable(int token)
|
||||
switch (token)
|
||||
{
|
||||
case GLFW_MOUSE_CURSOR:
|
||||
disableMouseCursor();
|
||||
disableMouseCursor(window);
|
||||
break;
|
||||
case GLFW_STICKY_KEYS:
|
||||
disableStickyKeys();
|
||||
disableStickyKeys(window);
|
||||
break;
|
||||
case GLFW_STICKY_MOUSE_BUTTONS:
|
||||
disableStickyMouseButtons();
|
||||
disableStickyMouseButtons(window);
|
||||
break;
|
||||
case GLFW_SYSTEM_KEYS:
|
||||
disableSystemKeys();
|
||||
disableSystemKeys(window);
|
||||
break;
|
||||
case GLFW_KEY_REPEAT:
|
||||
disableKeyRepeat();
|
||||
disableKeyRepeat(window);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
20
lib/glext.c
20
lib/glext.c
@ -132,15 +132,17 @@ GLFWAPI int glfwExtensionSupported(const char* extension)
|
||||
GLint count;
|
||||
int i;
|
||||
|
||||
if (!_glfwInitialized || !_glfwWin.opened)
|
||||
if (!_glfwInitialized || !_glfwLibrary.window)
|
||||
return GL_FALSE;
|
||||
|
||||
_GLFWwindow* window = _glfwLibrary.window;
|
||||
|
||||
// Extension names should not have spaces
|
||||
where = (GLubyte*) strchr(extension, ' ');
|
||||
if (where || *extension == '\0')
|
||||
return GL_FALSE;
|
||||
|
||||
if (_glfwWin.glMajor < 3)
|
||||
if (window->glMajor < 3)
|
||||
{
|
||||
// Check if extension is in the old style OpenGL extensions string
|
||||
|
||||
@ -159,7 +161,7 @@ GLFWAPI int glfwExtensionSupported(const char* extension)
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
if (strcmp((const char*) _glfwWin.GetStringi(GL_EXTENSIONS, i),
|
||||
if (strcmp((const char*) window->GetStringi(GL_EXTENSIONS, i),
|
||||
extension) == 0)
|
||||
{
|
||||
return GL_TRUE;
|
||||
@ -182,7 +184,7 @@ GLFWAPI int glfwExtensionSupported(const char* extension)
|
||||
|
||||
GLFWAPI void* glfwGetProcAddress(const char* procname)
|
||||
{
|
||||
if (!_glfwInitialized || !_glfwWin.opened)
|
||||
if (!_glfwInitialized || !_glfwLibrary.window)
|
||||
return NULL;
|
||||
|
||||
return _glfwPlatformGetProcAddress(procname);
|
||||
@ -195,16 +197,18 @@ GLFWAPI void* glfwGetProcAddress(const char* procname)
|
||||
|
||||
GLFWAPI void glfwGetGLVersion(int* major, int* minor, int* rev)
|
||||
{
|
||||
if (!_glfwInitialized || !_glfwWin.opened)
|
||||
if (!_glfwInitialized || !_glfwLibrary.window)
|
||||
return;
|
||||
|
||||
_GLFWwindow* window = _glfwLibrary.window;
|
||||
|
||||
if (major != NULL)
|
||||
*major = _glfwWin.glMajor;
|
||||
*major = window->glMajor;
|
||||
|
||||
if (minor != NULL)
|
||||
*minor = _glfwWin.glMinor;
|
||||
*minor = window->glMinor;
|
||||
|
||||
if (rev != NULL)
|
||||
*rev = _glfwWin.glRevision;
|
||||
*rev = window->glRevision;
|
||||
}
|
||||
|
||||
|
@ -48,13 +48,6 @@ GLFWAPI int glfwInit(void)
|
||||
return GL_TRUE;
|
||||
|
||||
memset(&_glfwLibrary, 0, sizeof(_glfwLibrary));
|
||||
memset(&_glfwWin, 0, sizeof(_glfwWin ));
|
||||
|
||||
// Window is not yet opened
|
||||
_glfwWin.opened = GL_FALSE;
|
||||
|
||||
// Default enable/disable settings
|
||||
_glfwWin.sysKeysDisabled = GL_FALSE;
|
||||
|
||||
// Clear window hints
|
||||
_glfwClearWindowHints();
|
||||
|
93
lib/input.c
93
lib/input.c
@ -35,23 +35,23 @@
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI int glfwGetKey(int key)
|
||||
GLFWAPI int glfwGetKey(GLFWwindow window, int key)
|
||||
{
|
||||
if (!_glfwInitialized || !_glfwWin.opened)
|
||||
if (!_glfwInitialized)
|
||||
return GLFW_RELEASE;
|
||||
|
||||
// Is it a valid key?
|
||||
if (key < 0 || key > GLFW_KEY_LAST)
|
||||
return GLFW_RELEASE;
|
||||
|
||||
if (_glfwInput.Key[key] == GLFW_STICK)
|
||||
if (window->key[key] == GLFW_STICK)
|
||||
{
|
||||
// Sticky mode: release key now
|
||||
_glfwInput.Key[key] = GLFW_RELEASE;
|
||||
window->key[key] = GLFW_RELEASE;
|
||||
return GLFW_PRESS;
|
||||
}
|
||||
|
||||
return (int) _glfwInput.Key[key];
|
||||
return (int) window->key[key];
|
||||
}
|
||||
|
||||
|
||||
@ -59,23 +59,23 @@ GLFWAPI int glfwGetKey(int key)
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI int glfwGetMouseButton(int button)
|
||||
GLFWAPI int glfwGetMouseButton(GLFWwindow window, int button)
|
||||
{
|
||||
if (!_glfwInitialized || !_glfwWin.opened)
|
||||
if (!_glfwInitialized)
|
||||
return GLFW_RELEASE;
|
||||
|
||||
// Is it a valid mouse button?
|
||||
if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST)
|
||||
return GLFW_RELEASE;
|
||||
|
||||
if (_glfwInput.MouseButton[button] == GLFW_STICK)
|
||||
if (window->mouseButton[button] == GLFW_STICK)
|
||||
{
|
||||
// Sticky mode: release mouse button now
|
||||
_glfwInput.MouseButton[button] = GLFW_RELEASE;
|
||||
window->mouseButton[button] = GLFW_RELEASE;
|
||||
return GLFW_PRESS;
|
||||
}
|
||||
|
||||
return (int) _glfwInput.MouseButton[button];
|
||||
return (int) window->mouseButton[button];
|
||||
}
|
||||
|
||||
|
||||
@ -83,17 +83,17 @@ GLFWAPI int glfwGetMouseButton(int button)
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwGetMousePos(int* xpos, int* ypos)
|
||||
GLFWAPI void glfwGetMousePos(GLFWwindow window, int* xpos, int* ypos)
|
||||
{
|
||||
if (!_glfwInitialized || !_glfwWin.opened)
|
||||
if (!_glfwInitialized)
|
||||
return;
|
||||
|
||||
// Return mouse position
|
||||
if (xpos != NULL)
|
||||
*xpos = _glfwInput.MousePosX;
|
||||
*xpos = window->mousePosX;
|
||||
|
||||
if (ypos != NULL)
|
||||
*ypos = _glfwInput.MousePosY;
|
||||
*ypos = window->mousePosY;
|
||||
}
|
||||
|
||||
|
||||
@ -101,25 +101,25 @@ GLFWAPI void glfwGetMousePos(int* xpos, int* ypos)
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetMousePos(int xpos, int ypos)
|
||||
GLFWAPI void glfwSetMousePos(GLFWwindow window, int xpos, int ypos)
|
||||
{
|
||||
if (!_glfwInitialized || !_glfwWin.opened)
|
||||
if (!_glfwInitialized)
|
||||
return;
|
||||
|
||||
// Don't do anything if the mouse position did not change
|
||||
if (xpos == _glfwInput.MousePosX && ypos == _glfwInput.MousePosY)
|
||||
if (xpos == window->mousePosX && ypos == window->mousePosY)
|
||||
return;
|
||||
|
||||
// Set GLFW mouse position
|
||||
_glfwInput.MousePosX = xpos;
|
||||
_glfwInput.MousePosY = ypos;
|
||||
window->mousePosX = xpos;
|
||||
window->mousePosY = ypos;
|
||||
|
||||
// If we have a locked mouse, do not change cursor position
|
||||
if (_glfwWin.mouseLock)
|
||||
if (_glfwLibrary.cursorLockWindow)
|
||||
return;
|
||||
|
||||
// Update physical cursor position
|
||||
_glfwPlatformSetMouseCursorPos(xpos, ypos);
|
||||
_glfwPlatformSetMouseCursorPos(window, xpos, ypos);
|
||||
}
|
||||
|
||||
|
||||
@ -127,13 +127,12 @@ GLFWAPI void glfwSetMousePos(int xpos, int ypos)
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI int glfwGetMouseWheel(void)
|
||||
GLFWAPI int glfwGetMouseWheel(GLFWwindow window)
|
||||
{
|
||||
if (!_glfwInitialized || !_glfwWin.opened)
|
||||
if (!_glfwInitialized)
|
||||
return 0;
|
||||
|
||||
// Return mouse wheel position
|
||||
return _glfwInput.WheelPos;
|
||||
return window->wheelPos;
|
||||
}
|
||||
|
||||
|
||||
@ -141,13 +140,12 @@ GLFWAPI int glfwGetMouseWheel(void)
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetMouseWheel(int pos)
|
||||
GLFWAPI void glfwSetMouseWheel(GLFWwindow window, int pos)
|
||||
{
|
||||
if (!_glfwInitialized || !_glfwWin.opened)
|
||||
if (!_glfwInitialized)
|
||||
return;
|
||||
|
||||
// Set mouse wheel position
|
||||
_glfwInput.WheelPos = pos;
|
||||
window->wheelPos = pos;
|
||||
}
|
||||
|
||||
|
||||
@ -155,13 +153,12 @@ GLFWAPI void glfwSetMouseWheel(int pos)
|
||||
// Set callback function for keyboard input
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetKeyCallback(GLFWkeyfun cbfun)
|
||||
GLFWAPI void glfwSetKeyCallback(GLFWwindow window, GLFWkeyfun cbfun)
|
||||
{
|
||||
if (!_glfwInitialized || !_glfwWin.opened)
|
||||
if (!_glfwInitialized)
|
||||
return;
|
||||
|
||||
// Set callback function
|
||||
_glfwWin.keyCallback = cbfun;
|
||||
window->keyCallback = cbfun;
|
||||
}
|
||||
|
||||
|
||||
@ -169,13 +166,12 @@ GLFWAPI void glfwSetKeyCallback(GLFWkeyfun cbfun)
|
||||
// Set callback function for character input
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun)
|
||||
GLFWAPI void glfwSetCharCallback(GLFWwindow window, GLFWcharfun cbfun)
|
||||
{
|
||||
if (!_glfwInitialized || !_glfwWin.opened)
|
||||
if (!_glfwInitialized)
|
||||
return;
|
||||
|
||||
// Set callback function
|
||||
_glfwWin.charCallback = cbfun;
|
||||
window->charCallback = cbfun;
|
||||
}
|
||||
|
||||
|
||||
@ -183,13 +179,12 @@ GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun)
|
||||
// Set callback function for mouse clicks
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetMouseButtonCallback(GLFWmousebuttonfun cbfun)
|
||||
GLFWAPI void glfwSetMouseButtonCallback(GLFWwindow window, GLFWmousebuttonfun cbfun)
|
||||
{
|
||||
if (!_glfwInitialized || !_glfwWin.opened)
|
||||
if (!_glfwInitialized)
|
||||
return;
|
||||
|
||||
// Set callback function
|
||||
_glfwWin.mouseButtonCallback = cbfun;
|
||||
window->mouseButtonCallback = cbfun;
|
||||
}
|
||||
|
||||
|
||||
@ -197,18 +192,18 @@ GLFWAPI void glfwSetMouseButtonCallback(GLFWmousebuttonfun cbfun)
|
||||
// Set callback function for mouse moves
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun)
|
||||
GLFWAPI void glfwSetMousePosCallback(GLFWwindow window, GLFWmouseposfun cbfun)
|
||||
{
|
||||
if (!_glfwInitialized || !_glfwWin.opened)
|
||||
if (!_glfwInitialized || !_glfwLibrary.window)
|
||||
return;
|
||||
|
||||
// Set callback function
|
||||
_glfwWin.mousePosCallback = cbfun;
|
||||
_glfwLibrary.window->mousePosCallback = cbfun;
|
||||
|
||||
// Call the callback function to let the application know the current
|
||||
// mouse position
|
||||
if (cbfun)
|
||||
cbfun(_glfwInput.MousePosX, _glfwInput.MousePosY);
|
||||
cbfun(window->mousePosX, window->mousePosY);
|
||||
}
|
||||
|
||||
|
||||
@ -216,17 +211,17 @@ GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun)
|
||||
// Set callback function for mouse wheel
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetMouseWheelCallback(GLFWmousewheelfun cbfun)
|
||||
GLFWAPI void glfwSetMouseWheelCallback(GLFWwindow window, GLFWmousewheelfun cbfun)
|
||||
{
|
||||
if (!_glfwInitialized || !_glfwWin.opened)
|
||||
if (!_glfwInitialized)
|
||||
return;
|
||||
|
||||
// Set callback function
|
||||
_glfwWin.mouseWheelCallback = cbfun;
|
||||
window->mouseWheelCallback = cbfun;
|
||||
|
||||
// Call the callback function to let the application know the current
|
||||
// mouse wheel position
|
||||
if (cbfun)
|
||||
cbfun(_glfwInput.WheelPos);
|
||||
cbfun(window->wheelPos);
|
||||
}
|
||||
|
||||
|
142
lib/internal.h
142
lib/internal.h
@ -51,6 +51,14 @@
|
||||
#define GLFW_STICK 2
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Platform specific definitions goes in platform.h (which also includes
|
||||
// glfw.h)
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Window opening hints (set by glfwOpenWindowHint)
|
||||
// A bucket of semi-random stuff bunched together for historical reasons
|
||||
@ -75,14 +83,6 @@ typedef struct {
|
||||
} _GLFWhints;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Platform specific definitions goes in platform.h (which also includes
|
||||
// glfw.h)
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Parameters relating to the creation of the context and window but not
|
||||
// directly related to the properties of the framebuffer
|
||||
@ -126,6 +126,81 @@ typedef struct {
|
||||
} _GLFWfbconfig;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Window structure
|
||||
//------------------------------------------------------------------------
|
||||
typedef struct _GLFWwindow {
|
||||
|
||||
// User callback functions
|
||||
GLFWwindowsizefun windowSizeCallback;
|
||||
GLFWwindowclosefun windowCloseCallback;
|
||||
GLFWwindowrefreshfun windowRefreshCallback;
|
||||
GLFWmousebuttonfun mouseButtonCallback;
|
||||
GLFWmouseposfun mousePosCallback;
|
||||
GLFWmousewheelfun mouseWheelCallback;
|
||||
GLFWkeyfun keyCallback;
|
||||
GLFWcharfun charCallback;
|
||||
|
||||
// User selected window settings
|
||||
int mode;
|
||||
GLboolean sysKeysDisabled; // System keys disabled flag
|
||||
GLboolean windowNoResize; // Resize- and maximize gadgets disabled flag
|
||||
int refreshRate; // Vertical monitor refresh rate
|
||||
|
||||
// Input
|
||||
GLboolean stickyKeys;
|
||||
GLboolean stickyMouseButtons;
|
||||
GLboolean keyRepeat;
|
||||
int mousePosX, mousePosY;
|
||||
int wheelPos;
|
||||
char mouseButton[GLFW_MOUSE_BUTTON_LAST + 1];
|
||||
char key[GLFW_KEY_LAST + 1];
|
||||
int lastChar;
|
||||
|
||||
// Window status & parameters
|
||||
GLboolean active; // Application active flag
|
||||
GLboolean iconified; // Window iconified flag
|
||||
int width, height; // Window width and heigth
|
||||
GLboolean accelerated; // GL_TRUE if window is HW accelerated
|
||||
|
||||
// Framebuffer attributes
|
||||
int redBits;
|
||||
int greenBits;
|
||||
int blueBits;
|
||||
int alphaBits;
|
||||
int depthBits;
|
||||
int stencilBits;
|
||||
int accumRedBits;
|
||||
int accumGreenBits;
|
||||
int accumBlueBits;
|
||||
int accumAlphaBits;
|
||||
int auxBuffers;
|
||||
GLboolean stereo;
|
||||
int samples;
|
||||
|
||||
// OpenGL extensions and context attributes
|
||||
int glMajor, glMinor, glRevision;
|
||||
int glForward, glDebug, glProfile;
|
||||
|
||||
PFNGLGETSTRINGIPROC GetStringi;
|
||||
|
||||
_GLFW_PLATFORM_WINDOW_STATE;
|
||||
} _GLFWwindow;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Library global data
|
||||
//------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
_GLFWhints hints;
|
||||
_GLFWwindow* window;
|
||||
_GLFWwindow* currentWindow;
|
||||
_GLFWwindow* cursorLockWindow;
|
||||
|
||||
_GLFW_PLATFORM_LIBRARY_STATE;
|
||||
} _GLFWlibrary;
|
||||
|
||||
|
||||
//========================================================================
|
||||
// System independent global variables (GLFW internals)
|
||||
//========================================================================
|
||||
@ -137,6 +212,8 @@ int _glfwInitialized = 0;
|
||||
GLFWGLOBAL int _glfwInitialized;
|
||||
#endif
|
||||
|
||||
GLFWGLOBAL _GLFWlibrary _glfwLibrary;
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Prototypes for platform specific implementation functions
|
||||
@ -147,17 +224,13 @@ int _glfwPlatformInit(void);
|
||||
int _glfwPlatformTerminate(void);
|
||||
|
||||
// Enable/Disable
|
||||
void _glfwPlatformEnableSystemKeys(void);
|
||||
void _glfwPlatformDisableSystemKeys(void);
|
||||
void _glfwPlatformEnableSystemKeys(_GLFWwindow* window);
|
||||
void _glfwPlatformDisableSystemKeys(_GLFWwindow* window);
|
||||
|
||||
// Fullscreen
|
||||
int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount);
|
||||
void _glfwPlatformGetDesktopMode(GLFWvidmode* mode);
|
||||
|
||||
// OpenGL extensions
|
||||
int _glfwPlatformExtensionSupported(const char* extension);
|
||||
void* _glfwPlatformGetProcAddress(const char* procname);
|
||||
|
||||
// Joystick
|
||||
int _glfwPlatformGetJoystickParam(int joy, int param);
|
||||
int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes);
|
||||
@ -168,21 +241,28 @@ double _glfwPlatformGetTime(void);
|
||||
void _glfwPlatformSetTime(double time);
|
||||
|
||||
// Window management
|
||||
int _glfwPlatformOpenWindow(int width, int height, const _GLFWwndconfig* wndconfig, const _GLFWfbconfig* fbconfig);
|
||||
void _glfwPlatformCloseWindow(void);
|
||||
void _glfwPlatformSetWindowTitle(const char* title);
|
||||
void _glfwPlatformSetWindowSize(int width, int height);
|
||||
void _glfwPlatformSetWindowPos(int x, int y);
|
||||
void _glfwPlatformIconifyWindow(void);
|
||||
void _glfwPlatformRestoreWindow(void);
|
||||
int _glfwPlatformOpenWindow(_GLFWwindow* window, int width, int height, const _GLFWwndconfig* wndconfig, const _GLFWfbconfig* fbconfig);
|
||||
int _glfwPlatformMakeWindowCurrent(_GLFWwindow* window);
|
||||
void _glfwPlatformCloseWindow(_GLFWwindow* window);
|
||||
void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title);
|
||||
void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height);
|
||||
void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y);
|
||||
void _glfwPlatformIconifyWindow(_GLFWwindow* window);
|
||||
void _glfwPlatformRestoreWindow(_GLFWwindow* window);
|
||||
void _glfwPlatformHideMouseCursor(_GLFWwindow* window);
|
||||
void _glfwPlatformShowMouseCursor(_GLFWwindow* window);
|
||||
void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y);
|
||||
|
||||
// Event management
|
||||
void _glfwPlatformPollEvents(void);
|
||||
void _glfwPlatformWaitEvents(void);
|
||||
|
||||
// OpenGL context management
|
||||
void _glfwPlatformSwapBuffers(void);
|
||||
void _glfwPlatformSwapInterval(int interval);
|
||||
void _glfwPlatformRefreshWindowParams(void);
|
||||
void _glfwPlatformPollEvents(void);
|
||||
void _glfwPlatformWaitEvents(void);
|
||||
void _glfwPlatformHideMouseCursor(void);
|
||||
void _glfwPlatformShowMouseCursor(void);
|
||||
void _glfwPlatformSetMouseCursorPos(int x, int y);
|
||||
int _glfwPlatformExtensionSupported(const char* extension);
|
||||
void* _glfwPlatformGetProcAddress(const char* procname);
|
||||
|
||||
|
||||
//========================================================================
|
||||
@ -193,11 +273,11 @@ void _glfwPlatformSetMouseCursorPos(int x, int y);
|
||||
void _glfwClearWindowHints(void);
|
||||
|
||||
// Input handling (window.c)
|
||||
void _glfwClearInput(void);
|
||||
void _glfwInputDeactivation(void);
|
||||
void _glfwInputKey(int key, int action);
|
||||
void _glfwInputChar(int character, int action);
|
||||
void _glfwInputMouseClick(int button, int action);
|
||||
void _glfwClearInput(_GLFWwindow* window);
|
||||
void _glfwInputDeactivation(_GLFWwindow* window);
|
||||
void _glfwInputKey(_GLFWwindow* window, int key, int action);
|
||||
void _glfwInputChar(_GLFWwindow* window, int character, int action);
|
||||
void _glfwInputMouseClick(_GLFWwindow* window, int button, int action);
|
||||
|
||||
// OpenGL extensions (glext.c)
|
||||
void _glfwParseGLVersion(int* major, int* minor, int* rev);
|
||||
|
377
lib/window.c
377
lib/window.c
@ -32,6 +32,7 @@
|
||||
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
//************************************************************************
|
||||
@ -58,22 +59,22 @@ void _glfwClearWindowHints(void)
|
||||
// Handle the input tracking part of window deactivation
|
||||
//========================================================================
|
||||
|
||||
void _glfwInputDeactivation(void)
|
||||
void _glfwInputDeactivation(_GLFWwindow* window)
|
||||
{
|
||||
int i;
|
||||
|
||||
// Release all keyboard keys
|
||||
for (i = 0; i <= GLFW_KEY_LAST; i++)
|
||||
{
|
||||
if(_glfwInput.Key[i] == GLFW_PRESS)
|
||||
_glfwInputKey(i, GLFW_RELEASE);
|
||||
if (window->key[i] == GLFW_PRESS)
|
||||
_glfwInputKey(window, i, GLFW_RELEASE);
|
||||
}
|
||||
|
||||
// Release all mouse buttons
|
||||
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
|
||||
{
|
||||
if (_glfwInput.MouseButton[i] == GLFW_PRESS)
|
||||
_glfwInputMouseClick(i, GLFW_RELEASE);
|
||||
if (window->mouseButton[i] == GLFW_PRESS)
|
||||
_glfwInputMouseClick(window, i, GLFW_RELEASE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,34 +83,34 @@ void _glfwInputDeactivation(void)
|
||||
// Clear all input state
|
||||
//========================================================================
|
||||
|
||||
void _glfwClearInput(void)
|
||||
void _glfwClearInput(_GLFWwindow* window)
|
||||
{
|
||||
int i;
|
||||
|
||||
// Release all keyboard keys
|
||||
for (i = 0; i <= GLFW_KEY_LAST; i++)
|
||||
_glfwInput.Key[i] = GLFW_RELEASE;
|
||||
window->key[i] = GLFW_RELEASE;
|
||||
|
||||
// Clear last character
|
||||
_glfwInput.LastChar = 0;
|
||||
window->lastChar = 0;
|
||||
|
||||
// Release all mouse buttons
|
||||
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
|
||||
_glfwInput.MouseButton[i] = GLFW_RELEASE;
|
||||
window->mouseButton[i] = GLFW_RELEASE;
|
||||
|
||||
// Set mouse position to (0,0)
|
||||
_glfwInput.MousePosX = 0;
|
||||
_glfwInput.MousePosY = 0;
|
||||
window->mousePosX = 0;
|
||||
window->mousePosY = 0;
|
||||
|
||||
// Set mouse wheel position to 0
|
||||
_glfwInput.WheelPos = 0;
|
||||
window->wheelPos = 0;
|
||||
|
||||
// The default is to use non sticky keys and mouse buttons
|
||||
_glfwInput.StickyKeys = GL_FALSE;
|
||||
_glfwInput.StickyMouseButtons = GL_FALSE;
|
||||
window->stickyKeys = GL_FALSE;
|
||||
window->stickyMouseButtons = GL_FALSE;
|
||||
|
||||
// The default is to disable key repeat
|
||||
_glfwInput.KeyRepeat = GL_FALSE;
|
||||
window->keyRepeat = GL_FALSE;
|
||||
}
|
||||
|
||||
|
||||
@ -117,30 +118,30 @@ void _glfwClearInput(void)
|
||||
// Register keyboard activity
|
||||
//========================================================================
|
||||
|
||||
void _glfwInputKey(int key, int action)
|
||||
void _glfwInputKey(_GLFWwindow* window, int key, int action)
|
||||
{
|
||||
int keyrepeat = 0;
|
||||
GLboolean keyrepeat = GL_FALSE;
|
||||
|
||||
if (key < 0 || key > GLFW_KEY_LAST)
|
||||
return;
|
||||
|
||||
// Are we trying to release an already released key?
|
||||
if (action == GLFW_RELEASE && _glfwInput.Key[key] != GLFW_PRESS)
|
||||
if (action == GLFW_RELEASE && window->key[key] != GLFW_PRESS)
|
||||
return;
|
||||
|
||||
// Register key action
|
||||
if(action == GLFW_RELEASE && _glfwInput.StickyKeys)
|
||||
_glfwInput.Key[key] = GLFW_STICK;
|
||||
if(action == GLFW_RELEASE && window->stickyKeys)
|
||||
window->key[key] = GLFW_STICK;
|
||||
else
|
||||
{
|
||||
keyrepeat = (_glfwInput.Key[key] == GLFW_PRESS) &&
|
||||
keyrepeat = (window->key[key] == GLFW_PRESS) &&
|
||||
(action == GLFW_PRESS);
|
||||
_glfwInput.Key[key] = (char) action;
|
||||
window->key[key] = (char) action;
|
||||
}
|
||||
|
||||
// Call user callback function
|
||||
if (_glfwWin.keyCallback && (_glfwInput.KeyRepeat || !keyrepeat) )
|
||||
_glfwWin.keyCallback(key, action);
|
||||
if (window->keyCallback && (window->keyRepeat || !keyrepeat) )
|
||||
window->keyCallback(key, action);
|
||||
}
|
||||
|
||||
|
||||
@ -148,7 +149,7 @@ void _glfwInputKey(int key, int action)
|
||||
// Register (keyboard) character activity
|
||||
//========================================================================
|
||||
|
||||
void _glfwInputChar(int character, int action)
|
||||
void _glfwInputChar(_GLFWwindow* window, int character, int action)
|
||||
{
|
||||
int keyrepeat = 0;
|
||||
|
||||
@ -157,14 +158,14 @@ void _glfwInputChar(int character, int action)
|
||||
return;
|
||||
|
||||
// Is this a key repeat?
|
||||
if (action == GLFW_PRESS && _glfwInput.LastChar == character)
|
||||
if (action == GLFW_PRESS && window->lastChar == character)
|
||||
keyrepeat = 1;
|
||||
|
||||
// Store this character as last character (or clear it, if released)
|
||||
if (action == GLFW_PRESS)
|
||||
_glfwInput.LastChar = character;
|
||||
window->lastChar = character;
|
||||
else
|
||||
_glfwInput.LastChar = 0;
|
||||
window->lastChar = 0;
|
||||
|
||||
if (action != GLFW_PRESS)
|
||||
{
|
||||
@ -184,8 +185,8 @@ void _glfwInputChar(int character, int action)
|
||||
return;
|
||||
}
|
||||
|
||||
if (_glfwWin.charCallback && (_glfwInput.KeyRepeat || !keyrepeat))
|
||||
_glfwWin.charCallback(character, action);
|
||||
if (window->charCallback && (window->keyRepeat || !keyrepeat))
|
||||
window->charCallback(character, action);
|
||||
}
|
||||
|
||||
|
||||
@ -193,20 +194,19 @@ void _glfwInputChar(int character, int action)
|
||||
// Register mouse button clicks
|
||||
//========================================================================
|
||||
|
||||
void _glfwInputMouseClick(int button, int action)
|
||||
void _glfwInputMouseClick(_GLFWwindow* window, int button, int action)
|
||||
{
|
||||
if (button >= 0 && button <= GLFW_MOUSE_BUTTON_LAST)
|
||||
{
|
||||
// Register mouse button action
|
||||
if (action == GLFW_RELEASE && _glfwInput.StickyMouseButtons)
|
||||
_glfwInput.MouseButton[button] = GLFW_STICK;
|
||||
else
|
||||
_glfwInput.MouseButton[button] = (char) action;
|
||||
if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST)
|
||||
return;
|
||||
|
||||
// Call user callback function
|
||||
if (_glfwWin.mouseButtonCallback)
|
||||
_glfwWin.mouseButtonCallback(button, action);
|
||||
}
|
||||
// Register mouse button action
|
||||
if (action == GLFW_RELEASE && window->stickyMouseButtons)
|
||||
window->mouseButton[button] = GLFW_STICK;
|
||||
else
|
||||
window->mouseButton[button] = (char) action;
|
||||
|
||||
if (window->mouseButtonCallback)
|
||||
window->mouseButtonCallback(button, action);
|
||||
}
|
||||
|
||||
|
||||
@ -393,16 +393,25 @@ const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired,
|
||||
// Create the GLFW window and its associated context
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI int glfwOpenWindow(int width, int height,
|
||||
int redbits, int greenbits, int bluebits,
|
||||
int alphabits, int depthbits, int stencilbits,
|
||||
int mode)
|
||||
GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
|
||||
int redbits, int greenbits, int bluebits,
|
||||
int alphabits, int depthbits, int stencilbits,
|
||||
int mode)
|
||||
{
|
||||
_GLFWfbconfig fbconfig;
|
||||
_GLFWwndconfig wndconfig;
|
||||
_GLFWwindow* window;
|
||||
|
||||
if (!_glfwInitialized || _glfwWin.opened)
|
||||
return GL_FALSE;
|
||||
if (!_glfwInitialized || _glfwLibrary.window)
|
||||
return NULL;
|
||||
|
||||
window = (_GLFWwindow*) malloc(sizeof(_GLFWwindow));
|
||||
if (!window)
|
||||
return NULL;
|
||||
|
||||
_glfwLibrary.window = window;
|
||||
|
||||
memset(window, 0, sizeof(_GLFWwindow));
|
||||
|
||||
// Set up desired framebuffer config
|
||||
fbconfig.redBits = Max(redbits, 0);
|
||||
@ -429,19 +438,25 @@ GLFWAPI int glfwOpenWindow(int width, int height,
|
||||
wndconfig.glDebug = _glfwLibrary.hints.glDebug ? GL_TRUE : GL_FALSE;
|
||||
wndconfig.glProfile = _glfwLibrary.hints.glProfile;
|
||||
|
||||
// Clear for next open call
|
||||
_glfwClearWindowHints();
|
||||
|
||||
if (wndconfig.glMajor == 1 && wndconfig.glMinor > 5)
|
||||
{
|
||||
// OpenGL 1.x series ended with version 1.5
|
||||
glfwCloseWindow(window);
|
||||
return GL_FALSE;
|
||||
}
|
||||
else if (wndconfig.glMajor == 2 && wndconfig.glMinor > 1)
|
||||
{
|
||||
// OpenGL 2.x series ended with version 2.1
|
||||
glfwCloseWindow(window);
|
||||
return GL_FALSE;
|
||||
}
|
||||
else if (wndconfig.glMajor == 3 && wndconfig.glMinor > 3)
|
||||
{
|
||||
// OpenGL 3.x series ended with version 3.3
|
||||
glfwCloseWindow(window);
|
||||
return GL_FALSE;
|
||||
}
|
||||
else
|
||||
@ -453,37 +468,26 @@ GLFWAPI int glfwOpenWindow(int width, int height,
|
||||
(wndconfig.glMajor < 3 || (wndconfig.glMajor == 3 && wndconfig.glMinor < 2)))
|
||||
{
|
||||
// Context profiles are only defined for OpenGL version 3.2 and above
|
||||
glfwCloseWindow(window);
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
if (wndconfig.glForward && wndconfig.glMajor < 3)
|
||||
{
|
||||
// Forward-compatible contexts are only defined for OpenGL version 3.0 and above
|
||||
glfwCloseWindow(window);
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
// Clear for next open call
|
||||
_glfwClearWindowHints();
|
||||
|
||||
// Check input arguments
|
||||
if (mode != GLFW_WINDOW && mode != GLFW_FULLSCREEN)
|
||||
{
|
||||
// Invalid window mode
|
||||
glfwCloseWindow(window);
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
// Clear GLFW window state
|
||||
_glfwWin.active = GL_TRUE;
|
||||
_glfwWin.iconified = GL_FALSE;
|
||||
_glfwWin.mouseLock = GL_FALSE;
|
||||
_glfwClearInput();
|
||||
|
||||
// Unregister all callback functions
|
||||
_glfwWin.windowSizeCallback = NULL;
|
||||
_glfwWin.windowCloseCallback = NULL;
|
||||
_glfwWin.windowRefreshCallback = NULL;
|
||||
_glfwWin.keyCallback = NULL;
|
||||
_glfwWin.charCallback = NULL;
|
||||
_glfwWin.mousePosCallback = NULL;
|
||||
_glfwWin.mouseButtonCallback = NULL;
|
||||
_glfwWin.mouseWheelCallback = NULL;
|
||||
_glfwClearInput(window);
|
||||
|
||||
// Check width & height
|
||||
if (width > 0 && height <= 0)
|
||||
@ -504,52 +508,68 @@ GLFWAPI int glfwOpenWindow(int width, int height,
|
||||
}
|
||||
|
||||
// Remember window settings
|
||||
_glfwWin.width = width;
|
||||
_glfwWin.height = height;
|
||||
_glfwWin.fullscreen = (mode == GLFW_FULLSCREEN ? GL_TRUE : GL_FALSE);
|
||||
window->width = width;
|
||||
window->height = height;
|
||||
window->mode = mode;
|
||||
|
||||
// Platform specific window opening routine
|
||||
if (!_glfwPlatformOpenWindow(width, height, &wndconfig, &fbconfig))
|
||||
return GL_FALSE;
|
||||
|
||||
// Flag that window is now opened
|
||||
_glfwWin.opened = GL_TRUE;
|
||||
|
||||
// Get window parameters (such as color buffer bits etc)
|
||||
_glfwPlatformRefreshWindowParams();
|
||||
|
||||
// Get OpenGL version
|
||||
_glfwParseGLVersion(&_glfwWin.glMajor, &_glfwWin.glMinor,
|
||||
&_glfwWin.glRevision);
|
||||
|
||||
if (_glfwWin.glMajor < wndconfig.glMajor ||
|
||||
(_glfwWin.glMajor == wndconfig.glMajor &&
|
||||
_glfwWin.glMinor < wndconfig.glMinor))
|
||||
if (!_glfwPlatformOpenWindow(window, width, height, &wndconfig, &fbconfig))
|
||||
{
|
||||
_glfwPlatformCloseWindow();
|
||||
glfwCloseWindow(window);
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
if (_glfwWin.glMajor > 2)
|
||||
// Get window parameters (such as color buffer bits etc)
|
||||
glfwMakeWindowCurrent(window);
|
||||
_glfwPlatformRefreshWindowParams();
|
||||
|
||||
// Get OpenGL version
|
||||
_glfwParseGLVersion(&window->glMajor, &window->glMinor, &window->glRevision);
|
||||
|
||||
if (window->glMajor < wndconfig.glMajor ||
|
||||
(window->glMajor == wndconfig.glMajor &&
|
||||
window->glMinor < wndconfig.glMinor))
|
||||
{
|
||||
_glfwWin.GetStringi = (PFNGLGETSTRINGIPROC) glfwGetProcAddress("glGetStringi");
|
||||
if (!_glfwWin.GetStringi)
|
||||
// The desired OpenGL version is greater than the actual version
|
||||
// This only happens if the machine lacks {GLX|WGL}_ARB_create_context
|
||||
glfwCloseWindow(window);
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
if (window->glMajor > 2)
|
||||
{
|
||||
window->GetStringi = (PFNGLGETSTRINGIPROC) glfwGetProcAddress("glGetStringi");
|
||||
if (!window->GetStringi)
|
||||
{
|
||||
_glfwPlatformCloseWindow();
|
||||
glfwCloseWindow(window);
|
||||
return GL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// If full-screen mode was requested, disable mouse cursor
|
||||
if (mode == GLFW_FULLSCREEN)
|
||||
glfwDisable(GLFW_MOUSE_CURSOR);
|
||||
glfwDisable(window, GLFW_MOUSE_CURSOR);
|
||||
|
||||
// Start by clearing the front buffer to black (avoid ugly desktop
|
||||
// remains in our OpenGL window)
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
_glfwPlatformSwapBuffers();
|
||||
|
||||
return GL_TRUE;
|
||||
return window;
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Make the OpenGL context associated with the specified window current
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwMakeWindowCurrent(GLFWwindow window)
|
||||
{
|
||||
if (_glfwLibrary.currentWindow == window)
|
||||
return;
|
||||
|
||||
_glfwPlatformMakeWindowCurrent(window);
|
||||
_glfwLibrary.currentWindow = window;
|
||||
}
|
||||
|
||||
|
||||
@ -616,18 +636,24 @@ GLFWAPI void glfwOpenWindowHint(int target, int hint)
|
||||
// Properly kill the window / video display
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwCloseWindow(void)
|
||||
GLFWAPI void glfwCloseWindow(GLFWwindow window)
|
||||
{
|
||||
if (!_glfwInitialized)
|
||||
return;
|
||||
|
||||
// Show mouse pointer again (if hidden)
|
||||
glfwEnable(GLFW_MOUSE_CURSOR);
|
||||
if (window == _glfwLibrary.cursorLockWindow)
|
||||
glfwEnable(window, GLFW_MOUSE_CURSOR);
|
||||
|
||||
_glfwPlatformCloseWindow();
|
||||
if (window == _glfwLibrary.currentWindow)
|
||||
glfwMakeWindowCurrent(NULL);
|
||||
|
||||
memset(&_glfwWin, 0, sizeof(_glfwWin));
|
||||
_glfwWin.opened = GL_FALSE;
|
||||
_glfwPlatformCloseWindow(window);
|
||||
|
||||
free(window);
|
||||
|
||||
// Yuck
|
||||
_glfwLibrary.window = NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -635,13 +661,12 @@ GLFWAPI void glfwCloseWindow(void)
|
||||
// Set the window title
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetWindowTitle(const char* title)
|
||||
GLFWAPI void glfwSetWindowTitle(GLFWwindow window, const char* title)
|
||||
{
|
||||
if (!_glfwInitialized || !_glfwWin.opened)
|
||||
if (!_glfwInitialized)
|
||||
return;
|
||||
|
||||
// Set window title
|
||||
_glfwPlatformSetWindowTitle(title);
|
||||
_glfwPlatformSetWindowTitle(window, title);
|
||||
}
|
||||
|
||||
|
||||
@ -649,13 +674,16 @@ GLFWAPI void glfwSetWindowTitle(const char* title)
|
||||
// Get the window size
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwGetWindowSize(int* width, int* height)
|
||||
GLFWAPI void glfwGetWindowSize(GLFWwindow window, int* width, int* height)
|
||||
{
|
||||
if (!_glfwInitialized)
|
||||
return;
|
||||
|
||||
if (width != NULL)
|
||||
*width = _glfwWin.width;
|
||||
*width = window->width;
|
||||
|
||||
if (height != NULL)
|
||||
*height = _glfwWin.height;
|
||||
*height = window->height;
|
||||
}
|
||||
|
||||
|
||||
@ -663,21 +691,23 @@ GLFWAPI void glfwGetWindowSize(int* width, int* height)
|
||||
// Set the window size
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetWindowSize(int width, int height)
|
||||
GLFWAPI void glfwSetWindowSize(GLFWwindow window, int width, int height)
|
||||
{
|
||||
if (!_glfwInitialized || !_glfwWin.opened || _glfwWin.iconified)
|
||||
if (!_glfwInitialized || window->iconified)
|
||||
return;
|
||||
|
||||
// Don't do anything if the window size did not change
|
||||
if (width == _glfwWin.width && height == _glfwWin.height)
|
||||
if (width == window->width && height == window->height)
|
||||
return;
|
||||
|
||||
// Change window size
|
||||
_glfwPlatformSetWindowSize(width, height);
|
||||
_glfwPlatformSetWindowSize(window, width, height);
|
||||
|
||||
// Refresh window parameters (may have changed due to changed video
|
||||
// modes)
|
||||
_glfwPlatformRefreshWindowParams();
|
||||
if (window->mode == GLFW_FULLSCREEN)
|
||||
{
|
||||
// Refresh window parameters (may have changed due to changed video
|
||||
// modes)
|
||||
_glfwPlatformRefreshWindowParams();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -685,16 +715,14 @@ GLFWAPI void glfwSetWindowSize(int width, int height)
|
||||
// Set the window position
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetWindowPos(int x, int y)
|
||||
GLFWAPI void glfwSetWindowPos(GLFWwindow window, int x, int y)
|
||||
{
|
||||
if (!_glfwInitialized || !_glfwWin.opened || _glfwWin.fullscreen ||
|
||||
_glfwWin.iconified)
|
||||
if (!_glfwInitialized || window->mode == GLFW_FULLSCREEN || window->iconified)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Set window position
|
||||
_glfwPlatformSetWindowPos(x, y);
|
||||
_glfwPlatformSetWindowPos(window, x, y);
|
||||
}
|
||||
|
||||
|
||||
@ -702,13 +730,12 @@ GLFWAPI void glfwSetWindowPos(int x, int y)
|
||||
// Window iconification
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwIconifyWindow(void)
|
||||
GLFWAPI void glfwIconifyWindow(GLFWwindow window)
|
||||
{
|
||||
if (!_glfwInitialized || !_glfwWin.opened || _glfwWin.iconified)
|
||||
if (!_glfwInitialized || window->iconified)
|
||||
return;
|
||||
|
||||
// Iconify window
|
||||
_glfwPlatformIconifyWindow();
|
||||
_glfwPlatformIconifyWindow(window);
|
||||
}
|
||||
|
||||
|
||||
@ -716,30 +743,29 @@ GLFWAPI void glfwIconifyWindow(void)
|
||||
// Window un-iconification
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwRestoreWindow(void)
|
||||
GLFWAPI void glfwRestoreWindow(GLFWwindow window)
|
||||
{
|
||||
if (!_glfwInitialized || !_glfwWin.opened || !_glfwWin.iconified)
|
||||
if (!_glfwInitialized || !window->iconified)
|
||||
return;
|
||||
|
||||
// Restore iconified window
|
||||
_glfwPlatformRestoreWindow();
|
||||
_glfwPlatformRestoreWindow(window);
|
||||
|
||||
// Refresh window parameters
|
||||
_glfwPlatformRefreshWindowParams();
|
||||
if (window->mode == GLFW_FULLSCREEN)
|
||||
_glfwPlatformRefreshWindowParams();
|
||||
}
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Swap buffers (double-buffering) and poll any new events
|
||||
// Swap buffers (double-buffering)
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSwapBuffers(void)
|
||||
{
|
||||
if (!_glfwInitialized || !_glfwWin.opened)
|
||||
if (!_glfwInitialized)
|
||||
return;
|
||||
|
||||
// Update display-buffer
|
||||
if (_glfwWin.opened)
|
||||
if (_glfwLibrary.currentWindow)
|
||||
_glfwPlatformSwapBuffers();
|
||||
}
|
||||
|
||||
@ -750,10 +776,9 @@ GLFWAPI void glfwSwapBuffers(void)
|
||||
|
||||
GLFWAPI void glfwSwapInterval(int interval)
|
||||
{
|
||||
if (!_glfwInitialized || !_glfwWin.opened)
|
||||
if (!_glfwInitialized)
|
||||
return;
|
||||
|
||||
// Set double buffering swap interval
|
||||
_glfwPlatformSwapInterval(interval);
|
||||
}
|
||||
|
||||
@ -762,70 +787,59 @@ GLFWAPI void glfwSwapInterval(int interval)
|
||||
// Get window parameter
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI int glfwGetWindowParam(int param)
|
||||
GLFWAPI int glfwGetWindowParam(GLFWwindow window, int param)
|
||||
{
|
||||
if (!_glfwInitialized)
|
||||
return 0;
|
||||
|
||||
if (!_glfwWin.opened)
|
||||
{
|
||||
if (param == GLFW_OPENED)
|
||||
return GL_FALSE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Window parameters
|
||||
switch (param)
|
||||
{
|
||||
case GLFW_OPENED:
|
||||
return GL_TRUE;
|
||||
case GLFW_ACTIVE:
|
||||
return _glfwWin.active;
|
||||
return window->active;
|
||||
case GLFW_ICONIFIED:
|
||||
return _glfwWin.iconified;
|
||||
return window->iconified;
|
||||
case GLFW_ACCELERATED:
|
||||
return _glfwWin.accelerated;
|
||||
return window->accelerated;
|
||||
case GLFW_RED_BITS:
|
||||
return _glfwWin.redBits;
|
||||
return window->redBits;
|
||||
case GLFW_GREEN_BITS:
|
||||
return _glfwWin.greenBits;
|
||||
return window->greenBits;
|
||||
case GLFW_BLUE_BITS:
|
||||
return _glfwWin.blueBits;
|
||||
return window->blueBits;
|
||||
case GLFW_ALPHA_BITS:
|
||||
return _glfwWin.alphaBits;
|
||||
return window->alphaBits;
|
||||
case GLFW_DEPTH_BITS:
|
||||
return _glfwWin.depthBits;
|
||||
return window->depthBits;
|
||||
case GLFW_STENCIL_BITS:
|
||||
return _glfwWin.stencilBits;
|
||||
return window->stencilBits;
|
||||
case GLFW_ACCUM_RED_BITS:
|
||||
return _glfwWin.accumRedBits;
|
||||
return window->accumRedBits;
|
||||
case GLFW_ACCUM_GREEN_BITS:
|
||||
return _glfwWin.accumGreenBits;
|
||||
return window->accumGreenBits;
|
||||
case GLFW_ACCUM_BLUE_BITS:
|
||||
return _glfwWin.accumBlueBits;
|
||||
return window->accumBlueBits;
|
||||
case GLFW_ACCUM_ALPHA_BITS:
|
||||
return _glfwWin.accumAlphaBits;
|
||||
return window->accumAlphaBits;
|
||||
case GLFW_AUX_BUFFERS:
|
||||
return _glfwWin.auxBuffers;
|
||||
return window->auxBuffers;
|
||||
case GLFW_STEREO:
|
||||
return _glfwWin.stereo;
|
||||
return window->stereo;
|
||||
case GLFW_REFRESH_RATE:
|
||||
return _glfwWin.refreshRate;
|
||||
return window->refreshRate;
|
||||
case GLFW_WINDOW_NO_RESIZE:
|
||||
return _glfwWin.windowNoResize;
|
||||
return window->windowNoResize;
|
||||
case GLFW_FSAA_SAMPLES:
|
||||
return _glfwWin.samples;
|
||||
return window->samples;
|
||||
case GLFW_OPENGL_VERSION_MAJOR:
|
||||
return _glfwWin.glMajor;
|
||||
return window->glMajor;
|
||||
case GLFW_OPENGL_VERSION_MINOR:
|
||||
return _glfwWin.glMinor;
|
||||
return window->glMinor;
|
||||
case GLFW_OPENGL_FORWARD_COMPAT:
|
||||
return _glfwWin.glForward;
|
||||
return window->glForward;
|
||||
case GLFW_OPENGL_DEBUG_CONTEXT:
|
||||
return _glfwWin.glDebug;
|
||||
return window->glDebug;
|
||||
case GLFW_OPENGL_PROFILE:
|
||||
return _glfwWin.glProfile;
|
||||
return window->glProfile;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@ -836,31 +850,29 @@ GLFWAPI int glfwGetWindowParam(int param)
|
||||
// Set callback function for window size changes
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetWindowSizeCallback(GLFWwindowsizefun cbfun)
|
||||
GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow window, GLFWwindowsizefun cbfun)
|
||||
{
|
||||
if (!_glfwInitialized || !_glfwWin.opened)
|
||||
if (!_glfwInitialized)
|
||||
return;
|
||||
|
||||
// Set callback function
|
||||
_glfwWin.windowSizeCallback = cbfun;
|
||||
window->windowSizeCallback = cbfun;
|
||||
|
||||
// Call the callback function to let the application know the current
|
||||
// window size
|
||||
if (cbfun)
|
||||
cbfun(_glfwWin.width, _glfwWin.height);
|
||||
cbfun(window->width, window->height);
|
||||
}
|
||||
|
||||
//========================================================================
|
||||
// Set callback function for window close events
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetWindowCloseCallback(GLFWwindowclosefun cbfun)
|
||||
GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow window, GLFWwindowclosefun cbfun)
|
||||
{
|
||||
if (!_glfwInitialized || !_glfwWin.opened)
|
||||
if (!_glfwInitialized)
|
||||
return;
|
||||
|
||||
// Set callback function
|
||||
_glfwWin.windowCloseCallback = cbfun;
|
||||
window->windowCloseCallback = cbfun;
|
||||
}
|
||||
|
||||
|
||||
@ -868,13 +880,12 @@ GLFWAPI void glfwSetWindowCloseCallback(GLFWwindowclosefun cbfun)
|
||||
// Set callback function for window refresh events
|
||||
//========================================================================
|
||||
|
||||
GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindowrefreshfun cbfun)
|
||||
GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow window, GLFWwindowrefreshfun cbfun)
|
||||
{
|
||||
if (!_glfwInitialized || !_glfwWin.opened)
|
||||
if (!_glfwInitialized)
|
||||
return;
|
||||
|
||||
// Set callback function
|
||||
_glfwWin.windowRefreshCallback = cbfun;
|
||||
window->windowRefreshCallback = cbfun;
|
||||
}
|
||||
|
||||
|
||||
@ -884,10 +895,9 @@ GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindowrefreshfun cbfun)
|
||||
|
||||
GLFWAPI void glfwPollEvents(void)
|
||||
{
|
||||
if (!_glfwInitialized || !_glfwWin.opened)
|
||||
if (!_glfwInitialized)
|
||||
return;
|
||||
|
||||
// Poll for new events
|
||||
_glfwPlatformPollEvents();
|
||||
}
|
||||
|
||||
@ -898,10 +908,9 @@ GLFWAPI void glfwPollEvents(void)
|
||||
|
||||
GLFWAPI void glfwWaitEvents(void)
|
||||
{
|
||||
if (!_glfwInitialized || !_glfwWin.opened)
|
||||
if (!_glfwInitialized)
|
||||
return;
|
||||
|
||||
// Poll for new events
|
||||
_glfwPlatformWaitEvents();
|
||||
}
|
||||
|
||||
|
@ -161,6 +161,10 @@ typedef const GLubyte* (APIENTRY *PFNGLGETSTRINGIPROC)(GLenum, GLuint);
|
||||
#endif /*GL_VERSION_3_0*/
|
||||
|
||||
|
||||
#define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowX11 X11
|
||||
#define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryX11 X11
|
||||
|
||||
|
||||
|
||||
//========================================================================
|
||||
// Global variables (GLFW internals)
|
||||
@ -169,59 +173,7 @@ typedef const GLubyte* (APIENTRY *PFNGLGETSTRINGIPROC)(GLenum, GLuint);
|
||||
//------------------------------------------------------------------------
|
||||
// Window structure
|
||||
//------------------------------------------------------------------------
|
||||
typedef struct _GLFWwin_struct _GLFWwin;
|
||||
|
||||
struct _GLFWwin_struct {
|
||||
|
||||
// ========= PLATFORM INDEPENDENT MANDATORY PART =========================
|
||||
|
||||
// User callback functions
|
||||
GLFWwindowsizefun windowSizeCallback;
|
||||
GLFWwindowclosefun windowCloseCallback;
|
||||
GLFWwindowrefreshfun windowRefreshCallback;
|
||||
GLFWmousebuttonfun mouseButtonCallback;
|
||||
GLFWmouseposfun mousePosCallback;
|
||||
GLFWmousewheelfun mouseWheelCallback;
|
||||
GLFWkeyfun keyCallback;
|
||||
GLFWcharfun charCallback;
|
||||
|
||||
// User selected window settings
|
||||
int fullscreen; // Fullscreen flag
|
||||
int mouseLock; // Mouse-lock flag
|
||||
int sysKeysDisabled; // System keys disabled flag
|
||||
int windowNoResize; // Resize- and maximize gadgets disabled flag
|
||||
int refreshRate; // Vertical monitor refresh rate
|
||||
|
||||
// Window status & parameters
|
||||
int opened; // Flag telling if window is opened or not
|
||||
int active; // Application active flag
|
||||
int iconified; // Window iconified flag
|
||||
int width, height; // Window width and heigth
|
||||
int accelerated; // GL_TRUE if window is HW accelerated
|
||||
|
||||
// Framebuffer attributes
|
||||
int redBits;
|
||||
int greenBits;
|
||||
int blueBits;
|
||||
int alphaBits;
|
||||
int depthBits;
|
||||
int stencilBits;
|
||||
int accumRedBits;
|
||||
int accumGreenBits;
|
||||
int accumBlueBits;
|
||||
int accumAlphaBits;
|
||||
int auxBuffers;
|
||||
int stereo;
|
||||
int samples;
|
||||
|
||||
// OpenGL extensions and context attributes
|
||||
int glMajor, glMinor, glRevision;
|
||||
int glForward, glDebug, glProfile;
|
||||
|
||||
PFNGLGETSTRINGIPROC GetStringi;
|
||||
|
||||
|
||||
// ========= PLATFORM SPECIFIC PART ======================================
|
||||
typedef struct _GLFWwindowX11 {
|
||||
|
||||
// Platform specific window resources
|
||||
Colormap colormap; // Window colormap
|
||||
@ -238,6 +190,8 @@ struct _GLFWwin_struct {
|
||||
Atom wmActiveWindow; // _NET_ACTIVE_WINDOW atom
|
||||
Cursor cursor; // Invisible cursor for hidden cursor
|
||||
|
||||
int mouseMoved, cursorPosX, cursorPosY;
|
||||
|
||||
// GLX extensions
|
||||
PFNGLXSWAPINTERVALSGIPROC SwapIntervalSGI;
|
||||
PFNGLXGETFBCONFIGATTRIBSGIXPROC GetFBConfigAttribSGIX;
|
||||
@ -258,6 +212,30 @@ struct _GLFWwin_struct {
|
||||
GLboolean pointerGrabbed; // True if pointer is currently grabbed
|
||||
GLboolean pointerHidden; // True if pointer is currently hidden
|
||||
|
||||
} _GLFWwindowX11;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Platform-specific ibrary global data
|
||||
//------------------------------------------------------------------------
|
||||
typedef struct {
|
||||
Display* display;
|
||||
|
||||
// Server-side GLX version
|
||||
int glxMajor, glxMinor;
|
||||
|
||||
struct {
|
||||
int available;
|
||||
int eventBase;
|
||||
int errorBase;
|
||||
} XF86VidMode;
|
||||
|
||||
struct {
|
||||
int available;
|
||||
int eventBase;
|
||||
int errorBase;
|
||||
} XRandR;
|
||||
|
||||
// Screensaver data
|
||||
struct {
|
||||
int changed;
|
||||
@ -280,69 +258,6 @@ struct _GLFWwin_struct {
|
||||
Rotation oldRotation;
|
||||
#endif
|
||||
} FS;
|
||||
};
|
||||
|
||||
GLFWGLOBAL _GLFWwin _glfwWin;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// User input status (most of this should go in _GLFWwin)
|
||||
//------------------------------------------------------------------------
|
||||
GLFWGLOBAL struct {
|
||||
|
||||
// ========= PLATFORM INDEPENDENT MANDATORY PART =========================
|
||||
|
||||
// Mouse status
|
||||
int MousePosX, MousePosY;
|
||||
int WheelPos;
|
||||
char MouseButton[ GLFW_MOUSE_BUTTON_LAST+1 ];
|
||||
|
||||
// Keyboard status
|
||||
char Key[ GLFW_KEY_LAST+1 ];
|
||||
int LastChar;
|
||||
|
||||
// User selected settings
|
||||
int StickyKeys;
|
||||
int StickyMouseButtons;
|
||||
int KeyRepeat;
|
||||
|
||||
|
||||
// ========= PLATFORM SPECIFIC PART ======================================
|
||||
|
||||
// Platform specific internal variables
|
||||
int MouseMoved, CursorPosX, CursorPosY;
|
||||
|
||||
} _glfwInput;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Library global data
|
||||
//------------------------------------------------------------------------
|
||||
GLFWGLOBAL struct {
|
||||
|
||||
// ========= PLATFORM INDEPENDENT MANDATORY PART =========================
|
||||
|
||||
// Window opening hints
|
||||
_GLFWhints hints;
|
||||
|
||||
// ========= PLATFORM SPECIFIC PART ======================================
|
||||
|
||||
Display* display;
|
||||
|
||||
// Server-side GLX version
|
||||
int glxMajor, glxMinor;
|
||||
|
||||
struct {
|
||||
int available;
|
||||
int eventBase;
|
||||
int errorBase;
|
||||
} XF86VidMode;
|
||||
|
||||
struct {
|
||||
int available;
|
||||
int eventBase;
|
||||
int errorBase;
|
||||
} XRandR;
|
||||
|
||||
// Timer data
|
||||
struct {
|
||||
@ -355,7 +270,7 @@ GLFWGLOBAL struct {
|
||||
void* libGL; // dlopen handle for libGL.so
|
||||
} Libs;
|
||||
#endif
|
||||
} _glfwLibrary;
|
||||
} _GLFWlibraryX11;
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
@ -382,7 +297,7 @@ void _glfwInitTimer(void);
|
||||
int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate);
|
||||
void _glfwSetVideoModeMODE(int screen, int mode, int rate);
|
||||
void _glfwSetVideoMode(int screen, int* width, int* height, int* rate);
|
||||
void _glfwRestoreVideoMode(void);
|
||||
void _glfwRestoreVideoMode(int screen);
|
||||
|
||||
// Joystick input
|
||||
void _glfwInitJoysticks(void);
|
||||
|
@ -39,12 +39,12 @@
|
||||
// Enable system keys
|
||||
//========================================================================
|
||||
|
||||
void _glfwPlatformEnableSystemKeys(void)
|
||||
void _glfwPlatformEnableSystemKeys(_GLFWwindow* window)
|
||||
{
|
||||
if (_glfwWin.keyboardGrabbed)
|
||||
if (window->X11.keyboardGrabbed)
|
||||
{
|
||||
XUngrabKeyboard(_glfwLibrary.display, CurrentTime);
|
||||
_glfwWin.keyboardGrabbed = GL_FALSE;
|
||||
XUngrabKeyboard(_glfwLibrary.X11.display, CurrentTime);
|
||||
window->X11.keyboardGrabbed = GL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,13 +52,13 @@ void _glfwPlatformEnableSystemKeys(void)
|
||||
// Disable system keys
|
||||
//========================================================================
|
||||
|
||||
void _glfwPlatformDisableSystemKeys(void)
|
||||
void _glfwPlatformDisableSystemKeys(_GLFWwindow* window)
|
||||
{
|
||||
if (XGrabKeyboard(_glfwLibrary.display, _glfwWin.window,
|
||||
if (XGrabKeyboard(_glfwLibrary.X11.display, window->X11.window,
|
||||
True, GrabModeAsync, GrabModeAsync, CurrentTime)
|
||||
== GrabSuccess)
|
||||
{
|
||||
_glfwWin.keyboardGrabbed = GL_TRUE;
|
||||
window->X11.keyboardGrabbed = GL_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,10 +75,10 @@ int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate)
|
||||
XRRScreenConfiguration* sc;
|
||||
XRRScreenSize* sizelist;
|
||||
|
||||
if (_glfwLibrary.XRandR.available)
|
||||
if (_glfwLibrary.X11.XRandR.available)
|
||||
{
|
||||
sc = XRRGetScreenInfo(_glfwLibrary.display,
|
||||
RootWindow(_glfwLibrary.display, screen));
|
||||
sc = XRRGetScreenInfo(_glfwLibrary.X11.display,
|
||||
RootWindow(_glfwLibrary.X11.display, screen));
|
||||
|
||||
sizelist = XRRConfigSizes(sc, &sizecount);
|
||||
|
||||
@ -174,8 +174,8 @@ int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate)
|
||||
#endif
|
||||
|
||||
// Default: Simply use the screen resolution
|
||||
*width = DisplayWidth(_glfwLibrary.display, screen);
|
||||
*height = DisplayHeight(_glfwLibrary.display, screen);
|
||||
*width = DisplayWidth(_glfwLibrary.X11.display, screen);
|
||||
*height = DisplayHeight(_glfwLibrary.X11.display, screen);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -191,25 +191,25 @@ void _glfwSetVideoModeMODE(int screen, int mode, int rate)
|
||||
XRRScreenConfiguration* sc;
|
||||
Window root;
|
||||
|
||||
if (_glfwLibrary.XRandR.available)
|
||||
if (_glfwLibrary.X11.XRandR.available)
|
||||
{
|
||||
root = RootWindow(_glfwLibrary.display, screen);
|
||||
sc = XRRGetScreenInfo(_glfwLibrary.display, root);
|
||||
root = RootWindow(_glfwLibrary.X11.display, screen);
|
||||
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, root);
|
||||
|
||||
// Remember old size and flag that we have changed the mode
|
||||
if (!_glfwWin.FS.modeChanged)
|
||||
if (!_glfwLibrary.X11.FS.modeChanged)
|
||||
{
|
||||
_glfwWin.FS.oldSizeID = XRRConfigCurrentConfiguration(sc, &_glfwWin.FS.oldRotation);
|
||||
_glfwWin.FS.oldWidth = DisplayWidth(_glfwLibrary.display, screen);
|
||||
_glfwWin.FS.oldHeight = DisplayHeight(_glfwLibrary.display, screen);
|
||||
_glfwLibrary.X11.FS.oldSizeID = XRRConfigCurrentConfiguration(sc, &_glfwLibrary.X11.FS.oldRotation);
|
||||
_glfwLibrary.X11.FS.oldWidth = DisplayWidth(_glfwLibrary.X11.display, screen);
|
||||
_glfwLibrary.X11.FS.oldHeight = DisplayHeight(_glfwLibrary.X11.display, screen);
|
||||
|
||||
_glfwWin.FS.modeChanged = GL_TRUE;
|
||||
_glfwLibrary.X11.FS.modeChanged = GL_TRUE;
|
||||
}
|
||||
|
||||
if (rate > 0)
|
||||
{
|
||||
// Set desired configuration
|
||||
XRRSetScreenConfigAndRate(_glfwLibrary.display,
|
||||
XRRSetScreenConfigAndRate(_glfwLibrary.X11.display,
|
||||
sc,
|
||||
root,
|
||||
mode,
|
||||
@ -220,7 +220,7 @@ void _glfwSetVideoModeMODE(int screen, int mode, int rate)
|
||||
else
|
||||
{
|
||||
// Set desired configuration
|
||||
XRRSetScreenConfig(_glfwLibrary.display,
|
||||
XRRSetScreenConfig(_glfwLibrary.X11.display,
|
||||
sc,
|
||||
root,
|
||||
mode,
|
||||
@ -235,31 +235,31 @@ void _glfwSetVideoModeMODE(int screen, int mode, int rate)
|
||||
int modecount;
|
||||
|
||||
// Use the XF86VidMode extension to control video resolution
|
||||
if (_glfwLibrary.XF86VidMode.available)
|
||||
if (_glfwLibrary.X11.XF86VidMode.available)
|
||||
{
|
||||
// Get a list of all available display modes
|
||||
XF86VidModeGetAllModeLines(_glfwLibrary.display, screen,
|
||||
XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen,
|
||||
&modecount, &modelist);
|
||||
|
||||
// Unlock mode switch if necessary
|
||||
if (_glfwWin.FS.modeChanged)
|
||||
XF86VidModeLockModeSwitch(_glfwLibrary.display, screen, 0);
|
||||
if (_glfwLibrary.X11.FS.modeChanged)
|
||||
XF86VidModeLockModeSwitch(_glfwLibrary.X11.display, screen, 0);
|
||||
|
||||
// Change the video mode to the desired mode
|
||||
XF86VidModeSwitchToMode(_glfwLibrary.display, screen,
|
||||
XF86VidModeSwitchToMode(_glfwLibrary.X11.display, screen,
|
||||
modelist[mode]);
|
||||
|
||||
// Set viewport to upper left corner (where our window will be)
|
||||
XF86VidModeSetViewPort(_glfwLibrary.display, screen, 0, 0);
|
||||
XF86VidModeSetViewPort(_glfwLibrary.X11.display, screen, 0, 0);
|
||||
|
||||
// Lock mode switch
|
||||
XF86VidModeLockModeSwitch(_glfwLibrary.display, screen, 1);
|
||||
XF86VidModeLockModeSwitch(_glfwLibrary.X11.display, screen, 1);
|
||||
|
||||
// Remember old mode and flag that we have changed the mode
|
||||
if (!_glfwWin.FS.modeChanged)
|
||||
if (!_glfwLibrary.X11.FS.modeChanged)
|
||||
{
|
||||
_glfwWin.FS.oldMode = *modelist[0];
|
||||
_glfwWin.FS.modeChanged = GL_TRUE;
|
||||
_glfwLibrary.X11.FS.oldMode = *modelist[0];
|
||||
_glfwLibrary.X11.FS.modeChanged = GL_TRUE;
|
||||
}
|
||||
|
||||
// Free mode list
|
||||
@ -289,42 +289,44 @@ void _glfwSetVideoMode(int screen, int* width, int* height, int* rate)
|
||||
// Restore the previously saved (original) video mode
|
||||
//========================================================================
|
||||
|
||||
void _glfwRestoreVideoMode(void)
|
||||
void _glfwRestoreVideoMode(int screen)
|
||||
{
|
||||
if (_glfwWin.FS.modeChanged)
|
||||
if (_glfwLibrary.X11.FS.modeChanged)
|
||||
{
|
||||
#if defined(_GLFW_HAS_XRANDR)
|
||||
if (_glfwLibrary.XRandR.available)
|
||||
Window root = RootWindow(_glfwLibrary.X11.display, screen);
|
||||
|
||||
if (_glfwLibrary.X11.XRandR.available)
|
||||
{
|
||||
XRRScreenConfiguration* sc;
|
||||
|
||||
if (_glfwLibrary.XRandR.available)
|
||||
if (_glfwLibrary.X11.XRandR.available)
|
||||
{
|
||||
sc = XRRGetScreenInfo(_glfwLibrary.display, _glfwWin.root);
|
||||
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, root);
|
||||
|
||||
XRRSetScreenConfig(_glfwLibrary.display,
|
||||
XRRSetScreenConfig(_glfwLibrary.X11.display,
|
||||
sc,
|
||||
_glfwWin.root,
|
||||
_glfwWin.FS.oldSizeID,
|
||||
_glfwWin.FS.oldRotation,
|
||||
root,
|
||||
_glfwLibrary.X11.FS.oldSizeID,
|
||||
_glfwLibrary.X11.FS.oldRotation,
|
||||
CurrentTime);
|
||||
|
||||
XRRFreeScreenConfigInfo(sc);
|
||||
}
|
||||
}
|
||||
#elif defined(_GLFW_HAS_XF86VIDMODE)
|
||||
if (_glfwLibrary.XF86VidMode.available)
|
||||
if (_glfwLibrary.X11.XF86VidMode.available)
|
||||
{
|
||||
// Unlock mode switch
|
||||
XF86VidModeLockModeSwitch(_glfwLibrary.display, _glfwWin.screen, 0);
|
||||
XF86VidModeLockModeSwitch(_glfwLibrary.X11.display, screen, 0);
|
||||
|
||||
// Change the video mode back to the old mode
|
||||
XF86VidModeSwitchToMode(_glfwLibrary.display,
|
||||
_glfwWin.screen,
|
||||
&_glfwWin.FS.oldMode);
|
||||
XF86VidModeSwitchToMode(_glfwLibrary.X11.display,
|
||||
screen,
|
||||
&_glfwLibrary.X11.FS.oldMode);
|
||||
}
|
||||
#endif
|
||||
_glfwWin.FS.modeChanged = GL_FALSE;
|
||||
_glfwLibrary.X11.FS.modeChanged = GL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
@ -364,7 +366,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||
#endif
|
||||
|
||||
// Get display and screen
|
||||
dpy = _glfwLibrary.display;
|
||||
dpy = _glfwLibrary.X11.display;
|
||||
screen = DefaultScreen(dpy);
|
||||
|
||||
// Get list of visuals
|
||||
@ -410,7 +412,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
||||
|
||||
// Build resolution array
|
||||
#if defined(_GLFW_HAS_XRANDR)
|
||||
if (_glfwLibrary.XRandR.available)
|
||||
if (_glfwLibrary.X11.XRandR.available)
|
||||
{
|
||||
sc = XRRGetScreenInfo(dpy, RootWindow(dpy, screen));
|
||||
sizelist = XRRConfigSizes(sc, &sizecount);
|
||||
@ -505,7 +507,7 @@ void _glfwPlatformGetDesktopMode(GLFWvidmode* mode)
|
||||
#endif
|
||||
|
||||
// Get display and screen
|
||||
dpy = _glfwLibrary.display;
|
||||
dpy = _glfwLibrary.X11.display;
|
||||
screen = DefaultScreen(dpy);
|
||||
|
||||
// Get display depth
|
||||
@ -515,23 +517,23 @@ void _glfwPlatformGetDesktopMode(GLFWvidmode* mode)
|
||||
BPP2RGB(bpp, &mode->redBits, &mode->greenBits, &mode->blueBits);
|
||||
|
||||
#if defined(_GLFW_HAS_XRANDR)
|
||||
if (_glfwLibrary.XRandR.available)
|
||||
if (_glfwLibrary.X11.XRandR.available)
|
||||
{
|
||||
if (_glfwWin.FS.modeChanged)
|
||||
if (_glfwLibrary.X11.FS.modeChanged)
|
||||
{
|
||||
mode->width = _glfwWin.FS.oldWidth;
|
||||
mode->height = _glfwWin.FS.oldHeight;
|
||||
mode->width = _glfwLibrary.X11.FS.oldWidth;
|
||||
mode->height = _glfwLibrary.X11.FS.oldHeight;
|
||||
return;
|
||||
}
|
||||
}
|
||||
#elif defined(_GLFW_HAS_XF86VIDMODE)
|
||||
if (_glfwLibrary.XF86VidMode.available)
|
||||
if (_glfwLibrary.X11.XF86VidMode.available)
|
||||
{
|
||||
if (_glfwWin.FS.modeChanged)
|
||||
if (_glfwLibrary.X11.FS.modeChanged)
|
||||
{
|
||||
// The old (desktop) mode is stored in _glfwWin.FS.oldMode
|
||||
mode->width = _glfwWin.FS.oldMode.hdisplay;
|
||||
mode->height = _glfwWin.FS.oldMode.vdisplay;
|
||||
mode->width = _glfwLibrary.X11.FS.oldMode.hdisplay;
|
||||
mode->height = _glfwLibrary.X11.FS.oldMode.vdisplay;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -65,8 +65,9 @@ int _glfwPlatformExtensionSupported(const char* extension)
|
||||
const GLubyte* extensions;
|
||||
|
||||
// Get list of GLX extensions
|
||||
extensions = (const GLubyte*) glXQueryExtensionsString(_glfwLibrary.display,
|
||||
_glfwWin.screen);
|
||||
// Yuck
|
||||
extensions = (const GLubyte*) glXQueryExtensionsString(_glfwLibrary.X11.display,
|
||||
_glfwLibrary.window->X11.screen);
|
||||
if (extensions != NULL)
|
||||
{
|
||||
if (_glfwStringInExtensionString(extension, extensions))
|
||||
|
@ -82,8 +82,8 @@ static void glfw_atexit(void)
|
||||
static int initDisplay(void)
|
||||
{
|
||||
// Open display
|
||||
_glfwLibrary.display = XOpenDisplay(0);
|
||||
if (!_glfwLibrary.display)
|
||||
_glfwLibrary.X11.display = XOpenDisplay(0);
|
||||
if (!_glfwLibrary.X11.display)
|
||||
{
|
||||
fprintf(stderr, "Failed to open X display\n");
|
||||
return GL_FALSE;
|
||||
@ -91,36 +91,36 @@ static int initDisplay(void)
|
||||
|
||||
// Check for XF86VidMode extension
|
||||
#ifdef _GLFW_HAS_XF86VIDMODE
|
||||
_glfwLibrary.XF86VidMode.available =
|
||||
XF86VidModeQueryExtension(_glfwLibrary.display,
|
||||
&_glfwLibrary.XF86VidMode.eventBase,
|
||||
&_glfwLibrary.XF86VidMode.errorBase);
|
||||
_glfwLibrary.X11.XF86VidMode.available =
|
||||
XF86VidModeQueryExtension(_glfwLibrary.X11.display,
|
||||
&_glfwLibrary.X11.XF86VidMode.eventBase,
|
||||
&_glfwLibrary.X11.XF86VidMode.errorBase);
|
||||
#else
|
||||
_glfwLibrary.XF86VidMode.available = 0;
|
||||
_glfwLibrary.X11.XF86VidMode.available = 0;
|
||||
#endif
|
||||
|
||||
// Check for XRandR extension
|
||||
#ifdef _GLFW_HAS_XRANDR
|
||||
_glfwLibrary.XRandR.available =
|
||||
XRRQueryExtension(_glfwLibrary.display,
|
||||
&_glfwLibrary.XRandR.eventBase,
|
||||
&_glfwLibrary.XRandR.errorBase);
|
||||
_glfwLibrary.X11.XRandR.available =
|
||||
XRRQueryExtension(_glfwLibrary.X11.display,
|
||||
&_glfwLibrary.X11.XRandR.eventBase,
|
||||
&_glfwLibrary.X11.XRandR.errorBase);
|
||||
#else
|
||||
_glfwLibrary.XRandR.available = 0;
|
||||
_glfwLibrary.X11.XRandR.available = 0;
|
||||
#endif
|
||||
|
||||
// Fullscreen & screen saver settings
|
||||
// Check if GLX is supported on this display
|
||||
if (!glXQueryExtension(_glfwLibrary.display, NULL, NULL))
|
||||
if (!glXQueryExtension(_glfwLibrary.X11.display, NULL, NULL))
|
||||
{
|
||||
fprintf(stderr, "GLX not supported\n");
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
// Retrieve GLX version
|
||||
if (!glXQueryVersion(_glfwLibrary.display,
|
||||
&_glfwLibrary.glxMajor,
|
||||
&_glfwLibrary.glxMinor))
|
||||
if (!glXQueryVersion(_glfwLibrary.X11.display,
|
||||
&_glfwLibrary.X11.glxMajor,
|
||||
&_glfwLibrary.X11.glxMinor))
|
||||
{
|
||||
fprintf(stderr, "Unable to query GLX version\n");
|
||||
return GL_FALSE;
|
||||
@ -137,10 +137,10 @@ static int initDisplay(void)
|
||||
static void terminateDisplay(void)
|
||||
{
|
||||
// Open display
|
||||
if (_glfwLibrary.display)
|
||||
if (_glfwLibrary.X11.display)
|
||||
{
|
||||
XCloseDisplay(_glfwLibrary.display);
|
||||
_glfwLibrary.display = NULL;
|
||||
XCloseDisplay(_glfwLibrary.X11.display);
|
||||
_glfwLibrary.X11.display = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,8 +180,8 @@ int _glfwPlatformInit(void)
|
||||
|
||||
int _glfwPlatformTerminate(void)
|
||||
{
|
||||
// Close OpenGL window
|
||||
glfwCloseWindow();
|
||||
if (_glfwLibrary.window)
|
||||
glfwCloseWindow(_glfwLibrary.window);
|
||||
|
||||
// Terminate display
|
||||
terminateDisplay();
|
||||
|
@ -40,12 +40,12 @@ void _glfwInitTimer(void)
|
||||
struct timeval tv;
|
||||
|
||||
// "Resolution" is 1 us
|
||||
_glfwLibrary.Timer.resolution = 1e-6;
|
||||
_glfwLibrary.X11.Timer.resolution = 1e-6;
|
||||
|
||||
// Set start-time for timer
|
||||
gettimeofday(&tv, NULL);
|
||||
_glfwLibrary.Timer.t0 = (long long) tv.tv_sec * (long long) 1000000 +
|
||||
(long long) tv.tv_usec;
|
||||
_glfwLibrary.X11.Timer.t0 = (long long) tv.tv_sec * (long long) 1000000 +
|
||||
(long long) tv.tv_usec;
|
||||
}
|
||||
|
||||
|
||||
@ -66,7 +66,7 @@ double _glfwPlatformGetTime(void)
|
||||
t = (long long) tv.tv_sec * (long long) 1000000 +
|
||||
(long long) tv.tv_usec;
|
||||
|
||||
return (double)(t - _glfwLibrary.Timer.t0) * _glfwLibrary.Timer.resolution;
|
||||
return (double)(t - _glfwLibrary.X11.Timer.t0) * _glfwLibrary.X11.Timer.resolution;
|
||||
}
|
||||
|
||||
|
||||
@ -84,6 +84,6 @@ void _glfwPlatformSetTime(double t)
|
||||
(long long) tv.tv_usec;
|
||||
|
||||
// Calulate new starting time
|
||||
_glfwLibrary.Timer.t0 = t0 - (long long)(t / _glfwLibrary.Timer.resolution);
|
||||
_glfwLibrary.X11.Timer.t0 = t0 - (long long)(t / _glfwLibrary.X11.Timer.resolution);
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user