Merge branch 'master' of github.com:raedwulf/glfw into clipboard

Conflicts:
	tests/CMakeLists.txt
This commit is contained in:
Tai Chi Minh Ralph Eastwood 2012-02-19 06:17:52 +00:00
commit d561e3a0b0
26 changed files with 419 additions and 360 deletions

View File

@ -287,6 +287,7 @@ version of GLFW.</p>
<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_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 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>
@ -302,7 +303,7 @@ version of GLFW.</p>
<li>Removed <code>GLFW_OPENED</code> window parameter</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>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 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>

View File

@ -228,6 +228,7 @@ int _glfwPlatformInit(void)
// Save the original gamma ramp
_glfwLibrary.originalRampSize = CGDisplayGammaTableCapacity(CGMainDisplayID());
_glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp);
_glfwLibrary.currentRamp = _glfwLibrary.originalRamp;
return GL_TRUE;
}

View File

@ -67,11 +67,8 @@
NSRect contentRect =
[window->NS.window contentRectForFrameRect:[window->NS.window frame]];
window->width = contentRect.size.width;
window->height = contentRect.size.height;
if (_glfwLibrary.windowSizeCallback)
_glfwLibrary.windowSizeCallback(window, window->width, window->height);
_glfwInputWindowSize(window, contentRect.size.width, contentRect.size.height);
}
- (void)windowDidMove:(NSNotification *)notification
@ -87,24 +84,17 @@
mainScreenHeight - contentRect.origin.y -
mainScreenOrigin.y - window->height);
window->positionX = flippedPos.x;
window->positionY = flippedPos.y;
_glfwInputWindowPos(window, flippedPos.x, flippedPos.y);
}
- (void)windowDidMiniaturize:(NSNotification *)notification
{
window->iconified = GL_TRUE;
if (_glfwLibrary.windowIconifyCallback)
_glfwLibrary.windowIconifyCallback(window, window->iconified);
_glfwInputWindowIconify(window, GL_TRUE);
}
- (void)windowDidDeminiaturize:(NSNotification *)notification
{
window->iconified = GL_FALSE;
if (_glfwLibrary.windowIconifyCallback)
_glfwLibrary.windowIconifyCallback(window, window->iconified);
_glfwInputWindowIconify(window, GL_FALSE);
}
- (void)windowDidBecomeKey:(NSNotification *)notification
@ -349,24 +339,15 @@ static int convertMacKeyCode(unsigned int macKeyCode)
- (void)mouseMoved:(NSEvent *)event
{
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{
window->mousePosX += [event deltaX];
window->mousePosY += [event deltaY];
}
_glfwInputCursorMotion(window, [event deltaX], [event deltaY]);
else
{
NSPoint p = [event locationInWindow];
// Cocoa coordinate system has origin at lower left
window->mousePosX = p.x;
window->mousePosY = [[window->NS.window contentView] bounds].size.height - p.y;
}
p.y = [[window->NS.window contentView] bounds].size.height - p.y;
if (_glfwLibrary.mousePosCallback)
{
_glfwLibrary.mousePosCallback(window,
window->mousePosX,
window->mousePosY);
_glfwInputCursorMotion(window, p.x, p.y);
}
}
@ -707,8 +688,8 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
glfwMakeContextCurrent(window);
NSPoint point = [[NSCursor currentCursor] hotSpot];
window->mousePosX = point.x;
window->mousePosY = point.y;
window->cursorPosX = point.x;
window->cursorPosY = point.y;
window->windowNoResize = wndconfig->windowNoResize;

View File

@ -152,6 +152,7 @@ GLFWAPI void glfwEnable(GLFWwindow window, int token)
enableKeyRepeat(window);
break;
default:
_glfwSetError(GLFW_INVALID_ENUM, NULL);
break;
}
}
@ -184,6 +185,7 @@ GLFWAPI void glfwDisable(GLFWwindow window, int token)
disableKeyRepeat(window);
break;
default:
_glfwSetError(GLFW_INVALID_ENUM, NULL);
break;
}
}

View File

