From 6da82e0ffe1ab59dc0ae22cf444246a4d6140e19 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 20 Sep 2011 18:52:00 +0200 Subject: [PATCH 01/22] Formatting. --- src/x11_platform.h | 4 ++-- src/x11_time.c | 10 +++++----- tests/accuracy.c | 7 ------- tests/fsaa.c | 2 -- tests/reopen.c | 3 --- tests/tearing.c | 3 --- 6 files changed, 7 insertions(+), 22 deletions(-) diff --git a/src/x11_platform.h b/src/x11_platform.h index b3cf642e..70a57b84 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -193,7 +193,7 @@ typedef struct _GLFWlibraryX11 } Xkb; // Key code LUT (mapping X11 key codes to GLFW key codes) - int keyCodeLUT[256]; + int keyCodeLUT[256]; // Screensaver data struct { @@ -222,7 +222,7 @@ typedef struct _GLFWlibraryX11 struct { GLboolean monotonic; double resolution; - uint64_t t0; + uint64_t base; } timer; #if defined(_GLFW_DLOPEN_LIBGL) diff --git a/src/x11_time.c b/src/x11_time.c index 431389c4..e2203941 100644 --- a/src/x11_time.c +++ b/src/x11_time.c @@ -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); } diff --git a/tests/accuracy.c b/tests/accuracy.c index c3bebaca..f235cf75 100644 --- a/tests/accuracy.c +++ b/tests/accuracy.c @@ -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); diff --git a/tests/fsaa.c b/tests/fsaa.c index 404e77f4..6cdb77e0 100644 --- a/tests/fsaa.c +++ b/tests/fsaa.c @@ -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); diff --git a/tests/reopen.c b/tests/reopen.c index 9d76580f..5040697f 100644 --- a/tests/reopen.c +++ b/tests/reopen.c @@ -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) diff --git a/tests/tearing.c b/tests/tearing.c index 6e43e88f..10170b0f 100644 --- a/tests/tearing.c +++ b/tests/tearing.c @@ -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); From 02200c635e0328c1827772adff054123409e299c Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 22 Sep 2011 14:10:03 +0200 Subject: [PATCH 02/22] Added missing include. --- src/x11_init.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/x11_init.c b/src/x11_init.c index 9af7783e..2b8e3e35 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -32,6 +32,7 @@ #include #include +#include //======================================================================== From a98c66c8cb31061d2ec8781eac2bea25cb2fe02d Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 22 Sep 2011 14:15:07 +0200 Subject: [PATCH 03/22] Added glext header explanation. --- src/internal.h | 4 ++++ src/win32_platform.h | 3 +++ src/x11_platform.h | 3 +++ 3 files changed, 10 insertions(+) diff --git a/src/internal.h b/src/internal.h index 83559ecc..2d38912c 100644 --- a/src/internal.h +++ b/src/internal.h @@ -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) diff --git a/src/win32_platform.h b/src/win32_platform.h index db5b82ae..a2b94ebc 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -43,6 +43,9 @@ #include #include +// 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" diff --git a/src/x11_platform.h b/src/x11_platform.h index 70a57b84..46f09f1a 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -41,6 +41,9 @@ #define GLX_GLXEXT_LEGACY #include +// 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" From 5ac752d79d4897946c1d5546189250ec99390bcb Mon Sep 17 00:00:00 2001 From: Tai Chi Minh Ralph Eastwood Date: Sun, 25 Sep 2011 15:00:08 +0100 Subject: [PATCH 04/22] Set the current gamma ramp to original gamma ramp at start. --- src/cocoa_init.m | 1 + src/win32_init.c | 1 + src/x11_init.c | 1 + 3 files changed, 3 insertions(+) diff --git a/src/cocoa_init.m b/src/cocoa_init.m index dd85f3f8..c7c0d6c5 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -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; } diff --git a/src/win32_init.c b/src/win32_init.c index 51b3f093..a69cccd7 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -163,6 +163,7 @@ int _glfwPlatformInit(void) // Save the original gamma ramp _glfwLibrary.originalRampSize = 256; _glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp); + _glfwLibrary.currentRamp = _glfwLibrary.originalRamp; _glfwInitTimer(); diff --git a/src/x11_init.c b/src/x11_init.c index 2b8e3e35..cceaa174 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -502,6 +502,7 @@ static void initGammaRamp(void) // Save the original gamma ramp _glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp); + _glfwLibrary.currentRamp = _glfwLibrary.originalRamp; } From 5999a40aaa929a5a75ed4a0590980718d2b3bc45 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 26 Sep 2011 15:38:11 +0200 Subject: [PATCH 05/22] Improved legibility. --- src/x11_fullscreen.c | 66 ++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 42 deletions(-) diff --git a/src/x11_fullscreen.c b/src/x11_fullscreen.c index c154fe3d..7eead3a3 100644 --- a/src/x11_fullscreen.c +++ b/src/x11_fullscreen.c @@ -45,21 +45,16 @@ int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate) { int i, match, bestmatch; -#if defined(_GLFW_HAS_XRANDR) - int sizecount, bestsize; - int ratecount, bestrate; - short* ratelist; - XRRScreenConfiguration* sc; - XRRScreenSize* sizelist; -#endif /*_GLFW_HAS_XRANDR*/ -#if defined(_GLFW_HAS_XF86VIDMODE) - XF86VidModeModeInfo** modelist; - int bestmode, modecount; -#endif /*_GLFW_HAS_XF86VIDMODE*/ if (_glfwLibrary.X11.RandR.available) { #if defined(_GLFW_HAS_XRANDR) + int sizecount, bestsize; + int ratecount, bestrate; + short* ratelist; + XRRScreenConfiguration* sc; + XRRScreenSize* sizelist; + 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,15 +329,6 @@ 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); @@ -397,6 +379,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 +401,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 +456,6 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) } } - // Free visuals list XFree(vislist); _glfwFree(resarray); @@ -484,15 +472,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) From 0544afeb06fbfcfc87a3c344742b79c7d9d28403 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 26 Sep 2011 15:40:18 +0200 Subject: [PATCH 06/22] It is a platform error. --- src/x11_fullscreen.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/x11_fullscreen.c b/src/x11_fullscreen.c index 7eead3a3..bb0a3d53 100644 --- a/src/x11_fullscreen.c +++ b/src/x11_fullscreen.c @@ -334,7 +334,8 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) 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; } From c18eda3a1a7fe805a851cf6cd16a8411025e0d49 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 4 Oct 2011 01:06:43 +0200 Subject: [PATCH 07/22] Added error messages. --- src/fullscreen.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/fullscreen.c b/src/fullscreen.c index 7cc96bb7..631f6193 100644 --- a/src/fullscreen.c +++ b/src/fullscreen.c @@ -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; } From e290430c264b6d5d73703c4e51e686393d103f53 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 5 Oct 2011 00:46:09 +0200 Subject: [PATCH 08/22] Fixed closing bug. --- tests/reopen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/reopen.c b/tests/reopen.c index 5040697f..2922cb84 100644 --- a/tests/reopen.c +++ b/tests/reopen.c @@ -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; } From 2f7f7ca06f3b295bf33b80f8b5d16fb1521b82ac Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 5 Oct 2011 00:46:56 +0200 Subject: [PATCH 09/22] Fixed color of window. --- tests/windows.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/windows.c b/tests/windows.c index ddb8a224..c7ff32b2 100644 --- a/tests/windows.c +++ b/tests/windows.c @@ -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) From 0322d8fba047bf02b68195e5021042c0cd0d39db Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 5 Oct 2011 00:47:39 +0200 Subject: [PATCH 10/22] Made Win32 port build (functionality soon). --- src/win32_platform.h | 2 +- src/win32_window.c | 102 ++++++++++++++++++++++++++++--------------- 2 files changed, 67 insertions(+), 37 deletions(-) diff --git a/src/win32_platform.h b/src/win32_platform.h index db5b82ae..6b61cb77 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -251,7 +251,7 @@ typedef struct _GLFWwindowWin32 // Various platform specific internal variables int desiredRefreshRate; // Desired vertical monitor refresh rate - GLboolean mouseMoved; + GLboolean cursorCentered; int oldMouseX, oldMouseY; } _GLFWwindowWin32; diff --git a/src/win32_window.c b/src/win32_window.c index 1bfef9f5..e975235b 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -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 //======================================================================== @@ -1761,7 +1805,7 @@ 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; } @@ -1846,41 +1890,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 +1906,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; + } +} + From 1960d1ebb1484bc7b38187239a5eea64e78de77b Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sat, 8 Oct 2011 23:41:30 +0200 Subject: [PATCH 11/22] Added error setting for more cases of invalid tokens. --- src/enable.c | 2 ++ src/input.c | 2 +- src/window.c | 9 ++++----- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/enable.c b/src/enable.c index 82ba940c..897f0753 100644 --- a/src/enable.c +++ b/src/enable.c @@ -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; } } diff --git a/src/input.c b/src/input.c index 04c835a4..8845b758 100644 --- a/src/input.c +++ b/src/input.c @@ -53,7 +53,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; } diff --git a/src/window.c b/src/window.c index a39125ef..2e49b868 100644 --- a/src/window.c +++ b/src/window.c @@ -468,6 +468,7 @@ GLFWAPI void glfwOpenWindowHint(int target, int hint) _glfwLibrary.hints.glRobustness = hint; break; default: + _glfwSetError(GLFW_INVALID_ENUM, NULL); break; } } @@ -748,12 +749,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; } From 65f074d2574fb2dccee9818a03fc93a07c115530 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sat, 8 Oct 2011 23:57:03 +0200 Subject: [PATCH 12/22] Formatting. --- src/opengl.c | 1 + src/window.c | 1 + src/x11_enable.c | 1 + src/x11_window.c | 2 ++ 4 files changed, 5 insertions(+) diff --git a/src/opengl.c b/src/opengl.c index d75eee8f..f4c6984c 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -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 diff --git a/src/window.c b/src/window.c index 2e49b868..06c32b8d 100644 --- a/src/window.c +++ b/src/window.c @@ -817,6 +817,7 @@ GLFWAPI void glfwSetWindowSizeCallback(GLFWwindowsizefun cbfun) } } + //======================================================================== // Set callback function for window close events //======================================================================== diff --git a/src/x11_enable.c b/src/x11_enable.c index 9b439385..49961395 100644 --- a/src/x11_enable.c +++ b/src/x11_enable.c @@ -48,6 +48,7 @@ void _glfwPlatformEnableSystemKeys(_GLFWwindow* window) } } + //======================================================================== // Disable system keys //======================================================================== diff --git a/src/x11_window.c b/src/x11_window.c index a05b121c..962da7fb 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -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 //======================================================================== From ebffe58369254a3a4b52785e7a828d9228e144d4 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 9 Oct 2011 00:01:44 +0200 Subject: [PATCH 13/22] Renamed version to glfwinfo. --- readme.html | 3 ++- tests/CMakeLists.txt | 6 +++--- tests/{version.c => glfwinfo.c} | 0 3 files changed, 5 insertions(+), 4 deletions(-) rename tests/{version.c => glfwinfo.c} (100%) diff --git a/readme.html b/readme.html index 65fbf372..a028b45b 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 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
  • Replaced mouse wheel interface with two-dimensional scrolling interface
  • @@ -302,7 +303,7 @@ version of GLFW.

  • Removed GLFW_OPENED window parameter
  • Removed nonsensical key actions for Unicode character input
  • Removed GLFWCALL and GLFWAPIENTRY macros for stdcall calling convention
  • -
  • Bugfix: The default OpenGL version in the version test was set to 1.1
  • +
  • Bugfix: The default OpenGL version in the glfwinfo test was set to 1.1
  • Bugfix: The OpenGL profile and forward-compatibility window parameters were not saved after context creation
  • Bugfix: The FSAA test did not check for the availability of GL_ARB_multisample
  • [Cocoa] Added support for OpenGL 3.2 core profile in 10.7 Lion and above
  • diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9ef07acc..b85d79b4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,12 +10,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 @@ -32,8 +32,8 @@ else() endif(APPLE) set(WINDOWS_BINARIES accuracy sharing tearing windows) -set(CONSOLE_BINARIES defaults events fsaa fsfocus gamma iconify joysticks - listmodes peter reopen version) +set(CONSOLE_BINARIES 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 diff --git a/tests/version.c b/tests/glfwinfo.c similarity index 100% rename from tests/version.c rename to tests/glfwinfo.c From 792034c42d382391008f00725f6d5a3abe160cd9 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 9 Oct 2011 00:55:39 +0200 Subject: [PATCH 14/22] 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 15/22] 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 16/22] 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 17/22] 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 18/22] 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 19/22] 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 20/22] 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 21/22] 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 22/22] 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;