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