@ -110,9 +110,18 @@ GLFWAPI int glfwGetVideoModes(GLFWvidmode* list, int maxcount)
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;
}

View File

@ -31,6 +31,119 @@
#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 //////
//////////////////////////////////////////////////////////////////////////
@ -53,7 +166,7 @@ GLFWAPI int glfwGetKey(GLFWwindow handle, int key)
if (key < 0 || key > GLFW_KEY_LAST)
{
// TODO: Decide whether key is a value or enum
_glfwSetError(GLFW_INVALID_VALUE,
_glfwSetError(GLFW_INVALID_ENUM,
"glfwGetKey: The specified key is invalid");
return GLFW_RELEASE;
}
@ -118,10 +231,10 @@ GLFWAPI void glfwGetMousePos(GLFWwindow handle, int* xpos, int* ypos)
// Return mouse position
if (xpos != NULL)
*xpos = window->mousePosX;
*xpos = window->cursorPosX;
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
if (xpos == window->mousePosX && ypos == window->mousePosY)
if (xpos == window->cursorPosX && ypos == window->cursorPosY)
return;
// Set GLFW mouse position
window->mousePosX = xpos;
window->mousePosY = ypos;
window->cursorPosX = xpos;
window->cursorPosY = ypos;
// Do not move physical cursor in locked cursor mode
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)
{
int centerPosX, centerPosY;
_GLFWwindow* window = (_GLFWwindow*) handle;
if (!_glfwInitialized)
@ -210,29 +324,17 @@ GLFWAPI void glfwSetCursorMode(GLFWwindow handle, int mode)
if (window->cursorMode == mode)
return;
int centerPosX = window->width / 2;
int centerPosY = window->height / 2;
centerPosX = window->width / 2;
centerPosY = window->height / 2;
if (mode == GLFW_CURSOR_CAPTURED)
{
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
}
else if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{
if (centerPosX != window->mousePosX || centerPosY != window->mousePosY)
{
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
window->mousePosX = centerPosX;
window->mousePosY = centerPosY;
if (_glfwLibrary.mousePosCallback)
{
_glfwLibrary.mousePosCallback(window,
window->mousePosX,
window->mousePosY);
}
}
_glfwInputCursorMotion(window,
centerPosX - window->cursorPosX,
centerPosY - window->cursorPosY);
}
_glfwPlatformSetCursorMode(window, mode);
@ -311,7 +413,7 @@ GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun)
_GLFWwindow* window;
for (window = _glfwLibrary.windowListHead; window; window = window->next)
cbfun(window, window->mousePosX, window->mousePosY);
cbfun(window, window->cursorPosX, window->cursorPosY);
}
}

View File

@ -59,6 +59,10 @@
#include "config.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"
#if defined(_GLFW_COCOA_NSGL)
@ -180,7 +184,7 @@ struct _GLFWwindow
GLboolean stickyMouseButtons;
GLboolean keyRepeat;
GLboolean sysKeysDisabled; // system keys disabled flag
int mousePosX, mousePosY;
int cursorPosX, cursorPosY;
int cursorMode;
int scrollX, scrollY;
char mouseButton[GLFW_MOUSE_BUTTON_LAST + 1];
@ -339,12 +343,19 @@ void _glfwSetError(int error, const char* description);
// Window management (window.c)
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 _glfwInputChar(_GLFWwindow* window, int character);
void _glfwInputScroll(_GLFWwindow* window, int x, int y);
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)
int _glfwStringInExtensionString(const char* string, const GLubyte* extensions);

View File

@ -345,6 +345,7 @@ GLboolean _glfwIsValidContextConfig(_GLFWwndconfig* wndconfig)
return GL_TRUE;
}
//========================================================================
// Checks whether the specified context fulfils the requirements
// It blames glfwOpenWindow because that's the only caller

View File

@ -163,6 +163,7 @@ int _glfwPlatformInit(void)
// Save the original gamma ramp
_glfwLibrary.originalRampSize = 256;
_glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp);
_glfwLibrary.currentRamp = _glfwLibrary.originalRamp;
_glfwInitTimer();

