From 792034c42d382391008f00725f6d5a3abe160cd9 Mon Sep 17 00:00:00 2001
From: Camilla Berglund
Date: Sun, 9 Oct 2011 00:55:39 +0200
Subject: [PATCH 01/16] Fomatting.
---
tests/glfwinfo.c | 43 ++++++++++++++++++++++++++-----------------
1 file changed, 26 insertions(+), 17 deletions(-)
diff --git a/tests/glfwinfo.c b/tests/glfwinfo.c
index 9bcdd0f8..4de6634d 100644
--- a/tests/glfwinfo.c
+++ b/tests/glfwinfo.c
@@ -32,21 +32,28 @@
#include
#include
-#ifdef _MSC_VER
-#define strcasecmp(x, y) _stricmp(x, y)
-#endif
-
#include
#include
#include
#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());
@@ -266,7 +275,7 @@ int main(int argc, char** argv)
if (major > 1)
{
printf("OpenGL context shading language version: \"%s\"\n",
- glGetString(GL_SHADING_LANGUAGE_VERSION));
+ glGetString(GL_SHADING_LANGUAGE_VERSION));
}
// Report OpenGL extensions
From d0840bdea14fbf3abab21d3094a5b2811e99acee Mon Sep 17 00:00:00 2001
From: Camilla Berglund
Date: Sun, 9 Oct 2011 17:10:40 +0200
Subject: [PATCH 02/16] Added more input functions to clarify internal API.
---
src/cocoa_window.m | 33 +++++-----------------
src/internal.h | 10 +++++--
src/win32_window.c | 45 ++++++++----------------------
src/window.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++
src/x11_window.c | 56 ++++++++++---------------------------
5 files changed, 109 insertions(+), 104 deletions(-)
diff --git a/src/cocoa_window.m b/src/cocoa_window.m
index 93e37089..136a4378 100644
--- a/src/cocoa_window.m
+++ b/src/cocoa_window.m
@@ -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);
}
}
diff --git a/src/internal.h b/src/internal.h
index 2d38912c..bfe24fb0 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -339,12 +339,18 @@ 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);
+
+// 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);
diff --git a/src/win32_window.c b/src/win32_window.c
index e975235b..6343f902 100644
--- a/src/win32_window.c
+++ b/src/win32_window.c
@@ -852,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;
}
@@ -1006,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;
+ x = 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;
@@ -1053,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)
{
@@ -1064,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)
{
@@ -1086,6 +1061,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
if (GetWindowRect(window->Win32.handle, &ClipWindowRect))
ClipCursor(&ClipWindowRect);
}
+
+ _glfwInputWindowPos(window, LOWORD(lParam), HIWORD(lParam));
return 0;
}
diff --git a/src/window.c b/src/window.c
index 06c32b8d..73d32114 100644
--- a/src/window.c
+++ b/src/window.c
@@ -182,6 +182,28 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action)
}
+//========================================================================
+// Register cursor moves
+//========================================================================
+
+void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y)
+{
+ if (window->cursorMode == GLFW_CURSOR_CAPTURED)
+ {
+ window->mousePosX += x;
+ window->mousePosY += y;
+ }
+ else
+ {
+ window->mousePosX = x;
+ window->mousePosY = y;
+ }
+
+ if (_glfwLibrary.mousePosCallback)
+ _glfwLibrary.mousePosCallback(window, x, y);
+}
+
+
//========================================================================
// Register window focus events
//========================================================================
@@ -227,6 +249,53 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated)
}
+//========================================================================
+// Register window position events
+//========================================================================
+
+void _glfwInputWindowPos(_GLFWwindow* window, int x, int y)
+{
+ if (window->positionX == x && window->positionY == y)
+ return;
+
+ 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);
+}
+
+
//////////////////////////////////////////////////////////////////////////
////// GLFW public API //////
//////////////////////////////////////////////////////////////////////////
diff --git a/src/x11_window.c b/src/x11_window.c
index 962da7fb..c08b9b36 100644
--- a/src/x11_window.c
+++ b/src/x11_window.c
@@ -1194,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;
+ x = 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;
@@ -1236,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;
}
@@ -1305,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;
}
@@ -1323,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;
}
From 30ab9e2058ea01a98b9f82855f155b83830fc619 Mon Sep 17 00:00:00 2001
From: Camilla Berglund
Date: Sun, 9 Oct 2011 17:13:58 +0200
Subject: [PATCH 03/16] Moved input-related functions to input file.
---
src/input.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++
src/window.c | 101 -------------------------------------------------
2 files changed, 105 insertions(+), 101 deletions(-)
diff --git a/src/input.c b/src/input.c
index 8845b758..763172ea 100644
--- a/src/input.c
+++ b/src/input.c
@@ -31,6 +31,111 @@
#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)
+ {
+ window->mousePosX += x;
+ window->mousePosY += y;
+ }
+ else
+ {
+ window->mousePosX = x;
+ window->mousePosY = y;
+ }
+
+ if (_glfwLibrary.mousePosCallback)
+ _glfwLibrary.mousePosCallback(window, x, y);
+}
+
+
//////////////////////////////////////////////////////////////////////////
////// GLFW public API //////
//////////////////////////////////////////////////////////////////////////
diff --git a/src/window.c b/src/window.c
index 73d32114..131e41fa 100644
--- a/src/window.c
+++ b/src/window.c
@@ -103,107 +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 cursor moves
-//========================================================================
-
-void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y)
-{
- if (window->cursorMode == GLFW_CURSOR_CAPTURED)
- {
- window->mousePosX += x;
- window->mousePosY += y;
- }
- else
- {
- window->mousePosX = x;
- window->mousePosY = y;
- }
-
- if (_glfwLibrary.mousePosCallback)
- _glfwLibrary.mousePosCallback(window, x, y);
-}
-
-
//========================================================================
// Register window focus events
//========================================================================
From de147988f2b7f1311ef7b0c49cd87766b35f900a Mon Sep 17 00:00:00 2001
From: Camilla Berglund
Date: Sun, 9 Oct 2011 17:40:29 +0200
Subject: [PATCH 04/16] Fixed editing mistakes.
---
src/win32_window.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/win32_window.c b/src/win32_window.c
index 6343f902..930adccf 100644
--- a/src/win32_window.c
+++ b/src/win32_window.c
@@ -1005,13 +1005,13 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
if (_glfwLibrary.activeWindow != window)
return 0;
- x += newMouseX - window->Win32.oldMouseX;
- y += newMouseY - window->Win32.oldMouseY;
+ x = newMouseX - window->Win32.oldMouseX;
+ y = newMouseY - window->Win32.oldMouseY;
}
else
{
x = newMouseX;
- x = newMouseY;
+ y = newMouseY;
}
window->Win32.oldMouseX = newMouseX;
From 72ef5374259412e13650ef13df3f8998ad2620fd Mon Sep 17 00:00:00 2001
From: Camilla Berglund
Date: Sun, 9 Oct 2011 21:12:13 +0200
Subject: [PATCH 05/16] Added input function for window damage events.
---
src/internal.h | 1 +
src/win32_window.c | 4 +---
src/window.c | 11 +++++++++++
src/x11_window.c | 4 +---
4 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/src/internal.h b/src/internal.h
index bfe24fb0..89c77cd7 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -344,6 +344,7 @@ 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);
diff --git a/src/win32_window.c b/src/win32_window.c
index 930adccf..3442f5a3 100644
--- a/src/win32_window.c
+++ b/src/win32_window.c
@@ -1069,9 +1069,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
// Was the window contents damaged?
case WM_PAINT:
{
- if (_glfwLibrary.windowRefreshCallback)
- _glfwLibrary.windowRefreshCallback(window);
-
+ _glfwInputWindowDamage(window);
break;
}
diff --git a/src/window.c b/src/window.c
index 131e41fa..29707bd1 100644
--- a/src/window.c
+++ b/src/window.c
@@ -195,6 +195,17 @@ void _glfwInputWindowIconify(_GLFWwindow* window, int iconified)
}
+//========================================================================
+// Register window damage events
+//========================================================================
+
+void _glfwInputWindowDamage(_GLFWwindow* window)
+{
+ if (_glfwLibrary.windowRefreshCallback)
+ _glfwLibrary.windowRefreshCallback(window);
+}
+
+
//////////////////////////////////////////////////////////////////////////
////// GLFW public API //////
//////////////////////////////////////////////////////////////////////////
diff --git a/src/x11_window.c b/src/x11_window.c
index c08b9b36..8ec19572 100644
--- a/src/x11_window.c
+++ b/src/x11_window.c
@@ -1349,9 +1349,7 @@ static void processSingleEvent(void)
return;
}
- if (_glfwLibrary.windowRefreshCallback)
- _glfwLibrary.windowRefreshCallback(window);
-
+ _glfwInputWindowDamage(window);
break;
}
From 30c43d60a5eb482d91b11705bfe95f5eff38a683 Mon Sep 17 00:00:00 2001
From: Camilla Berglund
Date: Thu, 13 Oct 2011 14:07:24 +0200
Subject: [PATCH 06/16] Removed superfluous test.
---
src/window.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/src/window.c b/src/window.c
index 29707bd1..68893f09 100644
--- a/src/window.c
+++ b/src/window.c
@@ -154,9 +154,6 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated)
void _glfwInputWindowPos(_GLFWwindow* window, int x, int y)
{
- if (window->positionX == x && window->positionY == y)
- return;
-
window->positionX = x;
window->positionY = y;
}
From 3ebe9a43587df1e739444aedd9a1ae84fb3fbb41 Mon Sep 17 00:00:00 2001
From: Camilla Berglund
Date: Thu, 13 Oct 2011 14:07:52 +0200
Subject: [PATCH 07/16] Mouse input fixes.
---
src/input.c | 33 ++++++++++++++-------------------
src/x11_window.c | 2 +-
2 files changed, 15 insertions(+), 20 deletions(-)
diff --git a/src/input.c b/src/input.c
index 763172ea..42e3af97 100644
--- a/src/input.c
+++ b/src/input.c
@@ -122,17 +122,23 @@ void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y)
{
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{
+ if (!x && !y)
+ return;
+
window->mousePosX += x;
window->mousePosY += y;
}
else
{
+ if (window->mousePosX == x && window->mousePosY == y)
+ return;
+
window->mousePosX = x;
window->mousePosY = y;
}
if (_glfwLibrary.mousePosCallback)
- _glfwLibrary.mousePosCallback(window, x, y);
+ _glfwLibrary.mousePosCallback(window, window->mousePosX, window->mousePosY);
}
@@ -296,6 +302,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)
@@ -315,29 +322,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);
- }
- }
+ _glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
+ _glfwInputCursorMotion(window,
+ centerPosX - window->mousePosX,
+ centerPosY - window->mousePosY);
}
_glfwPlatformSetCursorMode(window, mode);
diff --git a/src/x11_window.c b/src/x11_window.c
index 8ec19572..1afa814a 100644
--- a/src/x11_window.c
+++ b/src/x11_window.c
@@ -1207,7 +1207,7 @@ static void processSingleEvent(void)
else
{
x = event.xmotion.x;
- x = event.xmotion.y;
+ y = event.xmotion.y;
}
window->X11.cursorPosX = event.xmotion.x;
From 851f510d4b6c1599b009479d7f04e208e3f27679 Mon Sep 17 00:00:00 2001
From: Camilla Berglund
Date: Thu, 13 Oct 2011 14:11:06 +0200
Subject: [PATCH 08/16] Added mode switch and offset output to peter.
---
tests/peter.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/tests/peter.c b/tests/peter.c
index 50209908..cefdb103 100644
--- a/tests/peter.c
+++ b/tests/peter.c
@@ -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);
From 2660b27cf39ccb88d3161179ff58ca86df45b753 Mon Sep 17 00:00:00 2001
From: Camilla Berglund
Date: Thu, 13 Oct 2011 15:20:59 +0200
Subject: [PATCH 09/16] Renamed internal cursor position in preparation of new
API.
---
src/cocoa_window.m | 4 ++--
src/input.c | 30 ++++++++++++++++--------------
src/internal.h | 2 +-
src/win32_window.c | 8 ++++----
src/x11_window.c | 4 ++--
5 files changed, 25 insertions(+), 23 deletions(-)
diff --git a/src/cocoa_window.m b/src/cocoa_window.m
index 136a4378..4f662faf 100644
--- a/src/cocoa_window.m
+++ b/src/cocoa_window.m
@@ -688,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;
diff --git a/src/input.c b/src/input.c
index 42e3af97..56ab0e5d 100644
--- a/src/input.c
+++ b/src/input.c
@@ -125,20 +125,22 @@ void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y)
if (!x && !y)
return;
- window->mousePosX += x;
- window->mousePosY += y;
+ window->cursorPosX += x;
+ window->cursorPosY += y;
}
else
{
- if (window->mousePosX == x && window->mousePosY == y)
+ if (window->cursorPosX == x && window->cursorPosY == y)
return;
- window->mousePosX = x;
- window->mousePosY = y;
+ window->cursorPosX = x;
+ window->cursorPosY = y;
}
if (_glfwLibrary.mousePosCallback)
- _glfwLibrary.mousePosCallback(window, window->mousePosX, window->mousePosY);
+ _glfwLibrary.mousePosCallback(window,
+ window->cursorPosX,
+ window->cursorPosY);
}
@@ -229,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;
}
@@ -258,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)
@@ -331,8 +333,8 @@ GLFWAPI void glfwSetCursorMode(GLFWwindow handle, int mode)
{
_glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY);
_glfwInputCursorMotion(window,
- centerPosX - window->mousePosX,
- centerPosY - window->mousePosY);
+ centerPosX - window->cursorPosX,
+ centerPosY - window->cursorPosY);
}
_glfwPlatformSetCursorMode(window, mode);
@@ -411,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);
}
}
diff --git a/src/internal.h b/src/internal.h
index 89c77cd7..3c27bba1 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -184,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];
diff --git a/src/win32_window.c b/src/win32_window.c
index 3442f5a3..d81da139 100644
--- a/src/win32_window.c
+++ b/src/win32_window.c
@@ -1371,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;
}
@@ -1786,8 +1786,8 @@ void _glfwPlatformPollEvents(void)
}
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))
diff --git a/src/x11_window.c b/src/x11_window.c
index 1afa814a..3ce5e832 100644
--- a/src/x11_window.c
+++ b/src/x11_window.c
@@ -1457,8 +1457,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;
From a18cd1b14c7ed4f8006d8f7a4d1aeb5cf47b8d45 Mon Sep 17 00:00:00 2001
From: Camilla Berglund
Date: Wed, 2 Nov 2011 16:56:34 +0100
Subject: [PATCH 10/16] Renamed GLFW_WINDOW_NO_RESIZE to GLFW_WINDOW_RESIZABLE.
---
examples/heightmap.c | 2 +-
include/GL/glfw3.h | 2 +-
readme.html | 1 +
src/cocoa_window.m | 4 ++--
src/internal.h | 6 +++---
src/win32_window.c | 2 +-
src/window.c | 13 ++++++++-----
src/x11_window.c | 8 ++++----
8 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/examples/heightmap.c b/examples/heightmap.c
index 1d3dd72e..b4dcf082 100644
--- a/examples/heightmap.c
+++ b/examples/heightmap.c
@@ -583,7 +583,7 @@ int main(int argc, char** argv)
exit(EXIT_FAILURE);
}
- glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE);
+ glfwOpenWindowHint(GLFW_WINDOW_RESIZABLE, GL_FALSE);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h
index 1f52e742..88729631 100644
--- a/include/GL/glfw3.h
+++ b/include/GL/glfw3.h
@@ -418,7 +418,7 @@ extern "C" {
#define GLFW_ACCUM_ALPHA_BITS 0x0002100A
#define GLFW_AUX_BUFFERS 0x0002100B
#define GLFW_STEREO 0x0002100C
-#define GLFW_WINDOW_NO_RESIZE 0x0002100D
+#define GLFW_WINDOW_RESIZABLE 0x0002100D
#define GLFW_FSAA_SAMPLES 0x0002100E
#define GLFW_OPENGL_VERSION_MAJOR 0x0002100F
#define GLFW_OPENGL_VERSION_MINOR 0x00021010
diff --git a/readme.html b/readme.html
index a028b45b..21f043a3 100644
--- a/readme.html
+++ b/readme.html
@@ -287,6 +287,7 @@ version of GLFW.
Changed buffer bit depth parameters of glfwOpenWindow
to window hints
Renamed glfw.h
to glfw3.h
to avoid conflicts with 2.x series
Renamed GLFW_WINDOW
token to GLFW_WINDOWED
+ Renamed GLFW_WINDOW_NO_RESIZE
to GLFW_WINDOW_RESIZABLE
Renamed version
test to glfwinfo
Replaced ad hoc build system with CMake
Replaced layout-dependent key codes with single, platform-independent set based on US layout
diff --git a/src/cocoa_window.m b/src/cocoa_window.m
index 4f662faf..ce95217d 100644
--- a/src/cocoa_window.m
+++ b/src/cocoa_window.m
@@ -568,7 +568,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
styleMask = NSTitledWindowMask | NSClosableWindowMask |
NSMiniaturizableWindowMask;
- if (!wndconfig->windowNoResize)
+ if (wndconfig->resizable)
styleMask |= NSResizableWindowMask;
}
else
@@ -691,7 +691,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
window->cursorPosX = point.x;
window->cursorPosY = point.y;
- window->windowNoResize = wndconfig->windowNoResize;
+ window->resizable = wndconfig->resizable;
return GL_TRUE;
}
diff --git a/src/internal.h b/src/internal.h
index 3c27bba1..5992a0f4 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -103,7 +103,7 @@ struct _GLFWhints
int accumAlphaBits;
int auxBuffers;
GLboolean stereo;
- GLboolean windowNoResize;
+ GLboolean resizable;
int samples;
int glMajor;
int glMinor;
@@ -125,7 +125,7 @@ struct _GLFWwndconfig
int mode;
const char* title;
int refreshRate;
- GLboolean windowNoResize;
+ GLboolean resizable;
int glMajor;
int glMinor;
GLboolean glForward;
@@ -175,7 +175,7 @@ struct _GLFWwindow
int width, height;
int positionX, positionY;
int mode; // GLFW_WINDOW or GLFW_FULLSCREEN
- GLboolean windowNoResize; // resize- and maximize gadgets disabled flag
+ GLboolean resizable; // GL_TRUE if user may resize this window
int refreshRate; // monitor refresh rate
void* userPointer;
diff --git a/src/win32_window.c b/src/win32_window.c
index d81da139..e2619acf 100644
--- a/src/win32_window.c
+++ b/src/win32_window.c
@@ -1309,7 +1309,7 @@ static int createWindow(_GLFWwindow* window,
{
dwStyle |= WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
- if (!wndconfig->windowNoResize)
+ if (wndconfig->resizable)
{
dwStyle |= (WS_MAXIMIZEBOX | WS_SIZEBOX);
dwExStyle |= WS_EX_WINDOWEDGE;
diff --git a/src/window.c b/src/window.c
index 68893f09..88b3dc18 100644
--- a/src/window.c
+++ b/src/window.c
@@ -100,6 +100,9 @@ void _glfwSetDefaultWindowHints(void)
// The default minimum OpenGL version is 1.0
_glfwLibrary.hints.glMajor = 1;
_glfwLibrary.hints.glMinor = 0;
+
+ // The default is to allow window resizing
+ _glfwLibrary.hints.resizable = GL_TRUE;
}
@@ -247,7 +250,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height,
wndconfig.mode = mode;
wndconfig.title = title;
wndconfig.refreshRate = Max(_glfwLibrary.hints.refreshRate, 0);
- wndconfig.windowNoResize = _glfwLibrary.hints.windowNoResize ? GL_TRUE : GL_FALSE;
+ wndconfig.resizable = _glfwLibrary.hints.resizable ? GL_TRUE : GL_FALSE;
wndconfig.glMajor = _glfwLibrary.hints.glMajor;
wndconfig.glMinor = _glfwLibrary.hints.glMinor;
wndconfig.glForward = _glfwLibrary.hints.glForward ? GL_TRUE : GL_FALSE;
@@ -419,8 +422,8 @@ GLFWAPI void glfwOpenWindowHint(int target, int hint)
case GLFW_STEREO:
_glfwLibrary.hints.stereo = hint;
break;
- case GLFW_WINDOW_NO_RESIZE:
- _glfwLibrary.hints.windowNoResize = hint;
+ case GLFW_WINDOW_RESIZABLE:
+ _glfwLibrary.hints.resizable = hint;
break;
case GLFW_FSAA_SAMPLES:
_glfwLibrary.hints.samples = hint;
@@ -707,8 +710,8 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow handle, int param)
return window->stereo;
case GLFW_REFRESH_RATE:
return window->refreshRate;
- case GLFW_WINDOW_NO_RESIZE:
- return window->windowNoResize;
+ case GLFW_WINDOW_RESIZABLE:
+ return window->resizable;
case GLFW_FSAA_SAMPLES:
return window->samples;
case GLFW_OPENGL_VERSION_MAJOR:
diff --git a/src/x11_window.c b/src/x11_window.c
index 3ce5e832..effff0f9 100644
--- a/src/x11_window.c
+++ b/src/x11_window.c
@@ -794,7 +794,7 @@ static GLboolean createWindow(_GLFWwindow* window,
hints->flags = 0;
- if (wndconfig->windowNoResize)
+ if (!wndconfig->resizable)
{
hints->flags |= (PMinSize | PMaxSize);
hints->min_width = hints->max_width = window->width;
@@ -1391,8 +1391,8 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
{
_GLFWfbconfig closest;
- window->refreshRate = wndconfig->refreshRate;
- window->windowNoResize = wndconfig->windowNoResize;
+ window->refreshRate = wndconfig->refreshRate;
+ window->resizable = wndconfig->resizable;
initGLXExtensions(window);
@@ -1533,7 +1533,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height)
&width, &height, &rate);
}
- if (window->windowNoResize)
+ if (!window->resizable)
{
// Update window size restrictions to match new window size
From 96267c8696ff33237741481a95ae73d49f955aab Mon Sep 17 00:00:00 2001
From: Camilla Berglund
Date: Wed, 2 Nov 2011 17:34:27 +0100
Subject: [PATCH 11/16] Formatting.
---
src/cocoa_init.m | 10 +++++-----
src/x11_window.c | 2 +-
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/cocoa_init.m b/src/cocoa_init.m
index c7c0d6c5..785cd267 100644
--- a/src/cocoa_init.m
+++ b/src/cocoa_init.m
@@ -109,7 +109,7 @@ static NSString* findAppName(void)
char** progname = _NSGetProgname();
if (progname && *progname)
{
- // TODO: UTF8?
+ // TODO: UTF-8?
return [NSString stringWithUTF8String:*progname];
}
@@ -202,7 +202,7 @@ int _glfwPlatformInit(void)
[GLFWApplication sharedApplication];
_glfwLibrary.NS.OpenGLFramework =
- CFBundleGetBundleWithIdentifier( CFSTR( "com.apple.opengl" ) );
+ CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl"));
if (_glfwLibrary.NS.OpenGLFramework == NULL)
{
_glfwSetError(GLFW_PLATFORM_ERROR,
@@ -229,7 +229,7 @@ int _glfwPlatformInit(void)
_glfwLibrary.originalRampSize = CGDisplayGammaTableCapacity(CGMainDisplayID());
_glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp);
_glfwLibrary.currentRamp = _glfwLibrary.originalRamp;
-
+
return GL_TRUE;
}
@@ -240,10 +240,10 @@ int _glfwPlatformInit(void)
int _glfwPlatformTerminate(void)
{
// TODO: Probably other cleanup
-
+
// Restore the original gamma ramp
_glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp);
-
+
[NSApp setDelegate:nil];
[_glfwLibrary.NS.delegate release];
_glfwLibrary.NS.delegate = nil;
diff --git a/src/x11_window.c b/src/x11_window.c
index effff0f9..61e39583 100644
--- a/src/x11_window.c
+++ b/src/x11_window.c
@@ -1700,7 +1700,7 @@ void _glfwPlatformRefreshWindowParams(void)
&dotclock, &modeline);
pixels_per_second = 1000.0f * (float) dotclock;
pixels_per_frame = (float) modeline.htotal * modeline.vtotal;
- window->refreshRate = (int)(pixels_per_second/pixels_per_frame+0.5);
+ window->refreshRate = (int) (pixels_per_second / pixels_per_frame + 0.5);
#endif /*_GLFW_HAS_XF86VIDMODE*/
}
else
From 0c122bb8ad6c73de4129cd8d65545e29ea2cb8a3 Mon Sep 17 00:00:00 2001
From: Camilla Berglund
Date: Wed, 2 Nov 2011 17:59:18 +0100
Subject: [PATCH 12/16] Added dynamic linking test.
---
readme.html | 1 +
tests/CMakeLists.txt | 71 ++++++++++++++++++++++++------------
tests/dynamic.c | 87 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 135 insertions(+), 24 deletions(-)
create mode 100644 tests/dynamic.c
diff --git a/readme.html b/readme.html
index 21f043a3..175e3b81 100644
--- a/readme.html
+++ b/readme.html
@@ -281,6 +281,7 @@ version of GLFW.
Added GLFW_INCLUDE_GL3
macro for telling the GLFW header to include gl3.h
header instead of gl.h
Added windows
simple multi-window test program
Added sharing
simple OpenGL object sharing test program
+ Added dynamic
simple dynamic linking test program
Added a parameter to glfwOpenWindow
for specifying a context the new window's context will share objects with
Added initial window title parameter to glfwOpenWindow
Added glfwSetGamma
, glfwSetGammaRamp
and glfwGetGammaRamp
functions and GLFWgammaramp
type for monitor gamma ramp control
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index b85d79b4..81ba0dd6 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,35 +1,58 @@
-link_libraries(libglfwStatic ${GLFW_LIBRARIES} ${OPENGL_glu_LIBRARY})
+set(STATIC_DEPS libglfwStatic ${GLFW_LIBRARIES} ${OPENGL_glu_LIBRARY})
+set(SHARED_DEPS libglfwShared ${GLFW_LIBRARIES} ${OPENGL_glu_LIBRARY})
include_directories(${GLFW_SOURCE_DIR}/include
${GLFW_SOURCE_DIR}/support
${OPENGL_INCLUDE_DIR})
add_executable(defaults defaults.c)
-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)
+target_link_libraries(defaults ${STATIC_DEPS})
-if(APPLE)
- # Set fancy names for bundles
- add_executable(Accuracy MACOSX_BUNDLE accuracy.c)
- add_executable(Sharing MACOSX_BUNDLE sharing.c)
- add_executable(Tearing MACOSX_BUNDLE tearing.c)
- add_executable(Windows MACOSX_BUNDLE windows.c)
-else()
- # Set boring names for executables
- add_executable(accuracy WIN32 accuracy.c)
- add_executable(sharing WIN32 sharing.c)
- add_executable(tearing WIN32 tearing.c)
- add_executable(windows WIN32 windows.c)
-endif(APPLE)
+add_executable(dynamic dynamic.c)
+target_link_libraries(dynamic ${SHARED_DEPS})
+
+add_executable(events events.c)
+target_link_libraries(events ${STATIC_DEPS})
+
+add_executable(fsaa fsaa.c getopt.c)
+target_link_libraries(fsaa ${STATIC_DEPS})
+
+add_executable(fsfocus fsfocus.c)
+target_link_libraries(fsfocus ${STATIC_DEPS})
+
+add_executable(gamma gamma.c getopt.c)
+target_link_libraries(gamma ${STATIC_DEPS})
+
+add_executable(glfwinfo glfwinfo.c getopt.c)
+target_link_libraries(glfwinfo ${STATIC_DEPS})
+
+add_executable(iconify iconify.c getopt.c)
+target_link_libraries(iconify ${STATIC_DEPS})
+
+add_executable(joysticks joysticks.c)
+target_link_libraries(joysticks ${STATIC_DEPS})
+
+add_executable(listmodes listmodes.c)
+target_link_libraries(listmodes ${STATIC_DEPS})
+
+add_executable(peter peter.c)
+target_link_libraries(peter ${STATIC_DEPS})
+
+add_executable(reopen reopen.c)
+target_link_libraries(reopen ${STATIC_DEPS})
+
+add_executable(accuracy WIN32 MACOSX_BUNDLE accuracy.c)
+target_link_libraries(accuracy ${STATIC_DEPS})
+
+add_executable(sharing WIN32 MACOSX_BUNDLE sharing.c)
+target_link_libraries(sharing ${STATIC_DEPS})
+
+add_executable(tearing WIN32 MACOSX_BUNDLE tearing.c)
+target_link_libraries(tearing ${STATIC_DEPS})
+
+add_executable(windows WIN32 MACOSX_BUNDLE windows.c)
+target_link_libraries(windows ${STATIC_DEPS})
set(WINDOWS_BINARIES accuracy sharing tearing windows)
set(CONSOLE_BINARIES defaults events fsaa fsfocus gamma glfwinfo iconify
diff --git a/tests/dynamic.c b/tests/dynamic.c
new file mode 100644
index 00000000..0ad1c121
--- /dev/null
+++ b/tests/dynamic.c
@@ -0,0 +1,87 @@
+//========================================================================
+// Dynamic linking test
+// Copyright (c) Camilla Berglund
+//
+// This software is provided 'as-is', without any express or implied
+// warranty. In no event will the authors be held liable for any damages
+// arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it
+// freely, subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented; you must not
+// claim that you wrote the original software. If you use this software
+// in a product, an acknowledgment in the product documentation would
+// be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such, and must not
+// be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source
+// distribution.
+//
+//========================================================================
+//
+// This test came about as the result of bug #3060461
+//
+//========================================================================
+
+#define GLFW_DLL
+#include
+
+#include
+#include
+
+static void window_size_callback(GLFWwindow window, int width, int height)
+{
+ glViewport(0, 0, width, height);
+}
+
+int main(void)
+{
+ GLFWwindow window;
+ int major, minor, rev;
+ glfwGetVersion(&major, &minor, &rev);
+
+ if (major != GLFW_VERSION_MAJOR ||
+ minor != GLFW_VERSION_MINOR ||
+ rev != GLFW_VERSION_REVISION)
+ {
+ fprintf(stderr, "GLFW library version mismatch\n");
+ exit(EXIT_FAILURE);
+ }
+
+ printf("GLFW version: %i.%i.%i\n", major, minor, rev);
+ printf("GLFW version string: %s\n", glfwGetVersionString());
+
+ if (!glfwInit())
+ {
+ fprintf(stderr, "Failed to initialize GLFW\n");
+ exit(EXIT_FAILURE);
+ }
+
+ window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Dynamic Linking Test", NULL);
+ if (!window)
+ {
+ glfwTerminate();
+
+ fprintf(stderr, "Failed to open GLFW window\n");
+ exit(EXIT_FAILURE);
+ }
+
+ glfwSetWindowSizeCallback(window_size_callback);
+ glfwSwapInterval(1);
+
+ while (glfwIsWindow(window))
+ {
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ glfwSwapBuffers();
+ glfwPollEvents();
+ }
+
+ glfwTerminate();
+ exit(EXIT_SUCCESS);
+}
+
From 8117f4e48de7f4d527e879294c06f9e41e39e5bd Mon Sep 17 00:00:00 2001
From: Camilla Berglund
Date: Wed, 2 Nov 2011 23:10:04 +0100
Subject: [PATCH 13/16] Finished dynamic linking test debug output.
---
tests/dynamic.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
mode change 100644 => 100755 tests/dynamic.c
diff --git a/tests/dynamic.c b/tests/dynamic.c
old mode 100644
new mode 100755
index 0ad1c121..8bc5568b
--- a/tests/dynamic.c
+++ b/tests/dynamic.c
@@ -44,6 +44,13 @@ int main(void)
int major, minor, rev;
glfwGetVersion(&major, &minor, &rev);
+ printf("GLFW header version: %i.%i.%i\n",
+ GLFW_VERSION_MAJOR,
+ GLFW_VERSION_MINOR,
+ GLFW_VERSION_REVISION);
+ printf("GLFW library version: %i.%i.%i\n", major, minor, rev);
+ printf("GLFW library version string: %s\n", glfwGetVersionString());
+
if (major != GLFW_VERSION_MAJOR ||
minor != GLFW_VERSION_MINOR ||
rev != GLFW_VERSION_REVISION)
@@ -52,9 +59,6 @@ int main(void)
exit(EXIT_FAILURE);
}
- printf("GLFW version: %i.%i.%i\n", major, minor, rev);
- printf("GLFW version string: %s\n", glfwGetVersionString());
-
if (!glfwInit())
{
fprintf(stderr, "Failed to initialize GLFW\n");
From 85982b298597154f16f728bd235e64decc7e1c6b Mon Sep 17 00:00:00 2001
From: Camilla Berglund
Date: Thu, 3 Nov 2011 00:13:49 +0100
Subject: [PATCH 14/16] Removed Cygwin cross-compilation hacks.
---
CMakeLists.txt | 4 ++--
examples/CMakeLists.txt | 7 -------
src/CMakeLists.txt | 19 -------------------
tests/CMakeLists.txt | 10 ----------
tests/dynamic.c | 0
5 files changed, 2 insertions(+), 38 deletions(-)
mode change 100755 => 100644 tests/dynamic.c
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 83eb8bf8..d1e604e3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -36,7 +36,7 @@ endif (WIN32)
#--------------------------------------------------------------------
# Set up GLFW for Xlib and GLX on Unix-like systems with X Windows
#--------------------------------------------------------------------
-if (UNIX AND NOT APPLE AND NOT CYGWIN)
+if (UNIX AND NOT APPLE)
message(STATUS "Building GLFW for X11 and GLX on a Unix-like system")
# Define the platform identifier
@@ -92,7 +92,7 @@ if (UNIX AND NOT APPLE AND NOT CYGWIN)
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(_GLFW_USE_LINUX_JOYSTICKS 1)
endif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
-endif(UNIX AND NOT APPLE AND NOT CYGWIN)
+endif(UNIX AND NOT APPLE)
#--------------------------------------------------------------------
# Set up GLFW for Cocoa and NSOpenGL on Mac OS X
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 345631cc..d511b22d 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -32,10 +32,3 @@ if(MSVC)
LINK_FLAGS "/ENTRY:mainCRTStartup")
endif(MSVC)
-if(CYGWIN)
- # Set cross-compile and subsystem compile and link flags
- set_target_properties(${WINDOWS_BINARIES} PROPERTIES
- COMPILE_FLAGS "-mno-cygwin"
- LINK_FLAGS "-mno-cygwin -mwindows")
-endif(CYGWIN)
-
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index cd50b41d..f15089e9 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,16 +1,4 @@
-if(CYGWIN)
-
- # These lines are intended to remove the --export-all-symbols
- # flag added in the Modules/Platform/CYGWIN.cmake file of the
- # CMake distribution.
- # This is a HACK. If you have trouble _linking_ the GLFW
- # _shared_ library on Cygwin, try disabling this.
- set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-shared")
- set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
-
-endif(CYGWIN)
-
if(UNIX)
if(_GLFW_HAS_XRANDR)
set(GLFW_PKGLIBS "${GLFW_PKGLIBS} xrandr")
@@ -67,13 +55,6 @@ if(WIN32)
IMPORT_SUFFIX "dll.lib")
endif(WIN32)
-if(CYGWIN)
- # Build for the regular Win32 environment (not Cygwin)
- set_target_properties(libglfwStatic libglfwShared PROPERTIES
- COMPILE_FLAGS "-mwin32 -mno-cygwin"
- LINK_FLAGS "-mwin32 -mno-cygwin")
-endif(CYGWIN)
-
if(APPLE)
# Append -fno-common to the compile flags to work around a bug in the Apple GCC
get_target_property(CFLAGS libglfwShared COMPILE_FLAGS)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 81ba0dd6..5adbf351 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -64,13 +64,3 @@ if(MSVC)
LINK_FLAGS "/ENTRY:mainCRTStartup")
endif(MSVC)
-if(CYGWIN)
- # Set cross-compile and subsystem compile and link flags
- set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES
- COMPILE_FLAGS "-mno-cygwin")
- set_target_properties(${WINDOWS_BINARIES} PROPERTIES
- LINK_FLAGS "-mno-cygwin -mwindows")
- set_target_properties(${CONSOLE_BINARIES} PROPERTIES
- LINK_FLAGS "-mno-cygwin -mconsole")
-endif(CYGWIN)
-
diff --git a/tests/dynamic.c b/tests/dynamic.c
old mode 100755
new mode 100644
From d929752a427fa140aa1100aefc37f1f77669df55 Mon Sep 17 00:00:00 2001
From: Camilla Berglund
Date: Thu, 3 Nov 2011 02:41:53 +0100
Subject: [PATCH 15/16] Clarified functions.
---
CMakeLists.txt | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d1e604e3..3f5f6d3e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -52,7 +52,7 @@ if (UNIX AND NOT APPLE)
include(${CMAKE_CURRENT_SOURCE_DIR}/CMake/CheckX11Extensions.cmake)
# Check for XRandR (modern resolution switching extension)
- CHECK_X11_XRANDR()
+ check_x11_xrandr()
if (X11_XRANDR_FOUND)
set(_GLFW_HAS_XRANDR 1)
list(APPEND GLFW_INCLUDE_DIR ${X11_XRANDR_INCLUDE_DIR})
@@ -60,7 +60,7 @@ if (UNIX AND NOT APPLE)
endif(X11_XRANDR_FOUND)
# Check for Xf86VidMode (fallback legacy resolution switching extension)
- CHECK_X11_XF86VIDMODE()
+ check_x11_xf86vidmode()
if (X11_XF86VIDMODE_FOUND)
set(_GLFW_HAS_XF86VIDMODE 1)
list(APPEND GLFW_INCLUDE_DIR ${X11_XF86VIDMODE_INCLUDE_DIR})
@@ -68,17 +68,17 @@ if (UNIX AND NOT APPLE)
endif(X11_XF86VIDMODE_FOUND)
# Check for Xkb (X keyboard extension)
- CHECK_FUNCTION_EXISTS(XkbQueryExtension _GLFW_HAS_XKB)
+ check_function_exists(XkbQueryExtension _GLFW_HAS_XKB)
# Check for glXGetProcAddress
- CHECK_FUNCTION_EXISTS(glXGetProcAddress _GLFW_HAS_GLXGETPROCADDRESS)
+ check_function_exists(glXGetProcAddress _GLFW_HAS_GLXGETPROCADDRESS)
if (NOT _GLFW_HAS_GLXGETPROCADDRESS)
- CHECK_FUNCTION_EXISTS(glXGetProcAddressARB _GLFW_HAS_GLXGETPROCADDRESSARB)
+ check_function_exists(glXGetProcAddressARB _GLFW_HAS_GLXGETPROCADDRESSARB)
endif (NOT _GLFW_HAS_GLXGETPROCADDRESS)
if (NOT _GLFW_HAS_GLXGETPROCADDRESS AND NOT _GLFW_HAS_GLXGETPROCADDRESSARB)
- CHECK_FUNCTION_EXISTS(glXGetProcAddressEXT _GLFW_HAS_GLXGETPROCADDRESSEXT)
+ check_function_exists(glXGetProcAddressEXT _GLFW_HAS_GLXGETPROCADDRESSEXT)
endif (NOT _GLFW_HAS_GLXGETPROCADDRESS AND NOT _GLFW_HAS_GLXGETPROCADDRESSARB)
if (NOT _GLFW_HAS_GLXGETPROCADDRESS AND
From a559b5da9800083ec4c8d31c02a7c606c198c350 Mon Sep 17 00:00:00 2001
From: Camilla Berglund
Date: Thu, 3 Nov 2011 02:43:10 +0100
Subject: [PATCH 16/16] Added rudimentary detection of librt.
---
CMakeLists.txt | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3f5f6d3e..fad2f423 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -89,6 +89,11 @@ if (UNIX AND NOT APPLE)
NOT _GLFW_HAS_GLXGETPROCADDRESSARB AND
NOT _GLFW_HAS_GLXGETPROCADDRESSEXT)
+ find_library(LIBRT rt)
+ if (LIBRT)
+ list(APPEND GLFW_LIBRARIES ${LIBRT})
+ endif(LIBRT)
+
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(_GLFW_USE_LINUX_JOYSTICKS 1)
endif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")