mirror of
https://github.com/glfw/glfw.git
synced 2024-11-10 00:51:47 +00:00
Merge branch 'master' of github.com:raedwulf/glfw into clipboard
Conflicts: tests/CMakeLists.txt
This commit is contained in:
commit
d561e3a0b0
@ -287,6 +287,7 @@ version of GLFW.</p>
|
|||||||
<li>Changed buffer bit depth parameters of <code>glfwOpenWindow</code> to window hints</li>
|
<li>Changed buffer bit depth parameters of <code>glfwOpenWindow</code> to window hints</li>
|
||||||
<li>Renamed <code>glfw.h</code> to <code>glfw3.h</code> to avoid conflicts with 2.x series</li>
|
<li>Renamed <code>glfw.h</code> to <code>glfw3.h</code> to avoid conflicts with 2.x series</li>
|
||||||
<li>Renamed <code>GLFW_WINDOW</code> token to <code>GLFW_WINDOWED</code></li>
|
<li>Renamed <code>GLFW_WINDOW</code> token to <code>GLFW_WINDOWED</code></li>
|
||||||
|
<li>Renamed <code>version</code> test to <code>glfwinfo</code></li>
|
||||||
<li>Replaced ad hoc build system with CMake</li>
|
<li>Replaced ad hoc build system with CMake</li>
|
||||||
<li>Replaced layout-dependent key codes with single, platform-independent set based on US layout</li>
|
<li>Replaced layout-dependent key codes with single, platform-independent set based on US layout</li>
|
||||||
<li>Replaced mouse wheel interface with two-dimensional scrolling interface</li>
|
<li>Replaced mouse wheel interface with two-dimensional scrolling interface</li>
|
||||||
@ -302,7 +303,7 @@ version of GLFW.</p>
|
|||||||
<li>Removed <code>GLFW_OPENED</code> window parameter</li>
|
<li>Removed <code>GLFW_OPENED</code> window parameter</li>
|
||||||
<li>Removed nonsensical key actions for Unicode character input</li>
|
<li>Removed nonsensical key actions for Unicode character input</li>
|
||||||
<li>Removed <code>GLFWCALL</code> and <code>GLFWAPIENTRY</code> macros for stdcall calling convention</li>
|
<li>Removed <code>GLFWCALL</code> and <code>GLFWAPIENTRY</code> macros for stdcall calling convention</li>
|
||||||
<li>Bugfix: The default OpenGL version in the <code>version</code> test was set to 1.1</li>
|
<li>Bugfix: The default OpenGL version in the <code>glfwinfo</code> test was set to 1.1</li>
|
||||||
<li>Bugfix: The OpenGL profile and forward-compatibility window parameters were not saved after context creation</li>
|
<li>Bugfix: The OpenGL profile and forward-compatibility window parameters were not saved after context creation</li>
|
||||||
<li>Bugfix: The FSAA test did not check for the availability of <code>GL_ARB_multisample</code></li>
|
<li>Bugfix: The FSAA test did not check for the availability of <code>GL_ARB_multisample</code></li>
|
||||||
<li>[Cocoa] Added support for OpenGL 3.2 core profile in 10.7 Lion and above</li>
|
<li>[Cocoa] Added support for OpenGL 3.2 core profile in 10.7 Lion and above</li>
|
||||||
|
@ -228,6 +228,7 @@ int _glfwPlatformInit(void)
|
|||||||
// Save the original gamma ramp
|
// Save the original gamma ramp
|
||||||
_glfwLibrary.originalRampSize = CGDisplayGammaTableCapacity(CGMainDisplayID());
|
_glfwLibrary.originalRampSize = CGDisplayGammaTableCapacity(CGMainDisplayID());
|
||||||
_glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp);
|
_glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp);
|
||||||
|
_glfwLibrary.currentRamp = _glfwLibrary.originalRamp;
|
||||||
|
|
||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
}
|
}
|
||||||
|
@ -67,11 +67,8 @@
|
|||||||
|
|
||||||
NSRect contentRect =
|
NSRect contentRect =
|
||||||
[window->NS.window contentRectForFrameRect:[window->NS.window frame]];
|
[window->NS.window contentRectForFrameRect:[window->NS.window frame]];
|
||||||
window->width = contentRect.size.width;
|
|
||||||
window->height = contentRect.size.height;
|
|
||||||
|
|
||||||
if (_glfwLibrary.windowSizeCallback)
|
_glfwInputWindowSize(window, contentRect.size.width, contentRect.size.height);
|
||||||
_glfwLibrary.windowSizeCallback(window, window->width, window->height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)windowDidMove:(NSNotification *)notification
|
- (void)windowDidMove:(NSNotification *)notification
|
||||||
@ -87,24 +84,17 @@
|
|||||||
mainScreenHeight - contentRect.origin.y -
|
mainScreenHeight - contentRect.origin.y -
|
||||||
mainScreenOrigin.y - window->height);
|
mainScreenOrigin.y - window->height);
|
||||||
|
|
||||||
window->positionX = flippedPos.x;
|
_glfwInputWindowPos(window, flippedPos.x, flippedPos.y);
|
||||||
window->positionY = flippedPos.y;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)windowDidMiniaturize:(NSNotification *)notification
|
- (void)windowDidMiniaturize:(NSNotification *)notification
|
||||||
{
|
{
|
||||||
window->iconified = GL_TRUE;
|
_glfwInputWindowIconify(window, GL_TRUE);
|
||||||
|
|
||||||
if (_glfwLibrary.windowIconifyCallback)
|
|
||||||
_glfwLibrary.windowIconifyCallback(window, window->iconified);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)windowDidDeminiaturize:(NSNotification *)notification
|
- (void)windowDidDeminiaturize:(NSNotification *)notification
|
||||||
{
|
{
|
||||||
window->iconified = GL_FALSE;
|
_glfwInputWindowIconify(window, GL_FALSE);
|
||||||
|
|
||||||
if (_glfwLibrary.windowIconifyCallback)
|
|
||||||
_glfwLibrary.windowIconifyCallback(window, window->iconified);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)windowDidBecomeKey:(NSNotification *)notification
|
- (void)windowDidBecomeKey:(NSNotification *)notification
|
||||||
@ -349,24 +339,15 @@ static int convertMacKeyCode(unsigned int macKeyCode)
|
|||||||
- (void)mouseMoved:(NSEvent *)event
|
- (void)mouseMoved:(NSEvent *)event
|
||||||
{
|
{
|
||||||
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
||||||
{
|
_glfwInputCursorMotion(window, [event deltaX], [event deltaY]);
|
||||||
window->mousePosX += [event deltaX];
|
|
||||||
window->mousePosY += [event deltaY];
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NSPoint p = [event locationInWindow];
|
NSPoint p = [event locationInWindow];
|
||||||
|
|
||||||
// Cocoa coordinate system has origin at lower left
|
// Cocoa coordinate system has origin at lower left
|
||||||
window->mousePosX = p.x;
|
p.y = [[window->NS.window contentView] bounds].size.height - p.y;
|
||||||
window->mousePosY = [[window->NS.window contentView] bounds].size.height - p.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_glfwLibrary.mousePosCallback)
|
_glfwInputCursorMotion(window, p.x, p.y);
|
||||||
{
|
|
||||||
_glfwLibrary.mousePosCallback(window,
|
|
||||||
window->mousePosX,
|
|
||||||
window->mousePosY);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -707,8 +688,8 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
|||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(window);
|
||||||
|
|
||||||
NSPoint point = [[NSCursor currentCursor] hotSpot];
|
NSPoint point = [[NSCursor currentCursor] hotSpot];
|
||||||
window->mousePosX = point.x;
|
window->cursorPosX = point.x;
|
||||||
window->mousePosY = point.y;
|
window->cursorPosY = point.y;
|
||||||
|
|
||||||
window->windowNoResize = wndconfig->windowNoResize;
|
window->windowNoResize = wndconfig->windowNoResize;
|
||||||
|
|
||||||
|
@ -152,6 +152,7 @@ GLFWAPI void glfwEnable(GLFWwindow window, int token)
|
|||||||
enableKeyRepeat(window);
|
enableKeyRepeat(window);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
_glfwSetError(GLFW_INVALID_ENUM, NULL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -184,6 +185,7 @@ GLFWAPI void glfwDisable(GLFWwindow window, int token)
|
|||||||
disableKeyRepeat(window);
|
disableKeyRepeat(window);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
_glfwSetError(GLFW_INVALID_ENUM, NULL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,9 +110,18 @@ GLFWAPI int glfwGetVideoModes(GLFWvidmode* list, int maxcount)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maxcount <= 0 || list == NULL)
|
if (maxcount <= 0)
|
||||||
{
|
{
|
||||||
// TODO: Figure out if this is an error
|
_glfwSetError(GLFW_INVALID_VALUE,
|
||||||
|
"glfwGetVideoModes: Parameter 'maxcount' must be "
|
||||||
|
"greater than zero");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (list == NULL)
|
||||||
|
{
|
||||||
|
_glfwSetError(GLFW_INVALID_VALUE,
|
||||||
|
"glfwGetVideoModes: Parameter 'list' cannot be NULL");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
152
src/input.c
152
src/input.c
@ -31,6 +31,119 @@
|
|||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
////// GLFW internal API //////
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
//========================================================================
|
||||||
|
// Register keyboard activity
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
|
void _glfwInputKey(_GLFWwindow* window, int key, int action)
|
||||||
|
{
|
||||||
|
GLboolean keyrepeat = GL_FALSE;
|
||||||
|
|
||||||
|
if (key < 0 || key > GLFW_KEY_LAST)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Are we trying to release an already released key?
|
||||||
|
if (action == GLFW_RELEASE && window->key[key] != GLFW_PRESS)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Register key action
|
||||||
|
if(action == GLFW_RELEASE && window->stickyKeys)
|
||||||
|
window->key[key] = GLFW_STICK;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
keyrepeat = (window->key[key] == GLFW_PRESS) && (action == GLFW_PRESS);
|
||||||
|
window->key[key] = (char) action;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call user callback function
|
||||||
|
if (_glfwLibrary.keyCallback && (window->keyRepeat || !keyrepeat))
|
||||||
|
_glfwLibrary.keyCallback(window, key, action);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//========================================================================
|
||||||
|
// Register (keyboard) character activity
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
|
void _glfwInputChar(_GLFWwindow* window, int character)
|
||||||
|
{
|
||||||
|
// Valid Unicode (ISO 10646) character?
|
||||||
|
if (!((character >= 32 && character <= 126) || character >= 160))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_glfwLibrary.charCallback)
|
||||||
|
_glfwLibrary.charCallback(window, character);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//========================================================================
|
||||||
|
// Register scroll events
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
|
void _glfwInputScroll(_GLFWwindow* window, int xoffset, int yoffset)
|
||||||
|
{
|
||||||
|
window->scrollX += xoffset;
|
||||||
|
window->scrollY += yoffset;
|
||||||
|
|
||||||
|
if (_glfwLibrary.scrollCallback)
|
||||||
|
_glfwLibrary.scrollCallback(window, xoffset, yoffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//========================================================================
|
||||||
|
// Register mouse button clicks
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
|
void _glfwInputMouseClick(_GLFWwindow* window, int button, int action)
|
||||||
|
{
|
||||||
|
if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Register mouse button action
|
||||||
|
if (action == GLFW_RELEASE && window->stickyMouseButtons)
|
||||||
|
window->mouseButton[button] = GLFW_STICK;
|
||||||
|
else
|
||||||
|
window->mouseButton[button] = (char) action;
|
||||||
|
|
||||||
|
if (_glfwLibrary.mouseButtonCallback)
|
||||||
|
_glfwLibrary.mouseButtonCallback(window, button, action);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//========================================================================
|
||||||
|
// Register cursor moves
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
|
void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y)
|
||||||
|
{
|
||||||
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
||||||
|
{
|
||||||
|
if (!x && !y)
|
||||||
|
return;
|
||||||
|
|
||||||
|
window->cursorPosX += x;
|
||||||
|
window->cursorPosY += y;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (window->cursorPosX == x && window->cursorPosY == y)
|
||||||
|
return;
|
||||||
|
|
||||||
|
window->cursorPosX = x;
|
||||||
|
window->cursorPosY = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_glfwLibrary.mousePosCallback)
|
||||||
|
_glfwLibrary.mousePosCallback(window,
|
||||||
|
window->cursorPosX,
|
||||||
|
window->cursorPosY);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
////// GLFW public API //////
|
////// GLFW public API //////
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
@ -53,7 +166,7 @@ GLFWAPI int glfwGetKey(GLFWwindow handle, int key)
|
|||||||
if (key < 0 || key > GLFW_KEY_LAST)
|
if (key < 0 || key > GLFW_KEY_LAST)
|
||||||
{
|
{
|
||||||
// TODO: Decide whether key is a value or enum
|
// TODO: Decide whether key is a value or enum
|
||||||
_glfwSetError(GLFW_INVALID_VALUE,
|
_glfwSetError(GLFW_INVALID_ENUM,
|
||||||
"glfwGetKey: The specified key is invalid");
|
"glfwGetKey: The specified key is invalid");
|
||||||
return GLFW_RELEASE;
|
return GLFW_RELEASE;
|
||||||
}
|
}
|
||||||
@ -118,10 +231,10 @@ GLFWAPI void glfwGetMousePos(GLFWwindow handle, int* xpos, int* ypos)
|
|||||||
|
|
||||||
// Return mouse position
|
// Return mouse position
|
||||||
if (xpos != NULL)
|
if (xpos != NULL)
|
||||||
*xpos = window->mousePosX;
|
*xpos = window->cursorPosX;
|
||||||
|
|
||||||
if (ypos != NULL)
|
if (ypos != NULL)
|
||||||
*ypos = window->mousePosY;
|
*ypos = window->cursorPosY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -147,12 +260,12 @@ GLFWAPI void glfwSetMousePos(GLFWwindow handle, int xpos, int ypos)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Don't do anything if the mouse position did not change
|
// Don't do anything if the mouse position did not change
|
||||||
if (xpos == window->mousePosX && ypos == window->mousePosY)
|
if (xpos == window->cursorPosX && ypos == window->cursorPosY)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Set GLFW mouse position
|
// Set GLFW mouse position
|
||||||
window->mousePosX = xpos;
|
window->cursorPosX = xpos;
|
||||||
window->mousePosY = ypos;
|
window->cursorPosY = ypos;
|
||||||
|
|
||||||
// Do not move physical cursor in locked cursor mode
|
// Do not move physical cursor in locked cursor mode
|
||||||
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
||||||
@ -191,6 +304,7 @@ GLFWAPI void glfwGetScrollOffset(GLFWwindow handle, int* xoffset, int* yoffset)
|
|||||||
|
|
||||||
GLFWAPI void glfwSetCursorMode(GLFWwindow handle, int mode)
|
GLFWAPI void glfwSetCursorMode(GLFWwindow handle, int mode)
|
||||||
{
|
{
|
||||||
|
int centerPosX, centerPosY;
|
||||||
_GLFWwindow* window = (_GLFWwindow*) handle;
|
_GLFWwindow* window = (_GLFWwindow*) handle;
|
||||||
|
|
||||||
if (!_glfwInitialized)
|
if (!_glfwInitialized)
|
||||||
@ -210,29 +324,17 @@ GLFWAPI void glfwSetCursorMode(GLFWwindow handle, int mode)
|
|||||||
if (window->cursorMode == mode)
|
if (window->cursorMode == mode)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int centerPosX = window->width / 2;
|
centerPosX = window->width / 2;
|
||||||
int centerPosY = window->height / 2;
|
centerPosY = window->height / 2;
|
||||||
|
|
||||||
if (mode == GLFW_CURSOR_CAPTURED)
|
if (mode == GLFW_CURSOR_CAPTURED)
|
||||||
{
|
|
||||||
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
|
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
|
||||||
}
|
|
||||||
else if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
else if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
||||||
{
|
{
|
||||||
if (centerPosX != window->mousePosX || centerPosY != window->mousePosY)
|
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
|
||||||
{
|
_glfwInputCursorMotion(window,
|
||||||
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
|
centerPosX - window->cursorPosX,
|
||||||
|
centerPosY - window->cursorPosY);
|
||||||
window->mousePosX = centerPosX;
|
|
||||||
window->mousePosY = centerPosY;
|
|
||||||
|
|
||||||
if (_glfwLibrary.mousePosCallback)
|
|
||||||
{
|
|
||||||
_glfwLibrary.mousePosCallback(window,
|
|
||||||
window->mousePosX,
|
|
||||||
window->mousePosY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_glfwPlatformSetCursorMode(window, mode);
|
_glfwPlatformSetCursorMode(window, mode);
|
||||||
@ -311,7 +413,7 @@ GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun)
|
|||||||
_GLFWwindow* window;
|
_GLFWwindow* window;
|
||||||
|
|
||||||
for (window = _glfwLibrary.windowListHead; window; window = window->next)
|
for (window = _glfwLibrary.windowListHead; window; window = window->next)
|
||||||
cbfun(window, window->mousePosX, window->mousePosY);
|
cbfun(window, window->cursorPosX, window->cursorPosY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +59,10 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "../include/GL/glfw3.h"
|
#include "../include/GL/glfw3.h"
|
||||||
|
|
||||||
|
// This path may need to be changed if you build GLFW using your own setup
|
||||||
|
// We ship and use our own copy of glext.h since GLFW uses fairly new
|
||||||
|
// extensions and not all operating systems come with an up-to-date version
|
||||||
#include "../support/GL/glext.h"
|
#include "../support/GL/glext.h"
|
||||||
|
|
||||||
#if defined(_GLFW_COCOA_NSGL)
|
#if defined(_GLFW_COCOA_NSGL)
|
||||||
@ -180,7 +184,7 @@ struct _GLFWwindow
|
|||||||
GLboolean stickyMouseButtons;
|
GLboolean stickyMouseButtons;
|
||||||
GLboolean keyRepeat;
|
GLboolean keyRepeat;
|
||||||
GLboolean sysKeysDisabled; // system keys disabled flag
|
GLboolean sysKeysDisabled; // system keys disabled flag
|
||||||
int mousePosX, mousePosY;
|
int cursorPosX, cursorPosY;
|
||||||
int cursorMode;
|
int cursorMode;
|
||||||
int scrollX, scrollY;
|
int scrollX, scrollY;
|
||||||
char mouseButton[GLFW_MOUSE_BUTTON_LAST + 1];
|
char mouseButton[GLFW_MOUSE_BUTTON_LAST + 1];
|
||||||
@ -339,12 +343,19 @@ void _glfwSetError(int error, const char* description);
|
|||||||
// Window management (window.c)
|
// Window management (window.c)
|
||||||
void _glfwSetDefaultWindowHints(void);
|
void _glfwSetDefaultWindowHints(void);
|
||||||
|
|
||||||
// Input handling (window.c)
|
// WIndow event notification
|
||||||
|
void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated);
|
||||||
|
void _glfwInputWindowPos(_GLFWwindow* window, int x, int y);
|
||||||
|
void _glfwInputWindowSize(_GLFWwindow* window, int width, int height);
|
||||||
|
void _glfwInputWindowIconify(_GLFWwindow* window, int iconified);
|
||||||
|
void _glfwInputWindowDamage(_GLFWwindow* window);
|
||||||
|
|
||||||
|
// Input event notification
|
||||||
void _glfwInputKey(_GLFWwindow* window, int key, int action);
|
void _glfwInputKey(_GLFWwindow* window, int key, int action);
|
||||||
void _glfwInputChar(_GLFWwindow* window, int character);
|
void _glfwInputChar(_GLFWwindow* window, int character);
|
||||||
void _glfwInputScroll(_GLFWwindow* window, int x, int y);
|
void _glfwInputScroll(_GLFWwindow* window, int x, int y);
|
||||||
void _glfwInputMouseClick(_GLFWwindow* window, int button, int action);
|
void _glfwInputMouseClick(_GLFWwindow* window, int button, int action);
|
||||||
void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated);
|
void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y);
|
||||||
|
|
||||||
// OpenGL context helpers (opengl.c)
|
// OpenGL context helpers (opengl.c)
|
||||||
int _glfwStringInExtensionString(const char* string, const GLubyte* extensions);
|
int _glfwStringInExtensionString(const char* string, const GLubyte* extensions);
|
||||||
|
@ -345,6 +345,7 @@ GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig)
|
|||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Checks whether the specified context fulfils the requirements
|
// Checks whether the specified context fulfils the requirements
|
||||||
// It blames glfwOpenWindow because that's the only caller
|
// It blames glfwOpenWindow because that's the only caller
|
||||||
|
@ -163,6 +163,7 @@ int _glfwPlatformInit(void)
|
|||||||
// Save the original gamma ramp
|
// Save the original gamma ramp
|
||||||
_glfwLibrary.originalRampSize = 256;
|
_glfwLibrary.originalRampSize = 256;
|
||||||
_glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp);
|
_glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp);
|
||||||
|
_glfwLibrary.currentRamp = _glfwLibrary.originalRamp;
|
||||||
|
|
||||||
_glfwInitTimer();
|
_glfwInitTimer();
|
||||||
|
|
||||||
|
@ -43,6 +43,9 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <mmsystem.h>
|
#include <mmsystem.h>
|
||||||
|
|
||||||
|
// This path may need to be changed if you build GLFW using your own setup
|
||||||
|
// We ship and use our own copy of wglext.h since GLFW uses fairly new
|
||||||
|
// extensions and not all operating systems come with an up-to-date version
|
||||||
#include "../support/GL/wglext.h"
|
#include "../support/GL/wglext.h"
|
||||||
|
|
||||||
|
|
||||||
@ -251,7 +254,7 @@ typedef struct _GLFWwindowWin32
|
|||||||
|
|
||||||
// Various platform specific internal variables
|
// Various platform specific internal variables
|
||||||
int desiredRefreshRate; // Desired vertical monitor refresh rate
|
int desiredRefreshRate; // Desired vertical monitor refresh rate
|
||||||
GLboolean mouseMoved;
|
GLboolean cursorCentered;
|
||||||
int oldMouseX, oldMouseY;
|
int oldMouseX, oldMouseY;
|
||||||
} _GLFWwindowWin32;
|
} _GLFWwindowWin32;
|
||||||
|
|
||||||
|
@ -472,6 +472,50 @@ static GLboolean createContext(_GLFWwindow* window,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//========================================================================
|
||||||
|
// Hide mouse cursor
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
|
static void hideMouseCursor(_GLFWwindow* window)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//========================================================================
|
||||||
|
// Capture mouse cursor
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
|
static void captureMouseCursor(_GLFWwindow* window)
|
||||||
|
{
|
||||||
|
RECT ClipWindowRect;
|
||||||
|
|
||||||
|
ShowCursor(FALSE);
|
||||||
|
|
||||||
|
// Clip cursor to the window
|
||||||
|
if (GetWindowRect(window->Win32.handle, &ClipWindowRect))
|
||||||
|
ClipCursor(&ClipWindowRect);
|
||||||
|
|
||||||
|
// Capture cursor to user window
|
||||||
|
SetCapture(window->Win32.handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//========================================================================
|
||||||
|
// Show mouse cursor
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
|
static void showMouseCursor(_GLFWwindow* window)
|
||||||
|
{
|
||||||
|
// Un-capture cursor
|
||||||
|
ReleaseCapture();
|
||||||
|
|
||||||
|
// Release the cursor from the window
|
||||||
|
ClipCursor(NULL);
|
||||||
|
|
||||||
|
ShowCursor(TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Translates a Windows key to the corresponding GLFW key
|
// Translates a Windows key to the corresponding GLFW key
|
||||||
//========================================================================
|
//========================================================================
|
||||||
@ -808,15 +852,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|||||||
}
|
}
|
||||||
|
|
||||||
_glfwInputWindowFocus(window, active);
|
_glfwInputWindowFocus(window, active);
|
||||||
|
_glfwInputWindowIconify(window, iconified);
|
||||||
if (iconified != window->iconified)
|
|
||||||
{
|
|
||||||
window->iconified = iconified;
|
|
||||||
|
|
||||||
if (_glfwLibrary.windowIconifyCallback)
|
|
||||||
_glfwLibrary.windowIconifyCallback(window, window->iconified);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -962,32 +998,27 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|||||||
if (newMouseX != window->Win32.oldMouseX ||
|
if (newMouseX != window->Win32.oldMouseX ||
|
||||||
newMouseY != window->Win32.oldMouseY)
|
newMouseY != window->Win32.oldMouseY)
|
||||||
{
|
{
|
||||||
|
int x, y;
|
||||||
|
|
||||||
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
||||||
{
|
{
|
||||||
if (_glfwLibrary.activeWindow != window)
|
if (_glfwLibrary.activeWindow != window)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
window->mousePosX += newMouseX -
|
x = newMouseX - window->Win32.oldMouseX;
|
||||||
window->Win32.oldMouseX;
|
y = newMouseY - window->Win32.oldMouseY;
|
||||||
window->mousePosY += newMouseY -
|
|
||||||
window->Win32.oldMouseY;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
window->mousePosX = newMouseX;
|
x = newMouseX;
|
||||||
window->mousePosY = newMouseY;
|
y = newMouseY;
|
||||||
}
|
}
|
||||||
|
|
||||||
window->Win32.oldMouseX = newMouseX;
|
window->Win32.oldMouseX = newMouseX;
|
||||||
window->Win32.oldMouseY = newMouseY;
|
window->Win32.oldMouseY = newMouseY;
|
||||||
window->Win32.cursorCentered = GL_FALSE;
|
window->Win32.cursorCentered = GL_FALSE;
|
||||||
|
|
||||||
if (_glfwLibrary.mousePosCallback)
|
_glfwInputCursorMotion(window, x, y);
|
||||||
{
|
|
||||||
_glfwLibrary.mousePosCallback(window,
|
|
||||||
window->mousePosX,
|
|
||||||
window->mousePosY);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -1009,9 +1040,6 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|||||||
|
|
||||||
case WM_SIZE:
|
case WM_SIZE:
|
||||||
{
|
{
|
||||||
window->width = LOWORD(lParam);
|
|
||||||
window->height = HIWORD(lParam);
|
|
||||||
|
|
||||||
// If window is in cursor capture mode, update clipping rect
|
// If window is in cursor capture mode, update clipping rect
|
||||||
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
||||||
{
|
{
|
||||||
@ -1020,21 +1048,12 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|||||||
ClipCursor(&ClipWindowRect);
|
ClipCursor(&ClipWindowRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_glfwLibrary.windowSizeCallback)
|
_glfwInputWindowSize(window, LOWORD(lParam), HIWORD(lParam));
|
||||||
{
|
|
||||||
_glfwLibrary.windowSizeCallback(window,
|
|
||||||
window->width,
|
|
||||||
window->height);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
case WM_MOVE:
|
case WM_MOVE:
|
||||||
{
|
{
|
||||||
window->positionX = LOWORD(lParam);
|
|
||||||
window->positionY = HIWORD(lParam);
|
|
||||||
|
|
||||||
// If window is in cursor capture mode, update clipping rect
|
// If window is in cursor capture mode, update clipping rect
|
||||||
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
||||||
{
|
{
|
||||||
@ -1042,15 +1061,15 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|||||||
if (GetWindowRect(window->Win32.handle, &ClipWindowRect))
|
if (GetWindowRect(window->Win32.handle, &ClipWindowRect))
|
||||||
ClipCursor(&ClipWindowRect);
|
ClipCursor(&ClipWindowRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_glfwInputWindowPos(window, LOWORD(lParam), HIWORD(lParam));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Was the window contents damaged?
|
// Was the window contents damaged?
|
||||||
case WM_PAINT:
|
case WM_PAINT:
|
||||||
{
|
{
|
||||||
if (_glfwLibrary.windowRefreshCallback)
|
_glfwInputWindowDamage(window);
|
||||||
_glfwLibrary.windowRefreshCallback(window);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1352,8 +1371,8 @@ static int createWindow(_GLFWwindow* window,
|
|||||||
// Initialize mouse position data
|
// Initialize mouse position data
|
||||||
GetCursorPos(&pos);
|
GetCursorPos(&pos);
|
||||||
ScreenToClient(window->Win32.handle, &pos);
|
ScreenToClient(window->Win32.handle, &pos);
|
||||||
window->Win32.oldMouseX = window->mousePosX = pos.x;
|
window->Win32.oldMouseX = window->cursorPosX = pos.x;
|
||||||
window->Win32.oldMouseY = window->mousePosY = pos.y;
|
window->Win32.oldMouseY = window->cursorPosY = pos.y;
|
||||||
|
|
||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
}
|
}
|
||||||
@ -1761,14 +1780,14 @@ void _glfwPlatformPollEvents(void)
|
|||||||
window = _glfwLibrary.activeWindow;
|
window = _glfwLibrary.activeWindow;
|
||||||
if (window)
|
if (window)
|
||||||
{
|
{
|
||||||
window->Win32.mouseMoved = GL_FALSE;
|
window->Win32.cursorCentered = GL_FALSE;
|
||||||
window->Win32.oldMouseX = window->width / 2;
|
window->Win32.oldMouseX = window->width / 2;
|
||||||
window->Win32.oldMouseY = window->height / 2;
|
window->Win32.oldMouseY = window->height / 2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//window->Win32.oldMouseX = window->mousePosX;
|
//window->Win32.oldMouseX = window->cursorPosX;
|
||||||
//window->Win32.oldMouseY = window->mousePosY;
|
//window->Win32.oldMouseY = window->cursorPosY;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
||||||
@ -1846,41 +1865,6 @@ void _glfwPlatformWaitEvents(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
|
||||||
// Hide mouse cursor (lock it)
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
void _glfwPlatformHideMouseCursor(_GLFWwindow* window)
|
|
||||||
{
|
|
||||||
RECT ClipWindowRect;
|
|
||||||
|
|
||||||
ShowCursor(FALSE);
|
|
||||||
|
|
||||||
// Clip cursor to the window
|
|
||||||
if (GetWindowRect(window->Win32.handle, &ClipWindowRect))
|
|
||||||
ClipCursor(&ClipWindowRect);
|
|
||||||
|
|
||||||
// Capture cursor to user window
|
|
||||||
SetCapture(window->Win32.handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
|
||||||
// Show mouse cursor (unlock it)
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
void _glfwPlatformShowMouseCursor(_GLFWwindow* window)
|
|
||||||
{
|
|
||||||
// Un-capture cursor
|
|
||||||
ReleaseCapture();
|
|
||||||
|
|
||||||
// Release the cursor from the window
|
|
||||||
ClipCursor(NULL);
|
|
||||||
|
|
||||||
ShowCursor(TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Set physical mouse cursor position
|
// Set physical mouse cursor position
|
||||||
//========================================================================
|
//========================================================================
|
||||||
@ -1897,3 +1881,24 @@ void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y)
|
|||||||
SetCursorPos(pos.x, pos.y);
|
SetCursorPos(pos.x, pos.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//========================================================================
|
||||||
|
// Set physical mouse cursor mode
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
|
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
|
||||||
|
{
|
||||||
|
switch (mode)
|
||||||
|
{
|
||||||
|
case GLFW_CURSOR_NORMAL:
|
||||||
|
showMouseCursor(window);
|
||||||
|
break;
|
||||||
|
case GLFW_CURSOR_HIDDEN:
|
||||||
|
hideMouseCursor(window);
|
||||||
|
break;
|
||||||
|
case GLFW_CURSOR_CAPTURED:
|
||||||
|
captureMouseCursor(window);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
144
src/window.c
144
src/window.c
@ -103,85 +103,6 @@ void _glfwSetDefaultWindowHints(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
|
||||||
// Register keyboard activity
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
void _glfwInputKey(_GLFWwindow* window, int key, int action)
|
|
||||||
{
|
|
||||||
GLboolean keyrepeat = GL_FALSE;
|
|
||||||
|
|
||||||
if (key < 0 || key > GLFW_KEY_LAST)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Are we trying to release an already released key?
|
|
||||||
if (action == GLFW_RELEASE && window->key[key] != GLFW_PRESS)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Register key action
|
|
||||||
if(action == GLFW_RELEASE && window->stickyKeys)
|
|
||||||
window->key[key] = GLFW_STICK;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
keyrepeat = (window->key[key] == GLFW_PRESS) && (action == GLFW_PRESS);
|
|
||||||
window->key[key] = (char) action;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call user callback function
|
|
||||||
if (_glfwLibrary.keyCallback && (window->keyRepeat || !keyrepeat))
|
|
||||||
_glfwLibrary.keyCallback(window, key, action);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
|
||||||
// Register (keyboard) character activity
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
void _glfwInputChar(_GLFWwindow* window, int character)
|
|
||||||
{
|
|
||||||
// Valid Unicode (ISO 10646) character?
|
|
||||||
if (!((character >= 32 && character <= 126) || character >= 160))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (_glfwLibrary.charCallback)
|
|
||||||
_glfwLibrary.charCallback(window, character);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
|
||||||
// Register scroll events
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
void _glfwInputScroll(_GLFWwindow* window, int xoffset, int yoffset)
|
|
||||||
{
|
|
||||||
window->scrollX += xoffset;
|
|
||||||
window->scrollY += yoffset;
|
|
||||||
|
|
||||||
if (_glfwLibrary.scrollCallback)
|
|
||||||
_glfwLibrary.scrollCallback(window, xoffset, yoffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
|
||||||
// Register mouse button clicks
|
|
||||||
//========================================================================
|
|
||||||
|
|
||||||
void _glfwInputMouseClick(_GLFWwindow* window, int button, int action)
|
|
||||||
{
|
|
||||||
if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Register mouse button action
|
|
||||||
if (action == GLFW_RELEASE && window->stickyMouseButtons)
|
|
||||||
window->mouseButton[button] = GLFW_STICK;
|
|
||||||
else
|
|
||||||
window->mouseButton[button] = (char) action;
|
|
||||||
|
|
||||||
if (_glfwLibrary.mouseButtonCallback)
|
|
||||||
_glfwLibrary.mouseButtonCallback(window, button, action);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Register window focus events
|
// Register window focus events
|
||||||
//========================================================================
|
//========================================================================
|
||||||
@ -227,6 +148,61 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//========================================================================
|
||||||
|
// Register window position events
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
|
void _glfwInputWindowPos(_GLFWwindow* window, int x, int y)
|
||||||
|
{
|
||||||
|
window->positionX = x;
|
||||||
|
window->positionY = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//========================================================================
|
||||||
|
// Register window size events
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
|
void _glfwInputWindowSize(_GLFWwindow* window, int width, int height)
|
||||||
|
{
|
||||||
|
if (window->width == width && window->height == height)
|
||||||
|
return;
|
||||||
|
|
||||||
|
window->width = width;
|
||||||
|
window->height = height;
|
||||||
|
|
||||||
|
if (_glfwLibrary.windowSizeCallback)
|
||||||
|
_glfwLibrary.windowSizeCallback(window, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//========================================================================
|
||||||
|
// Register window size events
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
|
void _glfwInputWindowIconify(_GLFWwindow* window, int iconified)
|
||||||
|
{
|
||||||
|
if (window->iconified == iconified)
|
||||||
|
return;
|
||||||
|
|
||||||
|
window->iconified = iconified;
|
||||||
|
|
||||||
|
if (_glfwLibrary.windowIconifyCallback)
|
||||||
|
_glfwLibrary.windowIconifyCallback(window, iconified);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//========================================================================
|
||||||
|
// Register window damage events
|
||||||
|
//========================================================================
|
||||||
|
|
||||||
|
void _glfwInputWindowDamage(_GLFWwindow* window)
|
||||||
|
{
|
||||||
|
if (_glfwLibrary.windowRefreshCallback)
|
||||||
|
_glfwLibrary.windowRefreshCallback(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
////// GLFW public API //////
|
////// GLFW public API //////
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
@ -468,6 +444,7 @@ GLFWAPI void glfwOpenWindowHint(int target, int hint)
|
|||||||
_glfwLibrary.hints.glRobustness = hint;
|
_glfwLibrary.hints.glRobustness = hint;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
_glfwSetError(GLFW_INVALID_ENUM, NULL);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -748,12 +725,10 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow handle, int param)
|
|||||||
return window->glProfile;
|
return window->glProfile;
|
||||||
case GLFW_OPENGL_ROBUSTNESS:
|
case GLFW_OPENGL_ROBUSTNESS:
|
||||||
return window->glRobustness;
|
return window->glRobustness;
|
||||||
default:
|
|
||||||
_glfwSetError(GLFW_INVALID_ENUM,
|
|
||||||
"glfwGetWindowParam: Invalid enum value for 'param' "
|
|
||||||
"parameter");
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_glfwSetError(GLFW_INVALID_ENUM, NULL);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -818,6 +793,7 @@ GLFWAPI void glfwSetWindowSizeCallback(GLFWwindowsizefun cbfun)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Set callback function for window close events
|
// Set callback function for window close events
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -48,6 +48,7 @@ void _glfwPlatformEnableSystemKeys(_GLFWwindow* window)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Disable system keys
|
// Disable system keys
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
@ -45,21 +45,16 @@
|
|||||||
int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate)
|
int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate)
|
||||||
{
|
{
|
||||||
int i, match, bestmatch;
|
int i, match, bestmatch;
|
||||||
#if defined(_GLFW_HAS_XRANDR)
|
|
||||||
int sizecount, bestsize;
|
|
||||||
int ratecount, bestrate;
|
|
||||||
short* ratelist;
|
|
||||||
XRRScreenConfiguration* sc;
|
|
||||||
XRRScreenSize* sizelist;
|
|
||||||
#endif /*_GLFW_HAS_XRANDR*/
|
|
||||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
|
||||||
XF86VidModeModeInfo** modelist;
|
|
||||||
int bestmode, modecount;
|
|
||||||
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
|
||||||
|
|
||||||
if (_glfwLibrary.X11.RandR.available)
|
if (_glfwLibrary.X11.RandR.available)
|
||||||
{
|
{
|
||||||
#if defined(_GLFW_HAS_XRANDR)
|
#if defined(_GLFW_HAS_XRANDR)
|
||||||
|
int sizecount, bestsize;
|
||||||
|
int ratecount, bestrate;
|
||||||
|
short* ratelist;
|
||||||
|
XRRScreenConfiguration* sc;
|
||||||
|
XRRScreenSize* sizelist;
|
||||||
|
|
||||||
sc = XRRGetScreenInfo(_glfwLibrary.X11.display,
|
sc = XRRGetScreenInfo(_glfwLibrary.X11.display,
|
||||||
RootWindow(_glfwLibrary.X11.display, screen));
|
RootWindow(_glfwLibrary.X11.display, screen));
|
||||||
|
|
||||||
@ -108,7 +103,6 @@ int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free modelist
|
|
||||||
XRRFreeScreenConfigInfo(sc);
|
XRRFreeScreenConfigInfo(sc);
|
||||||
|
|
||||||
if (bestsize != -1)
|
if (bestsize != -1)
|
||||||
@ -118,6 +112,9 @@ int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate)
|
|||||||
else if (_glfwLibrary.X11.VidMode.available)
|
else if (_glfwLibrary.X11.VidMode.available)
|
||||||
{
|
{
|
||||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
#if defined(_GLFW_HAS_XF86VIDMODE)
|
||||||
|
XF86VidModeModeInfo** modelist;
|
||||||
|
int bestmode, modecount;
|
||||||
|
|
||||||
// Get a list of all available display modes
|
// Get a list of all available display modes
|
||||||
XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen,
|
XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen,
|
||||||
&modecount, &modelist);
|
&modecount, &modelist);
|
||||||
@ -145,7 +142,6 @@ int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate)
|
|||||||
*height = modelist[bestmode]->vdisplay;
|
*height = modelist[bestmode]->vdisplay;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free modelist
|
|
||||||
XFree(modelist);
|
XFree(modelist);
|
||||||
|
|
||||||
if (bestmode != -1)
|
if (bestmode != -1)
|
||||||
@ -167,18 +163,12 @@ 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)
|
||||||
{
|
{
|
||||||
#if defined(_GLFW_HAS_XRANDR)
|
|
||||||
XRRScreenConfiguration* sc;
|
|
||||||
Window root;
|
|
||||||
#endif /*_GLFW_HAS_XRANDR*/
|
|
||||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
|
||||||
XF86VidModeModeInfo **modelist;
|
|
||||||
int modecount;
|
|
||||||
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
|
||||||
|
|
||||||
if (_glfwLibrary.X11.RandR.available)
|
if (_glfwLibrary.X11.RandR.available)
|
||||||
{
|
{
|
||||||
#if defined(_GLFW_HAS_XRANDR)
|
#if defined(_GLFW_HAS_XRANDR)
|
||||||
|
XRRScreenConfiguration* sc;
|
||||||
|
Window root;
|
||||||
|
|
||||||
root = RootWindow(_glfwLibrary.X11.display, screen);
|
root = RootWindow(_glfwLibrary.X11.display, screen);
|
||||||
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, root);
|
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, root);
|
||||||
|
|
||||||
@ -220,6 +210,9 @@ void _glfwSetVideoModeMODE(int screen, int mode, int rate)
|
|||||||
else if (_glfwLibrary.X11.VidMode.available)
|
else if (_glfwLibrary.X11.VidMode.available)
|
||||||
{
|
{
|
||||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
#if defined(_GLFW_HAS_XF86VIDMODE)
|
||||||
|
XF86VidModeModeInfo **modelist;
|
||||||
|
int modecount;
|
||||||
|
|
||||||
// Get a list of all available display modes
|
// Get a list of all available display modes
|
||||||
XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen,
|
XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen,
|
||||||
&modecount, &modelist);
|
&modecount, &modelist);
|
||||||
@ -229,8 +222,7 @@ void _glfwSetVideoModeMODE(int screen, int mode, int rate)
|
|||||||
XF86VidModeLockModeSwitch(_glfwLibrary.X11.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.X11.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.X11.display, screen, 0, 0);
|
XF86VidModeSetViewPort(_glfwLibrary.X11.display, screen, 0, 0);
|
||||||
@ -245,7 +237,6 @@ void _glfwSetVideoModeMODE(int screen, int mode, int rate)
|
|||||||
_glfwLibrary.X11.FS.modeChanged = GL_TRUE;
|
_glfwLibrary.X11.FS.modeChanged = GL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free mode list
|
|
||||||
XFree(modelist);
|
XFree(modelist);
|
||||||
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
||||||
}
|
}
|
||||||
@ -338,21 +329,13 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
|||||||
int viscount, rgbcount, rescount;
|
int viscount, rgbcount, rescount;
|
||||||
int* rgbarray;
|
int* rgbarray;
|
||||||
struct _glfwResolution* resarray;
|
struct _glfwResolution* resarray;
|
||||||
#if defined(_GLFW_HAS_XRANDR)
|
|
||||||
XRRScreenConfiguration* sc;
|
|
||||||
XRRScreenSize* sizelist;
|
|
||||||
int sizecount;
|
|
||||||
#endif /*_GLFW_HAS_XRANDR*/
|
|
||||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
|
||||||
XF86VidModeModeInfo** modelist;
|
|
||||||
int modecount, width, height;
|
|
||||||
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
|
||||||
|
|
||||||
// Get list of visuals
|
// Get list of visuals
|
||||||
vislist = XGetVisualInfo(_glfwLibrary.X11.display, 0, &dummy, &viscount);
|
vislist = XGetVisualInfo(_glfwLibrary.X11.display, 0, &dummy, &viscount);
|
||||||
if (vislist == NULL)
|
if (vislist == NULL)
|
||||||
{
|
{
|
||||||
// TODO: Figure out which error this is
|
_glfwSetError(GLFW_PLATFORM_ERROR,
|
||||||
|
"X11/GLX: Failed to retrieve the available visuals");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,6 +380,10 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
|||||||
if (_glfwLibrary.X11.RandR.available)
|
if (_glfwLibrary.X11.RandR.available)
|
||||||
{
|
{
|
||||||
#if defined(_GLFW_HAS_XRANDR)
|
#if defined(_GLFW_HAS_XRANDR)
|
||||||
|
XRRScreenConfiguration* sc;
|
||||||
|
XRRScreenSize* sizelist;
|
||||||
|
int sizecount;
|
||||||
|
|
||||||
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, _glfwLibrary.X11.root);
|
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, _glfwLibrary.X11.root);
|
||||||
sizelist = XRRConfigSizes(sc, &sizecount);
|
sizelist = XRRConfigSizes(sc, &sizecount);
|
||||||
|
|
||||||
@ -415,6 +402,9 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
|||||||
else if (_glfwLibrary.X11.VidMode.available)
|
else if (_glfwLibrary.X11.VidMode.available)
|
||||||
{
|
{
|
||||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
#if defined(_GLFW_HAS_XF86VIDMODE)
|
||||||
|
XF86VidModeModeInfo** modelist;
|
||||||
|
int modecount, width, height;
|
||||||
|
|
||||||
XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen, &modecount, &modelist);
|
XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen, &modecount, &modelist);
|
||||||
|
|
||||||
resarray = (struct _glfwResolution*) _glfwMalloc(sizeof(struct _glfwResolution) * modecount);
|
resarray = (struct _glfwResolution*) _glfwMalloc(sizeof(struct _glfwResolution) * modecount);
|
||||||
@ -467,7 +457,6 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free visuals list
|
|
||||||
XFree(vislist);
|
XFree(vislist);
|
||||||
|
|
||||||
_glfwFree(resarray);
|
_glfwFree(resarray);
|
||||||
@ -484,15 +473,9 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
|
|||||||
void _glfwPlatformGetDesktopMode(GLFWvidmode* mode)
|
void _glfwPlatformGetDesktopMode(GLFWvidmode* mode)
|
||||||
{
|
{
|
||||||
int bpp;
|
int bpp;
|
||||||
#if defined(_GLFW_HAS_XF86VIDMODE)
|
|
||||||
XF86VidModeModeInfo** modelist;
|
|
||||||
int modecount;
|
|
||||||
#endif /*_GLFW_HAS_XF86VIDMODE*/
|
|
||||||
|
|
||||||
// Get display depth
|
// Get and split display depth
|
||||||
bpp = DefaultDepth(_glfwLibrary.X11.display, _glfwLibrary.X11.screen);
|
bpp = DefaultDepth(_glfwLibrary.X11.display, _glfwLibrary.X11.screen);
|
||||||
|
|
||||||
// Convert BPP to RGB bits
|
|
||||||
_glfwSplitBPP(bpp, &mode->redBits, &mode->greenBits, &mode->blueBits);
|
_glfwSplitBPP(bpp, &mode->redBits, &mode->greenBits, &mode->blueBits);
|
||||||
|
|
||||||
if (_glfwLibrary.X11.FS.modeChanged)
|
if (_glfwLibrary.X11.FS.modeChanged)
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
@ -516,6 +517,7 @@ static void initGammaRamp(void)
|
|||||||
|
|
||||||
// Save the original gamma ramp
|
// Save the original gamma ramp
|
||||||
_glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp);
|
_glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp);
|
||||||
|
_glfwLibrary.currentRamp = _glfwLibrary.originalRamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,6 +41,9 @@
|
|||||||
#define GLX_GLXEXT_LEGACY
|
#define GLX_GLXEXT_LEGACY
|
||||||
#include <GL/glx.h>
|
#include <GL/glx.h>
|
||||||
|
|
||||||
|
// This path may need to be changed if you build GLFW using your own setup
|
||||||
|
// We ship and use our own copy of glxext.h since GLFW uses fairly new
|
||||||
|
// extensions and not all operating systems come with an up-to-date version
|
||||||
#include "../support/GL/glxext.h"
|
#include "../support/GL/glxext.h"
|
||||||
|
|
||||||
|
|
||||||
@ -204,7 +207,7 @@ typedef struct _GLFWlibraryX11
|
|||||||
} Xkb;
|
} Xkb;
|
||||||
|
|
||||||
// Key code LUT (mapping X11 key codes to GLFW key codes)
|
// Key code LUT (mapping X11 key codes to GLFW key codes)
|
||||||
int keyCodeLUT[256];
|
int keyCodeLUT[256];
|
||||||
|
|
||||||
// Screensaver data
|
// Screensaver data
|
||||||
struct {
|
struct {
|
||||||
@ -233,7 +236,7 @@ typedef struct _GLFWlibraryX11
|
|||||||
struct {
|
struct {
|
||||||
GLboolean monotonic;
|
GLboolean monotonic;
|
||||||
double resolution;
|
double resolution;
|
||||||
uint64_t t0;
|
uint64_t base;
|
||||||
} timer;
|
} timer;
|
||||||
|
|
||||||
// Selection data
|
// Selection data
|
||||||
|
@ -78,7 +78,7 @@ void _glfwInitTimer(void)
|
|||||||
_glfwLibrary.X11.timer.resolution = 1e-6;
|
_glfwLibrary.X11.timer.resolution = 1e-6;
|
||||||
}
|
}
|
||||||
|
|
||||||
_glfwLibrary.X11.timer.t0 = getRawTime();
|
_glfwLibrary.X11.timer.base = getRawTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ void _glfwInitTimer(void)
|
|||||||
|
|
||||||
double _glfwPlatformGetTime(void)
|
double _glfwPlatformGetTime(void)
|
||||||
{
|
{
|
||||||
return (double) (getRawTime() - _glfwLibrary.X11.timer.t0) *
|
return (double) (getRawTime() - _glfwLibrary.X11.timer.base) *
|
||||||
_glfwLibrary.X11.timer.resolution;
|
_glfwLibrary.X11.timer.resolution;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,9 +101,9 @@ double _glfwPlatformGetTime(void)
|
|||||||
// Set timer value in seconds
|
// Set timer value in seconds
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
void _glfwPlatformSetTime(double t)
|
void _glfwPlatformSetTime(double time)
|
||||||
{
|
{
|
||||||
_glfwLibrary.X11.timer.t0 = getRawTime() -
|
_glfwLibrary.X11.timer.base = getRawTime() -
|
||||||
(uint64_t) (t / _glfwLibrary.X11.timer.resolution);
|
(uint64_t) (time / _glfwLibrary.X11.timer.resolution);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,6 +206,7 @@ static GLboolean hasEWMH(_GLFWwindow* window)
|
|||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Translates an X Window key to internal coding
|
// Translates an X Window key to internal coding
|
||||||
//========================================================================
|
//========================================================================
|
||||||
@ -974,6 +975,7 @@ static void enterFullscreenMode(_GLFWwindow* window)
|
|||||||
window->width / 2, window->height / 2);
|
window->width / 2, window->height / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//========================================================================
|
//========================================================================
|
||||||
// Leave fullscreen mode
|
// Leave fullscreen mode
|
||||||
//========================================================================
|
//========================================================================
|
||||||
@ -1192,33 +1194,27 @@ static void processSingleEvent(void)
|
|||||||
event.xmotion.y != window->X11.cursorPosY)
|
event.xmotion.y != window->X11.cursorPosY)
|
||||||
{
|
{
|
||||||
// The mouse cursor was moved and we didn't do it
|
// The mouse cursor was moved and we didn't do it
|
||||||
|
int x, y;
|
||||||
|
|
||||||
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
|
||||||
{
|
{
|
||||||
if (_glfwLibrary.activeWindow != window)
|
if (_glfwLibrary.activeWindow != window)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
window->mousePosX += event.xmotion.x -
|
x = event.xmotion.x - window->X11.cursorPosX;
|
||||||
window->X11.cursorPosX;
|
y = event.xmotion.y - window->X11.cursorPosY;
|
||||||
window->mousePosY += event.xmotion.y -
|
|
||||||
window->X11.cursorPosY;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
window->mousePosX = event.xmotion.x;
|
x = event.xmotion.x;
|
||||||
window->mousePosY = event.xmotion.y;
|
y = event.xmotion.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
window->X11.cursorPosX = event.xmotion.x;
|
window->X11.cursorPosX = event.xmotion.x;
|
||||||
window->X11.cursorPosY = event.xmotion.y;
|
window->X11.cursorPosY = event.xmotion.y;
|
||||||
window->X11.cursorCentered = GL_FALSE;
|
window->X11.cursorCentered = GL_FALSE;
|
||||||
|
|
||||||
if (_glfwLibrary.mousePosCallback)
|
_glfwInputCursorMotion(window, x, y);
|
||||||
{
|
|
||||||
_glfwLibrary.mousePosCallback(window,
|
|
||||||
window->mousePosX,
|
|
||||||
window->mousePosY);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -1234,27 +1230,13 @@ static void processSingleEvent(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.xconfigure.width != window->width ||
|
_glfwInputWindowSize(window,
|
||||||
event.xconfigure.height != window->height)
|
event.xconfigure.width,
|
||||||
{
|
event.xconfigure.height);
|
||||||
// The window was resized
|
|
||||||
|
|
||||||
window->width = event.xconfigure.width;
|
_glfwInputWindowPos(window,
|
||||||
window->height = event.xconfigure.height;
|
event.xconfigure.x,
|
||||||
if (_glfwLibrary.windowSizeCallback)
|
event.xconfigure.y);
|
||||||
{
|
|
||||||
_glfwLibrary.windowSizeCallback(window,
|
|
||||||
window->width,
|
|
||||||
window->height);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.xconfigure.x != window->positionX ||
|
|
||||||
event.xconfigure.y != window->positionY)
|
|
||||||
{
|
|
||||||
window->positionX = event.xconfigure.x;
|
|
||||||
window->positionY = event.xconfigure.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1303,11 +1285,7 @@ static void processSingleEvent(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window->iconified = GL_FALSE;
|
_glfwInputWindowIconify(window, GL_FALSE);
|
||||||
|
|
||||||
if (_glfwLibrary.windowIconifyCallback)
|
|
||||||
_glfwLibrary.windowIconifyCallback(window, window->iconified);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1321,11 +1299,7 @@ static void processSingleEvent(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window->iconified = GL_TRUE;
|
_glfwInputWindowIconify(window, GL_TRUE);
|
||||||
|
|
||||||
if (_glfwLibrary.windowIconifyCallback)
|
|
||||||
_glfwLibrary.windowIconifyCallback(window, window->iconified);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1375,9 +1349,7 @@ static void processSingleEvent(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_glfwLibrary.windowRefreshCallback)
|
_glfwInputWindowDamage(window);
|
||||||
_glfwLibrary.windowRefreshCallback(window);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1520,8 +1492,8 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
|
|||||||
|
|
||||||
// TODO: Probably check for some corner cases here.
|
// TODO: Probably check for some corner cases here.
|
||||||
|
|
||||||
window->mousePosX = windowX;
|
window->cursorPosX = windowX;
|
||||||
window->mousePosY = windowY;
|
window->cursorPosY = windowY;
|
||||||
}
|
}
|
||||||
|
|
||||||
return GL_TRUE;
|
return GL_TRUE;
|
||||||
|
@ -11,12 +11,12 @@ add_executable(events events.c)
|
|||||||
add_executable(fsaa fsaa.c getopt.c)
|
add_executable(fsaa fsaa.c getopt.c)
|
||||||
add_executable(fsfocus fsfocus.c)
|
add_executable(fsfocus fsfocus.c)
|
||||||
add_executable(gamma gamma.c getopt.c)
|
add_executable(gamma gamma.c getopt.c)
|
||||||
|
add_executable(glfwinfo glfwinfo.c getopt.c)
|
||||||
add_executable(iconify iconify.c getopt.c)
|
add_executable(iconify iconify.c getopt.c)
|
||||||
add_executable(joysticks joysticks.c)
|
add_executable(joysticks joysticks.c)
|
||||||
add_executable(listmodes listmodes.c)
|
add_executable(listmodes listmodes.c)
|
||||||
add_executable(peter peter.c)
|
add_executable(peter peter.c)
|
||||||
add_executable(reopen reopen.c)
|
add_executable(reopen reopen.c)
|
||||||
add_executable(version version.c getopt.c)
|
|
||||||
|
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
# Set fancy names for bundles
|
# Set fancy names for bundles
|
||||||
@ -33,8 +33,8 @@ else()
|
|||||||
endif(APPLE)
|
endif(APPLE)
|
||||||
|
|
||||||
set(WINDOWS_BINARIES accuracy sharing tearing windows)
|
set(WINDOWS_BINARIES accuracy sharing tearing windows)
|
||||||
set(CONSOLE_BINARIES clipboard defaults events fsaa fsfocus gamma iconify
|
set(CONSOLE_BINARIES clipboard defaults events fsaa fsfocus gamma glfwinfo iconify
|
||||||
joysticks listmodes peter reopen version)
|
joysticks listmodes peter reopen)
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
# Tell MSVC to use main instead of WinMain for Windows subsystem executables
|
# Tell MSVC to use main instead of WinMain for Windows subsystem executables
|
||||||
|
@ -78,17 +78,10 @@ int main(void)
|
|||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
glClearColor(0, 0, 0, 0);
|
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
|
||||||
glLoadIdentity();
|
|
||||||
|
|
||||||
while (glfwIsWindow(window))
|
while (glfwIsWindow(window))
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
glColor3f(1.f, 1.f, 1.f);
|
|
||||||
|
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
glVertex2f(0.f, (GLfloat) window_height - cursor_y);
|
glVertex2f(0.f, (GLfloat) window_height - cursor_y);
|
||||||
glVertex2f((GLfloat) window_width, (GLfloat) window_height - cursor_y);
|
glVertex2f((GLfloat) window_width, (GLfloat) window_height - cursor_y);
|
||||||
|
@ -132,8 +132,6 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
glColor3f(1.f, 1.f, 1.f);
|
|
||||||
|
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glTranslatef(0.25f, 0.25f, 0.f);
|
glTranslatef(0.25f, 0.25f, 0.f);
|
||||||
glRotatef(time, 0.f, 0.f, 1.f);
|
glRotatef(time, 0.f, 0.f, 1.f);
|
||||||
|
@ -32,21 +32,28 @@
|
|||||||
#include <GL/glfw3.h>
|
#include <GL/glfw3.h>
|
||||||
#include <GL/glext.h>
|
#include <GL/glext.h>
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
#define strcasecmp(x, y) _stricmp(x, y)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "getopt.h"
|
#include "getopt.h"
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define strcasecmp(x, y) _stricmp(x, y)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define PROFILE_NAME_CORE "core"
|
||||||
|
#define PROFILE_NAME_COMPAT "compat"
|
||||||
|
#define PROFILE_NAME_ES2 "es2"
|
||||||
|
|
||||||
|
#define STRATEGY_NAME_NONE "none"
|
||||||
|
#define STRATEGY_NAME_LOSE "lose"
|
||||||
|
|
||||||
static void usage(void)
|
static void usage(void)
|
||||||
{
|
{
|
||||||
printf("Usage: version [-h] [-m MAJOR] [-n MINOR] [-d] [-l] [-f] [-p PROFILE] [-r STRATEGY]\n");
|
printf("Usage: version [-h] [-m MAJOR] [-n MINOR] [-d] [-l] [-f] [-p PROFILE] [-r STRATEGY]\n");
|
||||||
printf("available profiles: core compat es2\n");
|
printf("available profiles: " PROFILE_NAME_CORE " " PROFILE_NAME_COMPAT " " PROFILE_NAME_ES2 "\n");
|
||||||
printf("available strategies: none lose\n");
|
printf("available strategies: " STRATEGY_NAME_NONE " " STRATEGY_NAME_LOSE "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void error_callback(int error, const char* description)
|
static void error_callback(int error, const char* description)
|
||||||
@ -57,11 +64,11 @@ static void error_callback(int error, const char* description)
|
|||||||
static const char* get_glfw_profile_name(int profile)
|
static const char* get_glfw_profile_name(int profile)
|
||||||
{
|
{
|
||||||
if (profile == GLFW_OPENGL_COMPAT_PROFILE)
|
if (profile == GLFW_OPENGL_COMPAT_PROFILE)
|
||||||
return "compatibility";
|
return PROFILE_NAME_COMPAT;
|
||||||
else if (profile == GLFW_OPENGL_CORE_PROFILE)
|
else if (profile == GLFW_OPENGL_CORE_PROFILE)
|
||||||
return "core";
|
return PROFILE_NAME_CORE;
|
||||||
else if (profile == GLFW_OPENGL_ES2_PROFILE)
|
else if (profile == GLFW_OPENGL_ES2_PROFILE)
|
||||||
return "es2";
|
return PROFILE_NAME_ES2;
|
||||||
|
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
@ -69,9 +76,9 @@ static const char* get_glfw_profile_name(int profile)
|
|||||||
static const char* get_profile_name(GLint mask)
|
static const char* get_profile_name(GLint mask)
|
||||||
{
|
{
|
||||||
if (mask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT)
|
if (mask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT)
|
||||||
return "compatibility";
|
return PROFILE_NAME_COMPAT;
|
||||||
if (mask & GL_CONTEXT_CORE_PROFILE_BIT)
|
if (mask & GL_CONTEXT_CORE_PROFILE_BIT)
|
||||||
return "core";
|
return PROFILE_NAME_CORE;
|
||||||
|
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
@ -142,11 +149,11 @@ int main(int argc, char** argv)
|
|||||||
minor = atoi(optarg);
|
minor = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
if (strcasecmp(optarg, "core") == 0)
|
if (strcasecmp(optarg, PROFILE_NAME_CORE) == 0)
|
||||||
profile = GLFW_OPENGL_CORE_PROFILE;
|
profile = GLFW_OPENGL_CORE_PROFILE;
|
||||||
else if (strcasecmp(optarg, "compat") == 0)
|
else if (strcasecmp(optarg, PROFILE_NAME_COMPAT) == 0)
|
||||||
profile = GLFW_OPENGL_COMPAT_PROFILE;
|
profile = GLFW_OPENGL_COMPAT_PROFILE;
|
||||||
else if (strcasecmp(optarg, "es2") == 0)
|
else if (strcasecmp(optarg, PROFILE_NAME_ES2) == 0)
|
||||||
profile = GLFW_OPENGL_ES2_PROFILE;
|
profile = GLFW_OPENGL_ES2_PROFILE;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -155,9 +162,9 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
if (strcasecmp(optarg, "none") == 0)
|
if (strcasecmp(optarg, STRATEGY_NAME_NONE) == 0)
|
||||||
strategy = GLFW_OPENGL_NO_RESET_NOTIFICATION;
|
strategy = GLFW_OPENGL_NO_RESET_NOTIFICATION;
|
||||||
else if (strcasecmp(optarg, "lose") == 0)
|
else if (strcasecmp(optarg, STRATEGY_NAME_LOSE) == 0)
|
||||||
strategy = GLFW_OPENGL_LOSE_CONTEXT_ON_RESET;
|
strategy = GLFW_OPENGL_LOSE_CONTEXT_ON_RESET;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -221,7 +228,9 @@ int main(int argc, char** argv)
|
|||||||
if (major != GLFW_VERSION_MAJOR ||
|
if (major != GLFW_VERSION_MAJOR ||
|
||||||
minor != GLFW_VERSION_MINOR ||
|
minor != GLFW_VERSION_MINOR ||
|
||||||
revision != GLFW_VERSION_REVISION)
|
revision != GLFW_VERSION_REVISION)
|
||||||
|
{
|
||||||
printf("*** WARNING: GLFW version mismatch! ***\n");
|
printf("*** WARNING: GLFW version mismatch! ***\n");
|
||||||
|
}
|
||||||
|
|
||||||
printf("GLFW library version string: \"%s\"\n", glfwGetVersionString());
|
printf("GLFW library version string: \"%s\"\n", glfwGetVersionString());
|
||||||
|
|
||||||
@ -266,7 +275,7 @@ int main(int argc, char** argv)
|
|||||||
if (major > 1)
|
if (major > 1)
|
||||||
{
|
{
|
||||||
printf("OpenGL context shading language version: \"%s\"\n",
|
printf("OpenGL context shading language version: \"%s\"\n",
|
||||||
glGetString(GL_SHADING_LANGUAGE_VERSION));
|
glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Report OpenGL extensions
|
// Report OpenGL extensions
|
@ -37,22 +37,32 @@
|
|||||||
|
|
||||||
static GLboolean cursor_captured = GL_FALSE;
|
static GLboolean cursor_captured = GL_FALSE;
|
||||||
static GLFWwindow window_handle = NULL;
|
static GLFWwindow window_handle = NULL;
|
||||||
|
static int cursor_x;
|
||||||
|
static int cursor_y;
|
||||||
|
|
||||||
static GLboolean open_window(void);
|
static GLboolean open_window(void);
|
||||||
|
|
||||||
static void toggle_mouse_cursor(GLFWwindow window)
|
static void toggle_mouse_cursor(GLFWwindow window)
|
||||||
{
|
{
|
||||||
if (cursor_captured)
|
if (cursor_captured)
|
||||||
|
{
|
||||||
|
printf("Released cursor\n");
|
||||||
glfwSetCursorMode(window, GLFW_CURSOR_NORMAL);
|
glfwSetCursorMode(window, GLFW_CURSOR_NORMAL);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
printf("Captured cursor\n");
|
||||||
glfwSetCursorMode(window, GLFW_CURSOR_CAPTURED);
|
glfwSetCursorMode(window, GLFW_CURSOR_CAPTURED);
|
||||||
|
}
|
||||||
|
|
||||||
cursor_captured = !cursor_captured;
|
cursor_captured = !cursor_captured;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mouse_position_callback(GLFWwindow window, int x, int y)
|
static void mouse_position_callback(GLFWwindow window, int x, int y)
|
||||||
{
|
{
|
||||||
printf("Mouse moved to: %i %i\n", x, y);
|
printf("Mouse moved to: %i %i (%i %i)\n", x, y, x - cursor_x, y - cursor_y);
|
||||||
|
cursor_x = x;
|
||||||
|
cursor_y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void key_callback(GLFWwindow window, int key, int action)
|
static void key_callback(GLFWwindow window, int key, int action)
|
||||||
@ -87,14 +97,12 @@ static void window_size_callback(GLFWwindow window, int width, int height)
|
|||||||
|
|
||||||
static GLboolean open_window(void)
|
static GLboolean open_window(void)
|
||||||
{
|
{
|
||||||
int x, y;
|
|
||||||
|
|
||||||
window_handle = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Peter Detector", NULL);
|
window_handle = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Peter Detector", NULL);
|
||||||
if (!window_handle)
|
if (!window_handle)
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
|
|
||||||
glfwGetMousePos(window_handle, &x, &y);
|
glfwGetMousePos(window_handle, &cursor_x, &cursor_y);
|
||||||
printf("Mouse position: %i %i\n", x, y);
|
printf("Mouse position: %i %i\n", cursor_x, cursor_y);
|
||||||
|
|
||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
glfwSetMousePosCallback(mouse_position_callback);
|
glfwSetMousePosCallback(mouse_position_callback);
|
||||||
|
@ -62,7 +62,7 @@ static void window_size_callback(GLFWwindow window, int width, int height)
|
|||||||
static int window_close_callback(GLFWwindow window)
|
static int window_close_callback(GLFWwindow window)
|
||||||
{
|
{
|
||||||
printf("Close callback triggered\n");
|
printf("Close callback triggered\n");
|
||||||
window_handle = NULL;
|
closed = GL_TRUE;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,9 +136,6 @@ int main(int argc, char** argv)
|
|||||||
glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f);
|
glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
|
||||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
|
||||||
glColor3f(1.f, 1.f, 1.f);
|
|
||||||
|
|
||||||
glfwSetTime(0.0);
|
glfwSetTime(0.0);
|
||||||
|
|
||||||
while (glfwGetTime() < 5.0)
|
while (glfwGetTime() < 5.0)
|
||||||
|
@ -62,9 +62,6 @@ int main(void)
|
|||||||
glfwSetWindowSizeCallback(window_size_callback);
|
glfwSetWindowSizeCallback(window_size_callback);
|
||||||
glfwSwapInterval(1);
|
glfwSwapInterval(1);
|
||||||
|
|
||||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
|
||||||
glColor3f(1.f, 1.f, 1.f);
|
|
||||||
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f);
|
glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f);
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
|
@ -66,7 +66,10 @@ int main(void)
|
|||||||
|
|
||||||
glfwSetWindowPos(windows[i], 100 + (i & 1) * 300, 100 + (i >> 1) * 300);
|
glfwSetWindowPos(windows[i], 100 + (i & 1) * 300, 100 + (i >> 1) * 300);
|
||||||
|
|
||||||
glClearColor((GLclampf) (i & 1), (GLclampf) (i >> 1), 0.0, 0.0);
|
glClearColor((GLclampf) (i & 1),
|
||||||
|
(GLclampf) (i >> 1),
|
||||||
|
i ? 0.0 : 1.0,
|
||||||
|
0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (running)
|
while (running)
|
||||||
|
Loading…
Reference in New Issue
Block a user