View File

@ -43,6 +43,9 @@
#include <windows.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"
@ -251,7 +254,7 @@ typedef struct _GLFWwindowWin32
// Various platform specific internal variables
int desiredRefreshRate; // Desired vertical monitor refresh rate
GLboolean mouseMoved;
GLboolean cursorCentered;
int oldMouseX, oldMouseY;
} _GLFWwindowWin32;

View File

@ -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
//========================================================================
@ -808,15 +852,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
}
_glfwInputWindowFocus(window, active);
if (iconified != window->iconified)
{
window->iconified = iconified;
if (_glfwLibrary.windowIconifyCallback)
_glfwLibrary.windowIconifyCallback(window, window->iconified);
}
_glfwInputWindowIconify(window, iconified);
return 0;
}
@ -962,32 +998,27 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
if (newMouseX != window->Win32.oldMouseX ||
newMouseY != window->Win32.oldMouseY)
{
int x, y;
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{
if (_glfwLibrary.activeWindow != window)
return 0;
window->mousePosX += newMouseX -
window->Win32.oldMouseX;
window->mousePosY += newMouseY -
window->Win32.oldMouseY;
x = newMouseX - window->Win32.oldMouseX;
y = newMouseY - window->Win32.oldMouseY;
}
else
{
window->mousePosX = newMouseX;
window->mousePosY = newMouseY;
x = newMouseX;
y = newMouseY;
}
window->Win32.oldMouseX = newMouseX;
window->Win32.oldMouseY = newMouseY;
window->Win32.cursorCentered = GL_FALSE;
if (_glfwLibrary.mousePosCallback)
{
_glfwLibrary.mousePosCallback(window,
window->mousePosX,
window->mousePosY);
}
_glfwInputCursorMotion(window, x, y);
}
return 0;
@ -1009,9 +1040,6 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
case WM_SIZE:
{
window->width = LOWORD(lParam);
window->height = HIWORD(lParam);
// If window is in cursor capture mode, update clipping rect
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{
@ -1020,21 +1048,12 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
ClipCursor(&ClipWindowRect);
}
if (_glfwLibrary.windowSizeCallback)
{
_glfwLibrary.windowSizeCallback(window,
window->width,
window->height);
}
_glfwInputWindowSize(window, LOWORD(lParam), HIWORD(lParam));
return 0;
}
case WM_MOVE:
{
window->positionX = LOWORD(lParam);
window->positionY = HIWORD(lParam);
// If window is in cursor capture mode, update clipping rect
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{
@ -1042,15 +1061,15 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
if (GetWindowRect(window->Win32.handle, &ClipWindowRect))
ClipCursor(&ClipWindowRect);
}
_glfwInputWindowPos(window, LOWORD(lParam), HIWORD(lParam));
return 0;
}
// Was the window contents damaged?
case WM_PAINT:
{
if (_glfwLibrary.windowRefreshCallback)
_glfwLibrary.windowRefreshCallback(window);
_glfwInputWindowDamage(window);
break;
}
@ -1352,8 +1371,8 @@ static int createWindow(_GLFWwindow* window,
// Initialize mouse position data
GetCursorPos(&pos);
ScreenToClient(window->Win32.handle, &pos);
window->Win32.oldMouseX = window->mousePosX = pos.x;
window->Win32.oldMouseY = window->mousePosY = pos.y;
window->Win32.oldMouseX = window->cursorPosX = pos.x;
window->Win32.oldMouseY = window->cursorPosY = pos.y;
return GL_TRUE;
}
@ -1761,14 +1780,14 @@ void _glfwPlatformPollEvents(void)
window = _glfwLibrary.activeWindow;
if (window)
{
window->Win32.mouseMoved = GL_FALSE;
window->Win32.cursorCentered = GL_FALSE;
window->Win32.oldMouseX = window->width / 2;
window->Win32.oldMouseY = window->height / 2;
}
else
{
//window->Win32.oldMouseX = window->mousePosX;
//window->Win32.oldMouseY = window->mousePosY;
//window->Win32.oldMouseX = window->cursorPosX;
//window->Win32.oldMouseY = window->cursorPosY;
}
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
//========================================================================
@ -1897,3 +1881,24 @@ void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int 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;
}
}

