From a98c66c8cb31061d2ec8781eac2bea25cb2fe02d Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 22 Sep 2011 14:15:07 +0200 Subject: [PATCH 1/8] 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 2/8] 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 3/8] 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 4/8] 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 5/8] 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 6/8] 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 7/8] 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 8/8] 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; + } +} +