View File

@ -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
//========================================================================
@ -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 //////
//////////////////////////////////////////////////////////////////////////
@ -468,6 +444,7 @@ GLFWAPI void glfwOpenWindowHint(int target, int hint)
_glfwLibrary.hints.glRobustness = hint;
break;
default:
_glfwSetError(GLFW_INVALID_ENUM, NULL);
break;
}
}
@ -748,12 +725,10 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow handle, int param)
return window->glProfile;
case GLFW_OPENGL_ROBUSTNESS:
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
//========================================================================

View File

@ -48,6 +48,7 @@ void _glfwPlatformEnableSystemKeys(_GLFWwindow* window)
}
}
//========================================================================
// Disable system keys
//========================================================================

View File

@ -45,21 +45,16 @@
int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate)
{
int i, match, bestmatch;
if (_glfwLibrary.X11.RandR.available)
{
#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 defined(_GLFW_HAS_XRANDR)
sc = XRRGetScreenInfo(_glfwLibrary.X11.display,
RootWindow(_glfwLibrary.X11.display, screen));
@ -108,7 +103,6 @@ int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate)
}
}
// Free modelist
XRRFreeScreenConfigInfo(sc);
if (bestsize != -1)
@ -118,6 +112,9 @@ int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate)
else if (_glfwLibrary.X11.VidMode.available)
{
#if defined(_GLFW_HAS_XF86VIDMODE)
XF86VidModeModeInfo** modelist;
int bestmode, modecount;
// Get a list of all available display modes
XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen,
&modecount, &modelist);
@ -145,7 +142,6 @@ int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate)
*height = modelist[bestmode]->vdisplay;
}
// Free modelist
XFree(modelist);
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)
{
#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 defined(_GLFW_HAS_XRANDR)
XRRScreenConfiguration* sc;
Window root;
root = RootWindow(_glfwLibrary.X11.display, screen);
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, root);
@ -220,6 +210,9 @@ void _glfwSetVideoModeMODE(int screen, int mode, int rate)
else if (_glfwLibrary.X11.VidMode.available)
{
#if defined(_GLFW_HAS_XF86VIDMODE)
XF86VidModeModeInfo **modelist;
int modecount;
// Get a list of all available display modes
XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen,
&modecount, &modelist);
@ -229,8 +222,7 @@ void _glfwSetVideoModeMODE(int screen, int mode, int rate)
XF86VidModeLockModeSwitch(_glfwLibrary.X11.display, screen, 0);
// Change the video mode to the desired mode
XF86VidModeSwitchToMode(_glfwLibrary.X11.display, screen,
modelist[mode]);
XF86VidModeSwitchToMode(_glfwLibrary.X11.display, screen, modelist[mode]);
// Set viewport to upper left corner (where our window will be)
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;
}
// Free mode list
XFree(modelist);
#endif /*_GLFW_HAS_XF86VIDMODE*/
}
@ -338,21 +329,13 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
int viscount, rgbcount, rescount;
int* rgbarray;
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
vislist = XGetVisualInfo(_glfwLibrary.X11.display, 0, &dummy, &viscount);
if (vislist == NULL)
{
// TODO: Figure out which error this is
_glfwSetError(GLFW_PLATFORM_ERROR,
"X11/GLX: Failed to retrieve the available visuals");
return 0;
}
@ -397,6 +380,10 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
if (_glfwLibrary.X11.RandR.available)
{
#if defined(_GLFW_HAS_XRANDR)
XRRScreenConfiguration* sc;
XRRScreenSize* sizelist;
int sizecount;
sc = XRRGetScreenInfo(_glfwLibrary.X11.display, _glfwLibrary.X11.root);
sizelist = XRRConfigSizes(sc, &sizecount);
@ -415,6 +402,9 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
else if (_glfwLibrary.X11.VidMode.available)
{
#if defined(_GLFW_HAS_XF86VIDMODE)
XF86VidModeModeInfo** modelist;
int modecount, width, height;
XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen, &modecount, &modelist);
resarray = (struct _glfwResolution*) _glfwMalloc(sizeof(struct _glfwResolution) * modecount);
@ -467,7 +457,6 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
}
}
// Free visuals list
XFree(vislist);
_glfwFree(resarray);
@ -484,15 +473,9 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount)
void _glfwPlatformGetDesktopMode(GLFWvidmode* mode)
{
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);
// Convert BPP to RGB bits
_glfwSplitBPP(bpp, &mode->redBits, &mode->greenBits, &mode->blueBits);
if (_glfwLibrary.X11.FS.modeChanged)

View File

@ -32,6 +32,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//========================================================================
@ -516,6 +517,7 @@ static void initGammaRamp(void)
// Save the original gamma ramp
_glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp);
_glfwLibrary.currentRamp = _glfwLibrary.originalRamp;
}

View File

@ -41,6 +41,9 @@
#define GLX_GLXEXT_LEGACY
#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"
@ -233,7 +236,7 @@ typedef struct _GLFWlibraryX11
struct {
GLboolean monotonic;
double resolution;
uint64_t t0;
uint64_t base;
} timer;
// Selection data

View File

@ -78,7 +78,7 @@ void _glfwInitTimer(void)
_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)
{
return (double) (getRawTime() - _glfwLibrary.X11.timer.t0) *
return (double) (getRawTime() - _glfwLibrary.X11.timer.base) *
_glfwLibrary.X11.timer.resolution;
}
@ -101,9 +101,9 @@ double _glfwPlatformGetTime(void)
// Set timer value in seconds
//========================================================================
void _glfwPlatformSetTime(double t)
void _glfwPlatformSetTime(double time)
{
_glfwLibrary.X11.timer.t0 = getRawTime() -
(uint64_t) (t / _glfwLibrary.X11.timer.resolution);
_glfwLibrary.X11.timer.base = getRawTime() -
(uint64_t) (time / _glfwLibrary.X11.timer.resolution);
}

View File

@ -206,6 +206,7 @@ static GLboolean hasEWMH(_GLFWwindow* window)
return GL_TRUE;
}
//========================================================================
// Translates an X Window key to internal coding
//========================================================================
@ -974,6 +975,7 @@ static void enterFullscreenMode(_GLFWwindow* window)
window->width / 2, window->height / 2);
}
//========================================================================
// Leave fullscreen mode
//========================================================================
@ -1192,33 +1194,27 @@ static void processSingleEvent(void)
event.xmotion.y != window->X11.cursorPosY)
{
// The mouse cursor was moved and we didn't do it
int x, y;
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{
if (_glfwLibrary.activeWindow != window)
break;
window->mousePosX += event.xmotion.x -
window->X11.cursorPosX;
window->mousePosY += event.xmotion.y -
window->X11.cursorPosY;
x = event.xmotion.x - window->X11.cursorPosX;
y = event.xmotion.y - window->X11.cursorPosY;
}
else
{
window->mousePosX = event.xmotion.x;
window->mousePosY = event.xmotion.y;
x = event.xmotion.x;
y = event.xmotion.y;
}
window->X11.cursorPosX = event.xmotion.x;
window->X11.cursorPosY = event.xmotion.y;
window->X11.cursorCentered = GL_FALSE;
if (_glfwLibrary.mousePosCallback)
{
_glfwLibrary.mousePosCallback(window,
window->mousePosX,
window->mousePosY);
}
_glfwInputCursorMotion(window, x, y);
}
break;
@ -1234,27 +1230,13 @@ static void processSingleEvent(void)
return;
}
if (event.xconfigure.width != window->width ||
event.xconfigure.height != window->height)
{
// The window was resized
_glfwInputWindowSize(window,
event.xconfigure.width,
event.xconfigure.height);
window->width = event.xconfigure.width;
window->height = event.xconfigure.height;
if (_glfwLibrary.windowSizeCallback)
{
_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;
}
_glfwInputWindowPos(window,
event.xconfigure.x,
event.xconfigure.y);
break;
}
@ -1303,11 +1285,7 @@ static void processSingleEvent(void)
return;
}
window->iconified = GL_FALSE;
if (_glfwLibrary.windowIconifyCallback)
_glfwLibrary.windowIconifyCallback(window, window->iconified);
_glfwInputWindowIconify(window, GL_FALSE);
break;
}
@ -1321,11 +1299,7 @@ static void processSingleEvent(void)
return;
}
window->iconified = GL_TRUE;
if (_glfwLibrary.windowIconifyCallback)
_glfwLibrary.windowIconifyCallback(window, window->iconified);
_glfwInputWindowIconify(window, GL_TRUE);
break;
}
@ -1375,9 +1349,7 @@ static void processSingleEvent(void)
return;
}
if (_glfwLibrary.windowRefreshCallback)
_glfwLibrary.windowRefreshCallback(window);
_glfwInputWindowDamage(window);
break;
}
@ -1520,8 +1492,8 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
// TODO: Probably check for some corner cases here.
window->mousePosX = windowX;
window->mousePosY = windowY;
window->cursorPosX = windowX;
window->cursorPosY = windowY;
}
return GL_TRUE;

View File

@ -11,12 +11,12 @@ add_executable(events events.c)
add_executable(fsaa fsaa.c getopt.c)
add_executable(fsfocus fsfocus.c)
add_executable(gamma gamma.c getopt.c)
add_executable(glfwinfo glfwinfo.c getopt.c)
add_executable(iconify iconify.c getopt.c)
add_executable(joysticks joysticks.c)
add_executable(listmodes listmodes.c)
add_executable(peter peter.c)
add_executable(reopen reopen.c)
add_executable(version version.c getopt.c)
if(APPLE)
# Set fancy names for bundles
@ -33,8 +33,8 @@ else()
endif(APPLE)
set(WINDOWS_BINARIES accuracy sharing tearing windows)
set(CONSOLE_BINARIES clipboard defaults events fsaa fsfocus gamma iconify
joysticks listmodes peter reopen version)
set(CONSOLE_BINARIES clipboard defaults events fsaa fsfocus gamma glfwinfo iconify
joysticks listmodes peter reopen)
if(MSVC)
# Tell MSVC to use main instead of WinMain for Windows subsystem executables

View File

@ -78,17 +78,10 @@ int main(void)
glfwSetWindowSizeCallback(window_size_callback);
glfwSwapInterval(1);
glClearColor(0, 0, 0, 0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
while (glfwIsWindow(window))
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.f, 1.f, 1.f);
glBegin(GL_LINES);
glVertex2f(0.f, (GLfloat) window_height - cursor_y);
glVertex2f((GLfloat) window_width, (GLfloat) window_height - cursor_y);

View File

@ -132,8 +132,6 @@ int main(int argc, char** argv)
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.f, 1.f, 1.f);
glLoadIdentity();
glTranslatef(0.25f, 0.25f, 0.f);
glRotatef(time, 0.f, 0.f, 1.f);

View File

@ -32,21 +32,28 @@
#include <GL/glfw3.h>
#include <GL/glext.h>
#ifdef _MSC_VER
#define strcasecmp(x, y) _stricmp(x, y)
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.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)
{
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 strategies: none lose\n");
printf("available profiles: " PROFILE_NAME_CORE " " PROFILE_NAME_COMPAT " " PROFILE_NAME_ES2 "\n");
printf("available strategies: " STRATEGY_NAME_NONE " " STRATEGY_NAME_LOSE "\n");
}
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)
{
if (profile == GLFW_OPENGL_COMPAT_PROFILE)
return "compatibility";
return PROFILE_NAME_COMPAT;
else if (profile == GLFW_OPENGL_CORE_PROFILE)
return "core";
return PROFILE_NAME_CORE;
else if (profile == GLFW_OPENGL_ES2_PROFILE)
return "es2";
return PROFILE_NAME_ES2;
return "unknown";
}
@ -69,9 +76,9 @@ static const char* get_glfw_profile_name(int profile)
static const char* get_profile_name(GLint mask)
{
if (mask & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT)
return "compatibility";
return PROFILE_NAME_COMPAT;
if (mask & GL_CONTEXT_CORE_PROFILE_BIT)
return "core";
return PROFILE_NAME_CORE;
return "unknown";
}
@ -142,11 +149,11 @@ int main(int argc, char** argv)
minor = atoi(optarg);
break;
case 'p':
if (strcasecmp(optarg, "core") == 0)
if (strcasecmp(optarg, PROFILE_NAME_CORE) == 0)
profile = GLFW_OPENGL_CORE_PROFILE;
else if (strcasecmp(optarg, "compat") == 0)
else if (strcasecmp(optarg, PROFILE_NAME_COMPAT) == 0)
profile = GLFW_OPENGL_COMPAT_PROFILE;
else if (strcasecmp(optarg, "es2") == 0)
else if (strcasecmp(optarg, PROFILE_NAME_ES2) == 0)
profile = GLFW_OPENGL_ES2_PROFILE;
else
{
@ -155,9 +162,9 @@ int main(int argc, char** argv)
}
break;
case 'r':
if (strcasecmp(optarg, "none") == 0)
if (strcasecmp(optarg, STRATEGY_NAME_NONE) == 0)
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;
else
{
@ -221,7 +228,9 @@ int main(int argc, char** argv)
if (major != GLFW_VERSION_MAJOR ||
minor != GLFW_VERSION_MINOR ||
revision != GLFW_VERSION_REVISION)
{
printf("*** WARNING: GLFW version mismatch! ***\n");
}
printf("GLFW library version string: \"%s\"\n", glfwGetVersionString());

View File

@ -37,22 +37,32 @@
static GLboolean cursor_captured = GL_FALSE;
static GLFWwindow window_handle = NULL;
static int cursor_x;
static int cursor_y;
static GLboolean open_window(void);
static void toggle_mouse_cursor(GLFWwindow window)
{
if (cursor_captured)
{
printf("Released cursor\n");
glfwSetCursorMode(window, GLFW_CURSOR_NORMAL);
}
else
{
printf("Captured cursor\n");
glfwSetCursorMode(window, GLFW_CURSOR_CAPTURED);
}
cursor_captured = !cursor_captured;
}
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)
@ -87,14 +97,12 @@ static void window_size_callback(GLFWwindow window, int width, int height)
static GLboolean open_window(void)
{
int x, y;
window_handle = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Peter Detector", NULL);
if (!window_handle)
return GL_FALSE;
glfwGetMousePos(window_handle, &x, &y);
printf("Mouse position: %i %i\n", x, y);
glfwGetMousePos(window_handle, &cursor_x, &cursor_y);
printf("Mouse position: %i %i\n", cursor_x, cursor_y);
glfwSetWindowSizeCallback(window_size_callback);
glfwSetMousePosCallback(mouse_position_callback);

View File

@ -62,7 +62,7 @@ static void window_size_callback(GLFWwindow window, int width, int height)
static int window_close_callback(GLFWwindow window)
{
printf("Close callback triggered\n");
window_handle = NULL;
closed = GL_TRUE;
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);
glMatrixMode(GL_MODELVIEW);
glClearColor(0.f, 0.f, 0.f, 0.f);
glColor3f(1.f, 1.f, 1.f);
glfwSetTime(0.0);
while (glfwGetTime() < 5.0)

View File

@ -62,9 +62,6 @@ int main(void)
glfwSetWindowSizeCallback(window_size_callback);
glfwSwapInterval(1);
glClearColor(0.f, 0.f, 0.f, 0.f);
glColor3f(1.f, 1.f, 1.f);
glMatrixMode(GL_PROJECTION);
glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f);
glMatrixMode(GL_MODELVIEW);

View File

@ -66,7 +66,10 @@ int main(void)
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)