From 596132c3a1becceb0ba6d10991d52a85ba8f201c Mon Sep 17 00:00:00 2001 From: Riku Salminen Date: Tue, 21 Aug 2012 21:01:57 +0300 Subject: [PATCH 01/27] Add glfwShowWindow, glfwHideWindow Add glfwShowWindow and glfwHideWindow functions to allow explicit control over show/hide window. Remove platform specific show window code from _glfwPlatformCreateWindow but call glfwShowWindow from glfwCreateWindow to avoid breaking things (for now). --- include/GL/glfw3.h | 2 + src/cocoa_window.m | 20 +++++++- src/internal.h | 2 + src/win32_window.c | 114 +++++++++------------------------------------ src/window.c | 34 ++++++++++++++ src/x11_window.c | 26 +++++++++-- 6 files changed, 101 insertions(+), 97 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 050f0c30..79b6033a 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -540,6 +540,8 @@ GLFWAPI void glfwGetWindowPos(GLFWwindow, int* xpos, int* ypos); GLFWAPI void glfwSetWindowPos(GLFWwindow, int xpos, int ypos); GLFWAPI void glfwIconifyWindow(GLFWwindow window); GLFWAPI void glfwRestoreWindow(GLFWwindow window); +GLFWAPI void glfwShowWindow(GLFWwindow window); +GLFWAPI void glfwHideWindow(GLFWwindow window); GLFWAPI int glfwGetWindowParam(GLFWwindow window, int param); GLFWAPI void glfwSetWindowUserPointer(GLFWwindow window, void* pointer); GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow window); diff --git a/src/cocoa_window.m b/src/cocoa_window.m index d7764f92..db6d07b8 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -906,7 +906,6 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, if (!createContext(window, wndconfig, fbconfig)) return GL_FALSE; - [window->NS.object makeKeyAndOrderFront:nil]; [window->NSGL.context setView:[window->NS.object contentView]]; if (wndconfig->mode == GLFW_FULLSCREEN) @@ -1030,6 +1029,25 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window) } +//======================================================================== +// Show window +//======================================================================== + +void _glfwPlatformShowWindow(_GLFWwindow* window) +{ + [window->NS.object makeKeyAndOrderFront:nil]; +} + + +//======================================================================== +// Hide window +//======================================================================== + +void _glfwPlatformHideWindow(_GLFWwindow* window) +{ + [window->NS.object orderOut:nil]; +} + //======================================================================== // Write back window parameters into GLFW window structure //======================================================================== diff --git a/src/internal.h b/src/internal.h index 89ac48b2..1bad7483 100644 --- a/src/internal.h +++ b/src/internal.h @@ -302,6 +302,8 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height); void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y); void _glfwPlatformIconifyWindow(_GLFWwindow* window); void _glfwPlatformRestoreWindow(_GLFWwindow* window); +void _glfwPlatformShowWindow(_GLFWwindow* window); +void _glfwPlatformHideWindow(_GLFWwindow* window); // Event management void _glfwPlatformPollEvents(void); diff --git a/src/win32_window.c b/src/win32_window.c index 77b99026..ff6941ab 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -34,95 +34,6 @@ #include #include - -//======================================================================== -// Enable/disable minimize/restore animations -//======================================================================== - -static int setMinMaxAnimations(int enable) -{ - ANIMATIONINFO AI; - int old_enable; - - // Get old animation setting - AI.cbSize = sizeof(ANIMATIONINFO); - SystemParametersInfo(SPI_GETANIMATION, AI.cbSize, &AI, 0); - old_enable = AI.iMinAnimate; - - // If requested, change setting - if (old_enable != enable) - { - AI.iMinAnimate = enable; - SystemParametersInfo(SPI_SETANIMATION, AI.cbSize, &AI, - SPIF_SENDCHANGE); - } - - return old_enable; -} - - -//======================================================================== -// Focus the window and bring it to the top of the stack -// Due to some nastiness with how XP handles SetForegroundWindow we have -// to go through some really bizarre measures to achieve this -//======================================================================== - -static void setForegroundWindow(HWND hWnd) -{ - int try_count = 0; - int old_animate; - - // Try the standard approach first... - BringWindowToTop(hWnd); - SetForegroundWindow(hWnd); - - // If it worked, return now - if (hWnd == GetForegroundWindow()) - { - // Try to modify the system settings (since this is the foreground - // process, we are allowed to do this) - SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID) 0, - SPIF_SENDCHANGE); - return; - } - - // For other Windows versions than 95 & NT4.0, the standard approach - // may not work, so if we failed we have to "trick" Windows into - // making our window the foureground window: Iconify and restore - // again. It is ugly, but it seems to work (we turn off those annoying - // zoom animations to make it look a bit better at least). - - // Turn off minimize/restore animations - old_animate = setMinMaxAnimations(0); - - // We try this a few times, just to be on the safe side of things... - do - { - // Iconify & restore - ShowWindow(hWnd, SW_HIDE); - ShowWindow(hWnd, SW_SHOWMINIMIZED); - ShowWindow(hWnd, SW_SHOWNORMAL); - - // Try to get focus - BringWindowToTop(hWnd); - SetForegroundWindow(hWnd); - - // We do not want to keep going on forever, so we keep track of - // how many times we tried - try_count++; - } - while (hWnd != GetForegroundWindow() && try_count <= 3); - - // Restore the system minimize/restore animation setting - setMinMaxAnimations(old_animate); - - // Try to modify the system settings (since this is now hopefully the - // foreground process, we are probably allowed to do this) - SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID) 0, - SPIF_SENDCHANGE); -} - - //======================================================================== // Hide mouse cursor //======================================================================== @@ -1071,9 +982,6 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, SWP_NOMOVE | SWP_NOSIZE); } - setForegroundWindow(window->Win32.handle); - SetFocus(window->Win32.handle); - return GL_TRUE; } @@ -1193,6 +1101,28 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window) } +//======================================================================== +// Show or hide window +//======================================================================== + +void _glfwPlatformShowWindow(_GLFWwindow* window) +{ + ShowWindow(window->Win32.handle, SW_SHOWNORMAL); + BringWindowToTop(window->Win32.handle); + SetForegroundWindow(window->Win32.handle); + SetFocus(window->Win32.handle); +} + + +//======================================================================== +// Show or hide window +//======================================================================== + +void _glfwPlatformHideWindow(_GLFWwindow* window) +{ + ShowWindow(window->Win32.handle, SW_HIDE); +} + //======================================================================== // Write back window parameters into GLFW window structure //======================================================================== diff --git a/src/window.c b/src/window.c index 4e95129a..efaa1572 100644 --- a/src/window.c +++ b/src/window.c @@ -318,6 +318,8 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height, return GL_FALSE; } + glfwShowWindow(window, 1); // TODO: consider if this is necessary! + // Cache the actual (as opposed to requested) window parameters _glfwPlatformRefreshWindowParams(window); @@ -623,6 +625,38 @@ GLFWAPI void glfwIconifyWindow(GLFWwindow handle) } +//======================================================================== +// Window show +//======================================================================== + +GLFWAPI void glfwShowWindow(GLFWwindow window) +{ + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED, NULL); + return; + } + + _glfwPlatformShowWindow((_GLFWwindow*)window); +} + + +//======================================================================== +// Window hide +//======================================================================== + +GLFWAPI void glfwHideWindow(GLFWwindow window) +{ + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED, NULL); + return; + } + + _glfwPlatformHideWindow((_GLFWwindow*)window); +} + + //======================================================================== // Window un-iconification //======================================================================== diff --git a/src/x11_window.c b/src/x11_window.c index 442e76c0..90938ccb 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -230,10 +230,6 @@ static GLboolean createWindow(_GLFWwindow* window, _glfwPlatformSetWindowTitle(window, wndconfig->title); - // Make sure the window is mapped before proceeding - XMapWindow(_glfwLibrary.X11.display, window->X11.handle); - XFlush(_glfwLibrary.X11.display); - return GL_TRUE; } @@ -1099,6 +1095,28 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window) } +//======================================================================== +// Show window +//======================================================================== + +void _glfwPlatformShowWindow(_GLFWwindow* window) +{ + XMapRaised(_glfwLibrary.X11.display, window->X11.handle); + XFlush(_glfwLibrary.X11.display); +} + + +//======================================================================== +// Hide window +//======================================================================== + +void _glfwPlatformHideWindow(_GLFWwindow* window) +{ + XUnmapWindow(_glfwLibrary.X11.display, window->X11.handle); + XFlush(_glfwLibrary.X11.display); +} + + //======================================================================== // Read back framebuffer parameters from the context //======================================================================== From a2ca095b869c0c8255cf678e354f44a4aac87120 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 21 Aug 2012 20:28:36 +0200 Subject: [PATCH 02/27] Renamed GLFW_WINDOW_RESIZABLE to GLFW_RESIZABLE. This matches GLFW_ACTIVE and GLFW_ICONIFIED. --- examples/heightmap.c | 2 +- include/GL/glfw3.h | 14 +++++++------- readme.html | 2 +- src/window.c | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/heightmap.c b/examples/heightmap.c index fce8b8de..5139a493 100644 --- a/examples/heightmap.c +++ b/examples/heightmap.c @@ -581,7 +581,7 @@ int main(int argc, char** argv) exit(EXIT_FAILURE); } - glfwWindowHint(GLFW_WINDOW_RESIZABLE, GL_FALSE); + glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); glfwWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 79b6033a..5472f8b1 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -405,18 +405,18 @@ extern "C" { #define GLFW_ACCUM_ALPHA_BITS 0x0002100A #define GLFW_AUX_BUFFERS 0x0002100B #define GLFW_STEREO 0x0002100C -#define GLFW_WINDOW_RESIZABLE 0x0002100D #define GLFW_FSAA_SAMPLES 0x0002100E /* The following constants are used with both glfwGetWindowParam * and glfwWindowHint */ -#define GLFW_OPENGL_VERSION_MAJOR 0x0002100F -#define GLFW_OPENGL_VERSION_MINOR 0x00021010 -#define GLFW_OPENGL_FORWARD_COMPAT 0x00021011 -#define GLFW_OPENGL_DEBUG_CONTEXT 0x00021012 -#define GLFW_OPENGL_PROFILE 0x00021013 -#define GLFW_OPENGL_ROBUSTNESS 0x00021014 +#define GLFW_OPENGL_VERSION_MAJOR 0x00022000 +#define GLFW_OPENGL_VERSION_MINOR 0x00022001 +#define GLFW_OPENGL_FORWARD_COMPAT 0x00022002 +#define GLFW_OPENGL_DEBUG_CONTEXT 0x00022003 +#define GLFW_OPENGL_PROFILE 0x00022004 +#define GLFW_OPENGL_ROBUSTNESS 0x00022005 +#define GLFW_RESIZABLE 0x00022006 /* GLFW_OPENGL_ROBUSTNESS mode tokens */ #define GLFW_OPENGL_NO_ROBUSTNESS 0x00000000 diff --git a/readme.html b/readme.html index 39d0739b..580e21cd 100644 --- a/readme.html +++ b/readme.html @@ -296,7 +296,7 @@ version of GLFW.

  • Renamed glfw.h to glfw3.h to avoid conflicts with 2.x series
  • Renamed glfwOpenWindowHint to glfwWindowHint
  • Renamed GLFW_WINDOW token to GLFW_WINDOWED
  • -
  • Renamed GLFW_WINDOW_NO_RESIZE to GLFW_WINDOW_RESIZABLE
  • +
  • Renamed GLFW_WINDOW_NO_RESIZE to GLFW_RESIZABLE
  • Renamed GLFW_BUILD_DLL to _GLFW_BUILD_DLL
  • Renamed version test to glfwinfo
  • Renamed GLFW_NO_GLU to GLFW_INCLUDE_GLU and made it disabled by default
  • diff --git a/src/window.c b/src/window.c index efaa1572..81b0492c 100644 --- a/src/window.c +++ b/src/window.c @@ -410,7 +410,7 @@ GLFWAPI void glfwWindowHint(int target, int hint) case GLFW_STEREO: _glfwLibrary.hints.stereo = hint; break; - case GLFW_WINDOW_RESIZABLE: + case GLFW_RESIZABLE: _glfwLibrary.hints.resizable = hint; break; case GLFW_FSAA_SAMPLES: @@ -705,7 +705,7 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow handle, int param) return window->closeRequested; case GLFW_REFRESH_RATE: return window->refreshRate; - case GLFW_WINDOW_RESIZABLE: + case GLFW_RESIZABLE: return window->resizable; case GLFW_OPENGL_VERSION_MAJOR: return window->glMajor; From 3d2722dc4c638e7c3af9fea0c58a208cee1a3944 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 21 Aug 2012 20:32:44 +0200 Subject: [PATCH 03/27] Fixed broken call to glfwShowWindow. --- src/window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/window.c b/src/window.c index 81b0492c..4f8a96e6 100644 --- a/src/window.c +++ b/src/window.c @@ -318,7 +318,7 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height, return GL_FALSE; } - glfwShowWindow(window, 1); // TODO: consider if this is necessary! + glfwShowWindow(window); // Cache the actual (as opposed to requested) window parameters _glfwPlatformRefreshWindowParams(window); From 8bb5c59d2d01ccc6e1247b5680e7d962fb81de80 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 21 Aug 2012 21:18:09 +0200 Subject: [PATCH 04/27] Added GLFW_VISIBLE window hint and parameter. --- include/GL/glfw3.h | 1 + readme.html | 1 + src/cocoa_window.m | 16 ++++++++++++++++ src/internal.h | 4 ++++ src/win32_window.c | 6 ++++++ src/window.c | 22 +++++++++++++++++++--- src/x11_window.c | 2 ++ 7 files changed, 49 insertions(+), 3 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 5472f8b1..6f535408 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -417,6 +417,7 @@ extern "C" { #define GLFW_OPENGL_PROFILE 0x00022004 #define GLFW_OPENGL_ROBUSTNESS 0x00022005 #define GLFW_RESIZABLE 0x00022006 +#define GLFW_VISIBLE 0x00022007 /* GLFW_OPENGL_ROBUSTNESS mode tokens */ #define GLFW_OPENGL_NO_ROBUSTNESS 0x00000000 diff --git a/readme.html b/readme.html index 580e21cd..c6eedbf3 100644 --- a/readme.html +++ b/readme.html @@ -283,6 +283,7 @@ version of GLFW.

  • Added GLFW_OPENGL_ROBUSTNESS window hint and associated strategy tokens for GL_ARB_robustness support
  • Added GLFW_OPENGL_REVISION window parameter to make up for removal of glfwGetGLVersion
  • Added GLFW_INCLUDE_GL3 macro for telling the GLFW header to include gl3.h header instead of gl.h
  • +
  • Added GLFW_VISIBLE window hint and parameter for controlling and polling window visibility
  • Added windows simple multi-window test program
  • Added sharing simple OpenGL object sharing test program
  • Added modes video mode enumeration and setting test program
  • diff --git a/src/cocoa_window.m b/src/cocoa_window.m index db6d07b8..0d62b0fa 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -131,6 +131,22 @@ return NSTerminateCancel; } +- (void)applicationDidHide:(NSNotification *)notification +{ + _GLFWwindow* window; + + for (window = _glfwLibrary.windowListHead; window; window = window->next) + _glfwInputWindowVisibility(window, GL_FALSE); +} + +- (void)applicationDidUnhide:(NSNotification *)notification +{ + _GLFWwindow* window; + + for (window = _glfwLibrary.windowListHead; window; window = window->next) + _glfwInputWindowVisibility(window, GL_TRUE); +} + @end diff --git a/src/internal.h b/src/internal.h index 1bad7483..8e923d50 100644 --- a/src/internal.h +++ b/src/internal.h @@ -109,6 +109,7 @@ struct _GLFWhints int auxBuffers; GLboolean stereo; GLboolean resizable; + GLboolean visible; int samples; int glMajor; int glMinor; @@ -131,6 +132,7 @@ struct _GLFWwndconfig const char* title; int refreshRate; GLboolean resizable; + GLboolean visible; int glMajor; int glMinor; GLboolean glForward; @@ -181,6 +183,7 @@ struct _GLFWwindow int positionX, positionY; int mode; // GLFW_WINDOW or GLFW_FULLSCREEN GLboolean resizable; // GL_TRUE if user may resize this window + GLboolean visible; // GL_TRUE if this window is visible int refreshRate; // monitor refresh rate void* userPointer; @@ -338,6 +341,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 _glfwInputWindowVisibility(_GLFWwindow* window, int visible); void _glfwInputWindowDamage(_GLFWwindow* window); void _glfwInputWindowCloseRequest(_GLFWwindow* window); diff --git a/src/win32_window.c b/src/win32_window.c index ff6941ab..b83d504a 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -418,6 +418,12 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, return 0; } + case WM_SHOWWINDOW: + { + _glfwInputWindowVisibility(window, wParam ? GL_TRUE : GL_FALSE); + break; + } + case WM_SYSCOMMAND: { switch (wParam & 0xfff0) diff --git a/src/window.c b/src/window.c index 4f8a96e6..7e928cf2 100644 --- a/src/window.c +++ b/src/window.c @@ -82,8 +82,9 @@ void _glfwSetDefaultWindowHints(void) _glfwLibrary.hints.glMajor = 1; _glfwLibrary.hints.glMinor = 0; - // The default is to allow window resizing + // The default is to show the window and allow window resizing _glfwLibrary.hints.resizable = GL_TRUE; + _glfwLibrary.hints.visible = GL_TRUE; } @@ -176,6 +177,16 @@ void _glfwInputWindowIconify(_GLFWwindow* window, int iconified) } +//======================================================================== +// Register window visibility events +//======================================================================== + +void _glfwInputWindowVisibility(_GLFWwindow* window, int visible) +{ + window->visible = visible; +} + + //======================================================================== // Register window damage events //======================================================================== @@ -246,6 +257,7 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height, wndconfig.title = title; wndconfig.refreshRate = Max(_glfwLibrary.hints.refreshRate, 0); wndconfig.resizable = _glfwLibrary.hints.resizable ? GL_TRUE : GL_FALSE; + wndconfig.visible = _glfwLibrary.hints.visible ? GL_TRUE : GL_FALSE; wndconfig.glMajor = _glfwLibrary.hints.glMajor; wndconfig.glMinor = _glfwLibrary.hints.glMinor; wndconfig.glForward = _glfwLibrary.hints.glForward ? GL_TRUE : GL_FALSE; @@ -318,8 +330,6 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height, return GL_FALSE; } - glfwShowWindow(window); - // Cache the actual (as opposed to requested) window parameters _glfwPlatformRefreshWindowParams(window); @@ -353,6 +363,9 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height, glClear(GL_COLOR_BUFFER_BIT); _glfwPlatformSwapBuffers(window); + if (wndconfig.visible) + glfwShowWindow(window); + return window; } @@ -413,6 +426,9 @@ GLFWAPI void glfwWindowHint(int target, int hint) case GLFW_RESIZABLE: _glfwLibrary.hints.resizable = hint; break; + case GLFW_VISIBLE: + _glfwLibrary.hints.visible = hint; + break; case GLFW_FSAA_SAMPLES: _glfwLibrary.hints.samples = hint; break; diff --git a/src/x11_window.c b/src/x11_window.c index 90938ccb..b4d62605 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -736,6 +736,7 @@ static void processSingleEvent(void) return; } + _glfwInputWindowVisibility(window, GL_TRUE); _glfwInputWindowIconify(window, GL_FALSE); break; } @@ -750,6 +751,7 @@ static void processSingleEvent(void) return; } + _glfwInputWindowVisibility(window, GL_FALSE); _glfwInputWindowIconify(window, GL_TRUE); break; } From 85576bcb453762008f9c2e609ec310f3a3f85ebd Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 21 Aug 2012 21:19:30 +0200 Subject: [PATCH 05/27] Added credit. --- readme.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/readme.html b/readme.html index c6eedbf3..dd80672e 100644 --- a/readme.html +++ b/readme.html @@ -926,6 +926,9 @@ their skills. Special thanks go out to:

  • Arturo J. PĂ©rez, for a bug fix for cursor tracking on Mac OS X 10.6 Snow Leopard
  • +
  • Riku Salminen, for the initial implementation of + glfwShowWindow and glfwHideWindow
  • +
  • Douglas C. Schmidt and Irfan Pyarali, for their excellent article Strategies for Implementing POSIX Condition Variables on Win32
  • From b665903e14df43f9ca0b9fa8835cabfc022b3bd4 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 21 Aug 2012 21:19:33 +0200 Subject: [PATCH 06/27] Added testing of glfwShowWindow and GLFW_VISIBLE. --- tests/windows.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/windows.c b/tests/windows.c index 894febeb..f4c74bfd 100644 --- a/tests/windows.c +++ b/tests/windows.c @@ -55,6 +55,8 @@ int main(void) for (i = 0; i < 4; i++) { + glfwWindowHint(GLFW_VISIBLE, GL_FALSE); + windows[i] = glfwCreateWindow(200, 200, GLFW_WINDOWED, titles[i], NULL); if (!windows[i]) { @@ -71,6 +73,7 @@ int main(void) 0.f); glfwSetWindowPos(windows[i], 100 + (i & 1) * 300, 100 + (i >> 1) * 300); + glfwShowWindow(windows[i]); } while (running) From 0e63488b407f4f2f1d3ae99ea7b366fa647bcdec Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 21 Aug 2012 21:35:42 +0200 Subject: [PATCH 07/27] Cocoa window visibility fixes. --- src/cocoa_window.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 0d62b0fa..35bdd974 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -144,7 +144,10 @@ _GLFWwindow* window; for (window = _glfwLibrary.windowListHead; window; window = window->next) - _glfwInputWindowVisibility(window, GL_TRUE); + { + if ([window->NS.object isVisible]) + _glfwInputWindowVisibility(window, GL_TRUE); + } } @end @@ -1052,6 +1055,7 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window) void _glfwPlatformShowWindow(_GLFWwindow* window) { [window->NS.object makeKeyAndOrderFront:nil]; + _glfwInputWindowVisibility(window, GL_TRUE); } @@ -1062,6 +1066,7 @@ void _glfwPlatformShowWindow(_GLFWwindow* window) void _glfwPlatformHideWindow(_GLFWwindow* window) { [window->NS.object orderOut:nil]; + _glfwInputWindowVisibility(window, GL_FALSE); } //======================================================================== From f6a1bbf782a0fd3e6e460997c3cea529bb85868f Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 21 Aug 2012 21:57:13 +0200 Subject: [PATCH 08/27] Added GLFW_VISIBLE to glfwWindowParam. --- src/window.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/window.c b/src/window.c index 7e928cf2..2507dd5c 100644 --- a/src/window.c +++ b/src/window.c @@ -723,6 +723,8 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow handle, int param) return window->refreshRate; case GLFW_RESIZABLE: return window->resizable; + case GLFW_VISIBLE: + return window->visible; case GLFW_OPENGL_VERSION_MAJOR: return window->glMajor; case GLFW_OPENGL_VERSION_MINOR: From f5bfe41456d6f4bfbe4c1ac4c5eb0ef23cc545c7 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 28 Aug 2012 17:52:22 +0200 Subject: [PATCH 09/27] Moved GLFW_VISIBLE hint use to glfwinfo. --- tests/glfwinfo.c | 2 ++ tests/windows.c | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/glfwinfo.c b/tests/glfwinfo.c index 90fd329f..0019bf66 100644 --- a/tests/glfwinfo.c +++ b/tests/glfwinfo.c @@ -207,6 +207,8 @@ int main(int argc, char** argv) if (strategy) glfwWindowHint(GLFW_OPENGL_ROBUSTNESS, strategy); + glfwWindowHint(GLFW_VISIBLE, GL_FALSE); + // We assume here that we stand a better chance of success by leaving all // possible details of pixel format selection to GLFW diff --git a/tests/windows.c b/tests/windows.c index f4c74bfd..894febeb 100644 --- a/tests/windows.c +++ b/tests/windows.c @@ -55,8 +55,6 @@ int main(void) for (i = 0; i < 4; i++) { - glfwWindowHint(GLFW_VISIBLE, GL_FALSE); - windows[i] = glfwCreateWindow(200, 200, GLFW_WINDOWED, titles[i], NULL); if (!windows[i]) { @@ -73,7 +71,6 @@ int main(void) 0.f); glfwSetWindowPos(windows[i], 100 + (i & 1) * 300, 100 + (i >> 1) * 300); - glfwShowWindow(windows[i]); } while (running) From d5ede068593638647eae61ce3984f20403927bb5 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 28 Aug 2012 21:37:07 +0200 Subject: [PATCH 10/27] Removed WS_VISIBLE from creation flags. --- src/win32_window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/win32_window.c b/src/win32_window.c index 5a74955e..13096073 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -753,7 +753,7 @@ static int createWindow(_GLFWwindow* window, WCHAR* wideTitle; // Set common window styles - dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE; + dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN; dwExStyle = WS_EX_APPWINDOW; // Set window style, depending on fullscreen mode From 7be55239e73c306d8fa5543ff969dda2b26cf9d2 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 10 Sep 2012 21:45:06 +0200 Subject: [PATCH 11/27] Disabled native API by default. --- CMakeLists.txt | 8 +++++++- src/CMakeLists.txt | 20 +++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 14eaceb3..c72e00ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ set(LIB_SUFFIX "" CACHE STRING "Takes an empty string or 64. Directory where lib option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" ON) option(GLFW_BUILD_TESTS "Build the GLFW test programs" ON) +option(GLFW_NATIVE_API "Build the GLFW native API" OFF) option(BUILD_SHARED_LIBS "Build shared libraries" OFF) find_package(OpenGL REQUIRED) @@ -259,7 +260,12 @@ configure_file(${GLFW_SOURCE_DIR}/src/config.h.in # The src directory's CMakeLists.txt file installs the library #-------------------------------------------------------------------- install(DIRECTORY include/GL DESTINATION include - FILES_MATCHING PATTERN glfw3.h PATTERN glfw3native.h) + FILES_MATCHING PATTERN glfw3.h) + +if (GLFW_NATIVE_API) + install(DIRECTORY include/GL DESTINATION include + FILES_MATCHING PATTERN glfw3native.h) +endif() install(FILES COPYING.txt readme.html DESTINATION share/doc/glfw-${GLFW_VERSION_FULL}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index eaf37325..ec5508c2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,7 +10,11 @@ if (_GLFW_COCOA_NSGL) set(glfw_HEADERS ${common_HEADERS} cocoa_platform.h) set(glfw_SOURCES ${common_SOURCES} cocoa_clipboard.m cocoa_fullscreen.m cocoa_gamma.c cocoa_init.m cocoa_input.m cocoa_joystick.m - cocoa_native.m cocoa_opengl.m cocoa_time.c cocoa_window.m) + cocoa_opengl.m cocoa_time.c cocoa_window.m) + + if (GLFW_NATIVE_API) + list(APPEND glfw_SOURCES cocoa_native.m) + endif() # For some reason, CMake doesn't know about .m set_source_files_properties(${glfw_SOURCES} PROPERTIES LANGUAGE C) @@ -18,14 +22,20 @@ elseif (_GLFW_WIN32_WGL) set(glfw_HEADERS ${common_HEADERS} win32_platform.h) set(glfw_SOURCES ${common_SOURCES} win32_clipboard.c win32_fullscreen.c win32_gamma.c win32_init.c win32_input.c win32_joystick.c - win32_native.c win32_opengl.c win32_time.c win32_window.c - win32_dllmain.c) + win32_opengl.c win32_time.c win32_window.c win32_dllmain.c) + + if (GLFW_NATIVE_API) + list(APPEND glfw_SOURCES win32_native.c) + endif() elseif (_GLFW_X11_GLX) set(glfw_HEADERS ${common_HEADERS} x11_platform.h) set(glfw_SOURCES ${common_SOURCES} x11_clipboard.c x11_fullscreen.c x11_gamma.c x11_init.c x11_input.c x11_joystick.c - x11_keysym2unicode.c x11_native.c x11_opengl.c x11_time.c - x11_window.c) + x11_keysym2unicode.c x11_opengl.c x11_time.c x11_window.c) + + if (GLFW_NATIVE_API) + list(APPEND glfw_SOURCES x11_native.c) + endif() endif() add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS}) From d214bfdfded62ac933e4388f55597c0ab00a83e4 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 11 Sep 2012 22:23:35 +0200 Subject: [PATCH 12/27] Made defaults test window hidden. --- tests/defaults.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/defaults.c b/tests/defaults.c index 391b4984..2877cfd9 100644 --- a/tests/defaults.c +++ b/tests/defaults.c @@ -83,6 +83,8 @@ int main(void) exit(EXIT_FAILURE); } + glfwWindowHint(GLFW_VISIBLE, GL_FALSE); + window = glfwCreateWindow(0, 0, GLFW_WINDOWED, "Defaults", NULL); if (!window) { From 023b816bcc3ce638bbab63fad38404d5632e5be2 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 11 Sep 2012 23:51:45 +0200 Subject: [PATCH 13/27] Disallowed hiding of fullscreen windows. --- src/window.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/window.c b/src/window.c index ab29725d..04e4f762 100644 --- a/src/window.c +++ b/src/window.c @@ -366,7 +366,7 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height, glClear(GL_COLOR_BUFFER_BIT); _glfwPlatformSwapBuffers(window); - if (wndconfig.visible) + if (wndconfig.visible || mode == GLFW_FULLSCREEN) glfwShowWindow(window); return window; @@ -649,15 +649,20 @@ GLFWAPI void glfwIconifyWindow(GLFWwindow handle) // Window show //======================================================================== -GLFWAPI void glfwShowWindow(GLFWwindow window) +GLFWAPI void glfwShowWindow(GLFWwindow handle) { + _GLFWwindow* window = (_GLFWwindow*) handle; + if (!_glfwInitialized) { _glfwSetError(GLFW_NOT_INITIALIZED, NULL); return; } - _glfwPlatformShowWindow((_GLFWwindow*)window); + if (window->mode == GLFW_FULLSCREEN) + return; + + _glfwPlatformShowWindow(window); } @@ -665,15 +670,20 @@ GLFWAPI void glfwShowWindow(GLFWwindow window) // Window hide //======================================================================== -GLFWAPI void glfwHideWindow(GLFWwindow window) +GLFWAPI void glfwHideWindow(GLFWwindow handle) { + _GLFWwindow* window = (_GLFWwindow*) handle; + if (!_glfwInitialized) { _glfwSetError(GLFW_NOT_INITIALIZED, NULL); return; } - _glfwPlatformHideWindow((_GLFWwindow*)window); + if (window->mode == GLFW_FULLSCREEN) + return; + + _glfwPlatformHideWindow(window); } From 0e2b12be4305e0636cb735839a5219b3b1065b22 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 11 Sep 2012 23:53:10 +0200 Subject: [PATCH 14/27] Corrected comment. --- src/window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/window.c b/src/window.c index 04e4f762..d4f063f5 100644 --- a/src/window.c +++ b/src/window.c @@ -877,7 +877,7 @@ GLFWAPI void glfwSetWindowIconifyCallback(GLFWwindowiconifyfun cbfun) //======================================================================== -// Poll for new window and input events and close any flagged windows +// Poll for new window and input events //======================================================================== GLFWAPI void glfwPollEvents(void) From e15e92b5838b06dc2835a7bff13292b0cc93a66f Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 11 Sep 2012 23:56:44 +0200 Subject: [PATCH 15/27] Fixed function grouping. --- src/window.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/window.c b/src/window.c index d4f063f5..b46065a7 100644 --- a/src/window.c +++ b/src/window.c @@ -645,6 +645,30 @@ GLFWAPI void glfwIconifyWindow(GLFWwindow handle) } +//======================================================================== +// Window un-iconification +//======================================================================== + +GLFWAPI void glfwRestoreWindow(GLFWwindow handle) +{ + _GLFWwindow* window = (_GLFWwindow*) handle; + + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED, NULL); + return; + } + + if (!window->iconified) + return; + + _glfwPlatformRestoreWindow(window); + + if (window->mode == GLFW_FULLSCREEN) + _glfwPlatformRefreshWindowParams(window); +} + + //======================================================================== // Window show //======================================================================== @@ -687,30 +711,6 @@ GLFWAPI void glfwHideWindow(GLFWwindow handle) } -//======================================================================== -// Window un-iconification -//======================================================================== - -GLFWAPI void glfwRestoreWindow(GLFWwindow handle) -{ - _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwSetError(GLFW_NOT_INITIALIZED, NULL); - return; - } - - if (!window->iconified) - return; - - _glfwPlatformRestoreWindow(window); - - if (window->mode == GLFW_FULLSCREEN) - _glfwPlatformRefreshWindowParams(window); -} - - //======================================================================== // Get window parameter //======================================================================== From 64c677be9e9e8e9ab693000b99ca61ae710ef0c5 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 12 Sep 2012 03:17:50 +0200 Subject: [PATCH 16/27] Renamed config macro to match convention. --- CMakeLists.txt | 2 +- src/config.h.in | 2 +- src/x11_init.c | 2 +- src/x11_joystick.c | 20 ++++++++++---------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c72e00ae..a1ad4923 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -184,7 +184,7 @@ if (_GLFW_X11_GLX) endif() if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") - set(_GLFW_USE_LINUX_JOYSTICKS 1) + set(_GLFW_HAS_LINUX_JOYSTICKS 1) endif() endif() diff --git a/src/config.h.in b/src/config.h.in index 01d541a2..a432d947 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -64,7 +64,7 @@ #cmakedefine _GLFW_HAS_GLXGETPROCADDRESSEXT // Define this to 1 if the Linux joystick API is available -#cmakedefine _GLFW_USE_LINUX_JOYSTICKS +#cmakedefine _GLFW_HAS_LINUX_JOYSTICKS // The GLFW version as used by glfwGetVersionString #define _GLFW_VERSION_FULL "@GLFW_VERSION_FULL@" diff --git a/src/x11_init.c b/src/x11_init.c index 32719cbf..666866de 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -719,7 +719,7 @@ const char* _glfwPlatformGetVersionString(void) #if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK) " clock_gettime" #endif -#if defined(_GLFW_USE_LINUX_JOYSTICKS) +#if defined(_GLFW_HAS_LINUX_JOYSTICKS) " Linux-joystick-API" #else " no-joystick-support" diff --git a/src/x11_joystick.c b/src/x11_joystick.c index c1fb62be..3d2f597d 100644 --- a/src/x11_joystick.c +++ b/src/x11_joystick.c @@ -30,7 +30,7 @@ #include "internal.h" -#ifdef _GLFW_USE_LINUX_JOYSTICKS +#ifdef _GLFW_HAS_LINUX_JOYSTICKS #include #include @@ -41,7 +41,7 @@ #include #include #include -#endif // _GLFW_USE_LINUX_JOYSTICKS +#endif // _GLFW_HAS_LINUX_JOYSTICKS //======================================================================== @@ -50,7 +50,7 @@ static int openJoystickDevice(int joy, const char* path) { -#ifdef _GLFW_USE_LINUX_JOYSTICKS +#ifdef _GLFW_HAS_LINUX_JOYSTICKS char numAxes, numButtons; int fd, version; @@ -97,7 +97,7 @@ static int openJoystickDevice(int joy, const char* path) } _glfwLibrary.X11.joystick[joy].present = GL_TRUE; -#endif // _GLFW_USE_LINUX_JOYSTICKS +#endif // _GLFW_HAS_LINUX_JOYSTICKS return GL_TRUE; } @@ -109,7 +109,7 @@ static int openJoystickDevice(int joy, const char* path) static void pollJoystickEvents(void) { -#ifdef _GLFW_USE_LINUX_JOYSTICKS +#ifdef _GLFW_HAS_LINUX_JOYSTICKS int i; ssize_t result; struct js_event e; @@ -160,7 +160,7 @@ static void pollJoystickEvents(void) } } } -#endif // _GLFW_USE_LINUX_JOYSTICKS +#endif // _GLFW_HAS_LINUX_JOYSTICKS } @@ -174,7 +174,7 @@ static void pollJoystickEvents(void) int _glfwInitJoysticks(void) { -#ifdef _GLFW_USE_LINUX_JOYSTICKS +#ifdef _GLFW_HAS_LINUX_JOYSTICKS int i, joy = 0; regex_t regex; DIR* dir; @@ -215,7 +215,7 @@ int _glfwInitJoysticks(void) } regfree(®ex); -#endif // _GLFW_USE_LINUX_JOYSTICKS +#endif // _GLFW_HAS_LINUX_JOYSTICKS return GL_TRUE; } @@ -227,7 +227,7 @@ int _glfwInitJoysticks(void) void _glfwTerminateJoysticks(void) { -#ifdef _GLFW_USE_LINUX_JOYSTICKS +#ifdef _GLFW_HAS_LINUX_JOYSTICKS int i; for (i = 0; i <= GLFW_JOYSTICK_LAST; i++) @@ -241,7 +241,7 @@ void _glfwTerminateJoysticks(void) _glfwLibrary.X11.joystick[i].present = GL_FALSE; } } -#endif // _GLFW_USE_LINUX_JOYSTICKS +#endif // _GLFW_HAS_LINUX_JOYSTICKS } From 6ac58da26e707ec50bdce04d4f497b5b1225b1a6 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 12 Sep 2012 21:18:37 +0200 Subject: [PATCH 17/27] Narrowed criteria for non-standard inclusion. --- src/fullscreen.c | 2 +- src/window.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fullscreen.c b/src/fullscreen.c index 4372d153..f59046d8 100644 --- a/src/fullscreen.c +++ b/src/fullscreen.c @@ -32,7 +32,7 @@ #include "internal.h" #include -#if _WIN32 +#if defined(_MSC_VER) #include #endif diff --git a/src/window.c b/src/window.c index b46065a7..817691de 100644 --- a/src/window.c +++ b/src/window.c @@ -33,7 +33,7 @@ #include #include -#if _WIN32 +#if defined(_MSC_VER) #include #endif From c4d5da00901b3cbc0d0a884628204de1495cf19b Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 12 Sep 2012 21:23:04 +0200 Subject: [PATCH 18/27] Moved DllMain into Win32 init module. --- src/CMakeLists.txt | 2 +- src/win32_dllmain.c | 49 --------------------------------------------- src/win32_init.c | 12 +++++++++++ 3 files changed, 13 insertions(+), 50 deletions(-) delete mode 100644 src/win32_dllmain.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ec5508c2..8a7bdec3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,7 +22,7 @@ elseif (_GLFW_WIN32_WGL) set(glfw_HEADERS ${common_HEADERS} win32_platform.h) set(glfw_SOURCES ${common_SOURCES} win32_clipboard.c win32_fullscreen.c win32_gamma.c win32_init.c win32_input.c win32_joystick.c - win32_opengl.c win32_time.c win32_window.c win32_dllmain.c) + win32_opengl.c win32_time.c win32_window.c) if (GLFW_NATIVE_API) list(APPEND glfw_SOURCES win32_native.c) diff --git a/src/win32_dllmain.c b/src/win32_dllmain.c deleted file mode 100644 index 98f9ab2a..00000000 --- a/src/win32_dllmain.c +++ /dev/null @@ -1,49 +0,0 @@ -//======================================================================== -// GLFW - An OpenGL library -// Platform: Win32 -// API version: 3.0 -// WWW: http://www.glfw.org/ -//------------------------------------------------------------------------ -// Copyright (c) 2002-2006 Marcus Geelnard -// Copyright (c) 2006-2010 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. -// -//======================================================================== - -#include "internal.h" - - -#if defined(_GLFW_BUILD_DLL) - -//======================================================================== -// GLFW DLL entry point -//======================================================================== - -BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) -{ - // NOTE: Some compilers complains about instance and x never being used - - // never mind that (we don't want to use them)! - - return TRUE; -} - -#endif // _GLFW_BUILD_DLL - diff --git a/src/win32_init.c b/src/win32_init.c index 41444b97..21de415b 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -39,6 +39,18 @@ #endif // __BORLANDC__ +//======================================================================== +// GLFW DLL entry point +//======================================================================== + +#if defined(_GLFW_BUILD_DLL) +BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) +{ + return TRUE; +} +#endif // _GLFW_BUILD_DLL + + //======================================================================== // Load necessary libraries (DLLs) //======================================================================== From 1d6d6bc3c6ae75a25c2f6aa5281f2b2c1138297f Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 12 Sep 2012 21:25:52 +0200 Subject: [PATCH 19/27] Moved display closing to after GL terminate. --- src/x11_init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/x11_init.c b/src/x11_init.c index 666866de..60a0add3 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -672,12 +672,12 @@ int _glfwPlatformTerminate(void) _glfwTerminateGammaRamp(); - terminateDisplay(); - _glfwTerminateJoysticks(); _glfwTerminateOpenGL(); + terminateDisplay(); + // Free clipboard memory if (_glfwLibrary.X11.selection.string) free(_glfwLibrary.X11.selection.string); From 18392837ac85261bd9448d8548173c49f4fc1514 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 12 Sep 2012 21:34:23 +0200 Subject: [PATCH 20/27] Formatting. --- src/gamma.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/gamma.c b/src/gamma.c index 21940b0e..eed0b66d 100644 --- a/src/gamma.c +++ b/src/gamma.c @@ -61,18 +61,15 @@ GLFWAPI void glfwSetGamma(float gamma) for (i = 0; i < size; i++) { - float value = (float) i / ((float) (size - 1)); + float value; - // Apply gamma + // Calculate intensity + value = (float) i / (float) (size - 1); + // Apply gamma curve value = (float) pow(value, 1.f / gamma) * 65535.f + 0.5f; + // Clamp to value range + value = (float) fmax(fmin(value, 65535.f), 0.f); - // Clamp values - if (value < 0.f) - value = 0.f; - else if (value > 65535.f) - value = 65535.f; - - // Set the gamma ramp values ramp.red[i] = (unsigned short) value; ramp.green[i] = (unsigned short) value; ramp.blue[i] = (unsigned short) value; From 4408d2134c7b2800eef8f1a29bf5331da4e8e6e4 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 12 Sep 2012 21:37:36 +0200 Subject: [PATCH 21/27] Added use of standard lParam macros. --- src/win32_window.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/win32_window.c b/src/win32_window.c index 13096073..735f9b97 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -33,6 +33,7 @@ #include #include #include +#include //======================================================================== // Hide mouse cursor @@ -559,8 +560,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, int newCursorX, newCursorY; // Get signed (!) cursor position - newCursorX = (int)((short)LOWORD(lParam)); - newCursorY = (int)((short)HIWORD(lParam)); + newCursorX = GET_X_LPARAM(lParam); + newCursorY = GET_Y_LPARAM(lParam); if (newCursorX != window->Win32.oldCursorX || newCursorY != window->Win32.oldCursorY) From d5e4204ed102e2fa118ea22518b88115ac3550e0 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 12 Sep 2012 21:46:40 +0200 Subject: [PATCH 22/27] POSIX threads should not be preferred on Win32. --- CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a1ad4923..abfee8c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,10 @@ option(BUILD_SHARED_LIBS "Build shared libraries" OFF) find_package(OpenGL REQUIRED) -set(CMAKE_THREAD_PREFER_PTHREADS YES) +if (NOT WIN32) + set(CMAKE_THREAD_PREFER_PTHREADS YES) +endif() + find_package(Threads) if (CMAKE_THREAD_LIBS_INIT) list(APPEND glfw_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) From 89018331f76d257d48aab9691ef872c2bba70aaa Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 13 Sep 2012 17:29:07 +0200 Subject: [PATCH 23/27] Fixed invalid uses of glfwDestroyWindow. --- tests/clipboard.c | 17 +++++++++++++---- tests/gamma.c | 12 ++++++++++-- tests/iconify.c | 17 +++++++++++++---- tests/modes.c | 32 ++++++++++++++++---------------- tests/peter.c | 20 ++++++++++++++------ tests/sharing.c | 19 +++++-------------- 6 files changed, 71 insertions(+), 46 deletions(-) diff --git a/tests/clipboard.c b/tests/clipboard.c index fcd1c307..f83bbfea 100644 --- a/tests/clipboard.c +++ b/tests/clipboard.c @@ -34,6 +34,8 @@ #include "getopt.h" +static GLboolean closed = GL_FALSE; + static void usage(void) { printf("Usage: clipboard [-h]\n"); @@ -45,6 +47,12 @@ static GLboolean control_is_down(GLFWwindow window) glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL); } +static int window_close_callback(GLFWwindow window) +{ + closed = GL_TRUE; + return GL_FALSE; +} + static void key_callback(GLFWwindow window, int key, int action) { if (action != GLFW_PRESS) @@ -53,7 +61,7 @@ static void key_callback(GLFWwindow window, int key, int action) switch (key) { case GLFW_KEY_ESCAPE: - glfwDestroyWindow(window); + closed = GL_TRUE; break; case GLFW_KEY_V: @@ -80,7 +88,7 @@ static void key_callback(GLFWwindow window, int key, int action) } } -static void size_callback(GLFWwindow window, int width, int height) +static void window_size_callback(GLFWwindow window, int width, int height) { glViewport(0, 0, width, height); } @@ -130,7 +138,8 @@ int main(int argc, char** argv) glfwSwapInterval(1); glfwSetKeyCallback(key_callback); - glfwSetWindowSizeCallback(size_callback); + glfwSetWindowSizeCallback(window_size_callback); + glfwSetWindowCloseCallback(window_close_callback); glMatrixMode(GL_PROJECTION); glOrtho(-1.f, 1.f, -1.f, 1.f, -1.f, 1.f); @@ -138,7 +147,7 @@ int main(int argc, char** argv) glClearColor(0.5f, 0.5f, 0.5f, 0); - while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED)) + while (!closed) { glClear(GL_COLOR_BUFFER_BIT); diff --git a/tests/gamma.c b/tests/gamma.c index e74d5b43..c30dd53c 100644 --- a/tests/gamma.c +++ b/tests/gamma.c @@ -37,6 +37,7 @@ #define STEP_SIZE 0.1f +static GLboolean closed = GL_FALSE; static GLfloat gamma_value = 1.0f; static void usage(void) @@ -51,6 +52,12 @@ static void set_gamma(float value) glfwSetGamma(gamma_value); } +static int window_close_callback(GLFWwindow window) +{ + closed = GL_TRUE; + return GL_FALSE; +} + static void key_callback(GLFWwindow window, int key, int action) { if (action != GLFW_PRESS) @@ -60,7 +67,7 @@ static void key_callback(GLFWwindow window, int key, int action) { case GLFW_KEY_ESCAPE: { - glfwDestroyWindow(window); + closed = GL_TRUE; break; } @@ -145,6 +152,7 @@ int main(int argc, char** argv) glfwSwapInterval(1); glfwSetKeyCallback(key_callback); + glfwSetWindowCloseCallback(window_close_callback); glfwSetWindowSizeCallback(size_callback); glMatrixMode(GL_PROJECTION); @@ -153,7 +161,7 @@ int main(int argc, char** argv) glClearColor(0.5f, 0.5f, 0.5f, 0); - while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED)) + while (!closed) { glClear(GL_COLOR_BUFFER_BIT); diff --git a/tests/iconify.c b/tests/iconify.c index 33b6f058..77815358 100644 --- a/tests/iconify.c +++ b/tests/iconify.c @@ -35,11 +35,19 @@ #include "getopt.h" +static GLboolean closed = GL_FALSE; + static void usage(void) { printf("Usage: iconify [-h] [-f]\n"); } +static int window_close_callback(GLFWwindow window) +{ + closed = GL_TRUE; + return GL_FALSE; +} + static void key_callback(GLFWwindow window, int key, int action) { printf("%0.2f Key %s\n", @@ -55,12 +63,12 @@ static void key_callback(GLFWwindow window, int key, int action) glfwIconifyWindow(window); break; case GLFW_KEY_ESCAPE: - glfwDestroyWindow(window); + closed = GL_TRUE; break; } } -static void size_callback(GLFWwindow window, int width, int height) +static void window_size_callback(GLFWwindow window, int width, int height) { printf("%0.2f Size %ix%i\n", glfwGetTime(), width, height); @@ -124,11 +132,12 @@ int main(int argc, char** argv) glfwSwapInterval(1); glfwSetKeyCallback(key_callback); - glfwSetWindowSizeCallback(size_callback); + glfwSetWindowSizeCallback(window_size_callback); + glfwSetWindowCloseCallback(window_close_callback); glEnable(GL_SCISSOR_TEST); - while (!glfwGetWindowParam(window, GLFW_CLOSE_REQUESTED)) + while (!closed) { if (iconified != glfwGetWindowParam(window, GLFW_ICONIFIED) || active != glfwGetWindowParam(window, GLFW_ACTIVE)) diff --git a/tests/modes.c b/tests/modes.c index 5ce65abb..ef1db71c 100644 --- a/tests/modes.c +++ b/tests/modes.c @@ -35,7 +35,7 @@ #include "getopt.h" -static GLFWwindow window = NULL; +static GLFWwindow window_handle = NULL; enum Mode { @@ -68,25 +68,25 @@ static void error_callback(int error, const char* description) fprintf(stderr, "Error: %s\n", description); } -static void window_size_callback(GLFWwindow in_window, int width, int height) +static void window_size_callback(GLFWwindow window, int width, int height) { printf("Window resized to %ix%i\n", width, height); glViewport(0, 0, width, height); } -static int window_close_callback(GLFWwindow dummy) +static int window_close_callback(GLFWwindow window) { - window = NULL; + window_handle = NULL; return GL_TRUE; } -static void key_callback(GLFWwindow dummy, int key, int action) +static void key_callback(GLFWwindow window, int key, int action) { if (key == GLFW_KEY_ESCAPE) { glfwDestroyWindow(window); - window = NULL; + window_handle = NULL; } } @@ -132,10 +132,10 @@ static void test_modes(void) printf("Testing mode %u: %s", (unsigned int) i, format_mode(mode)); - window = glfwCreateWindow(mode->width, mode->height, - GLFW_FULLSCREEN, "Video Mode Test", - NULL); - if (!window) + window_handle = glfwCreateWindow(mode->width, mode->height, + GLFW_FULLSCREEN, "Video Mode Test", + NULL); + if (!window_handle) { printf("Failed to enter mode %u: %s\n", (unsigned int) i, @@ -143,7 +143,7 @@ static void test_modes(void) continue; } - glfwMakeContextCurrent(window); + glfwMakeContextCurrent(window_handle); glfwSwapInterval(1); glfwSetTime(0.0); @@ -151,10 +151,10 @@ static void test_modes(void) while (glfwGetTime() < 5.0) { glClear(GL_COLOR_BUFFER_BIT); - glfwSwapBuffers(window); + glfwSwapBuffers(window_handle); glfwPollEvents(); - if (!window) + if (!window_handle) { printf("User terminated program\n"); exit(EXIT_SUCCESS); @@ -165,7 +165,7 @@ static void test_modes(void) glGetIntegerv(GL_GREEN_BITS, ¤t.greenBits); glGetIntegerv(GL_BLUE_BITS, ¤t.blueBits); - glfwGetWindowSize(window, ¤t.width, ¤t.height); + glfwGetWindowSize(window_handle, ¤t.width, ¤t.height); if (current.redBits != mode->redBits || current.greenBits != mode->greenBits || @@ -185,9 +185,9 @@ static void test_modes(void) printf("Closing window\n"); - glfwDestroyWindow(window); + glfwDestroyWindow(window_handle); + window_handle = NULL; glfwPollEvents(); - window = NULL; } } diff --git a/tests/peter.c b/tests/peter.c index ae6e4b7d..59c917e9 100644 --- a/tests/peter.c +++ b/tests/peter.c @@ -35,6 +35,7 @@ #include #include +static GLboolean reopen = GL_FALSE; static GLFWwindow window_handle = NULL; static int cursor_x; static int cursor_y; @@ -77,10 +78,7 @@ static void key_callback(GLFWwindow window, int key, int action) case GLFW_KEY_R: { if (action == GLFW_PRESS) - { - glfwDestroyWindow(window); - open_window(); - } + reopen = GL_TRUE; break; } @@ -121,8 +119,6 @@ int main(void) if (!open_window()) { - glfwTerminate(); - fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); } @@ -135,6 +131,18 @@ int main(void) glfwSwapBuffers(window_handle); glfwWaitEvents(); + + if (reopen) + { + glfwDestroyWindow(window_handle); + if (!open_window()) + { + fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError())); + exit(EXIT_FAILURE); + } + + reopen = GL_FALSE; + } } glfwTerminate(); diff --git a/tests/sharing.c b/tests/sharing.c index 95f21342..64e61740 100644 --- a/tests/sharing.c +++ b/tests/sharing.c @@ -37,27 +37,18 @@ #define HEIGHT 400 static GLFWwindow windows[2]; +static GLboolean closed = GL_FALSE; static void key_callback(GLFWwindow window, int key, int action) { if (action == GLFW_PRESS && key == GLFW_KEY_ESCAPE) - glfwDestroyWindow(window); + closed = GL_TRUE; } static int window_close_callback(GLFWwindow window) { - int i; - - for (i = 0; i < 2; i++) - { - if (windows[i] == window) - { - windows[i] = NULL; - break; - } - } - - return GL_TRUE; + closed = GL_TRUE; + return GL_FALSE; } static GLFWwindow open_window(const char* title, GLFWwindow share) @@ -170,7 +161,7 @@ int main(int argc, char** argv) glfwGetWindowPos(windows[0], &x, &y); glfwSetWindowPos(windows[1], x + WIDTH + 50, y); - while (windows[0] && windows[1]) + while (!closed) { glfwMakeContextCurrent(windows[0]); draw_quad(texture); From dbd4d1657ea38ecbb18c66175fd58d365714f6de Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 13 Sep 2012 21:57:42 +0200 Subject: [PATCH 24/27] Formatting. --- src/win32_window.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/win32_window.c b/src/win32_window.c index 735f9b97..84829d61 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1130,6 +1130,7 @@ void _glfwPlatformHideWindow(_GLFWwindow* window) ShowWindow(window->Win32.handle, SW_HIDE); } + //======================================================================== // Write back window parameters into GLFW window structure //======================================================================== From d6d5fb26845ebab3383afde878b721839cd8798d Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 19 Sep 2012 13:17:53 +0200 Subject: [PATCH 25/27] Simplified character input. --- src/win32_window.c | 71 ++++++++++++---------------------------------- 1 file changed, 18 insertions(+), 53 deletions(-) diff --git a/src/win32_window.c b/src/win32_window.c index 84829d61..636fab07 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -305,37 +305,6 @@ static int translateKey(WPARAM wParam, LPARAM lParam) } -//======================================================================== -// Translates a Windows key to Unicode -//======================================================================== - -static void translateChar(_GLFWwindow* window, DWORD wParam, DWORD lParam) -{ - BYTE keyboard_state[256]; - WCHAR unicode_buf[10]; - UINT scan_code; - int i, num_chars; - - GetKeyboardState(keyboard_state); - - // Derive scan code from lParam and action - scan_code = (lParam & 0x01ff0000) >> 16; - - num_chars = ToUnicode( - wParam, // virtual-key code - scan_code, // scan code - keyboard_state, // key-state array - unicode_buf, // buffer for translated key - 10, // size of translated key buffer - 0 // active-menu flag - ); - - // Report characters - for (i = 0; i < num_chars; i++) - _glfwInputChar(window, (int) unicode_buf[i]); -} - - //======================================================================== // Window callback function (handles window events) //======================================================================== @@ -459,13 +428,15 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, case WM_SYSKEYDOWN: { _glfwInputKey(window, translateKey(wParam, lParam), GLFW_PRESS); - - if (_glfwLibrary.charCallback) - translateChar(window, (DWORD) wParam, (DWORD) lParam); - break; } + case WM_CHAR: + { + _glfwInputChar(window, wParam); + return 0; + } + case WM_KEYUP: case WM_SYSKEYUP: { @@ -1177,28 +1148,22 @@ void _glfwPlatformPollEvents(void) while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { - switch (msg.message) + if (msg.message == WM_QUIT) { - case WM_QUIT: + // Treat WM_QUIT as a close on all windows + + window = _glfwLibrary.windowListHead; + while (window) { - // Treat WM_QUIT as a close on all windows - - window = _glfwLibrary.windowListHead; - while (window) - { - _glfwInputWindowCloseRequest(window); - window = window->next; - } - - break; - } - - default: - { - DispatchMessage(&msg); - break; + _glfwInputWindowCloseRequest(window); + window = window->next; } } + else + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } } // LSHIFT/RSHIFT fixup (keys tend to "stick" without this fix) From 718af531a332ca876b9438ece39ccab1cdbf11f2 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 23 Sep 2012 14:08:36 +0200 Subject: [PATCH 26/27] Fixed order of operations. --- src/window.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/window.c b/src/window.c index 817691de..383662af 100644 --- a/src/window.c +++ b/src/window.c @@ -336,8 +336,9 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height, // Cache the actual (as opposed to requested) window parameters _glfwPlatformRefreshWindowParams(window); - // Cache the actual (as opposed to requested) context parameters glfwMakeContextCurrent(window); + + // Cache the actual (as opposed to requested) context parameters if (!_glfwRefreshContextParams()) { glfwDestroyWindow(window); @@ -353,6 +354,11 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height, return GL_FALSE; } + // Clearing the front buffer to black to avoid garbage pixels left over + // from previous uses of our bit of VRAM + glClear(GL_COLOR_BUFFER_BIT); + _glfwPlatformSwapBuffers(window); + // Restore the previously current context (or NULL) glfwMakeContextCurrent(previous); @@ -361,12 +367,7 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height, if (mode == GLFW_FULLSCREEN) glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_CAPTURED); - // Clearing the front buffer to black to avoid garbage pixels left over - // from previous uses of our bit of VRAM - glClear(GL_COLOR_BUFFER_BIT); - _glfwPlatformSwapBuffers(window); - - if (wndconfig.visible || mode == GLFW_FULLSCREEN) + if (mode == GLFW_FULLSCREEN || wndconfig.visible) glfwShowWindow(window); return window; From c0dcb5a056eb0433cc6dc4a9d22c0d00eb4b1bd0 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 23 Sep 2012 15:08:43 +0200 Subject: [PATCH 27/27] Fixed fullscreen regressions. --- src/cocoa_window.m | 1 + src/win32_window.c | 1 + src/window.c | 2 +- src/x11_window.c | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 477a1fad..efdc0c6b 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -931,6 +931,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, return GL_FALSE; } + _glfwPlatformShowWindow(window); [[window->NS.object contentView] enterFullScreenMode:[NSScreen mainScreen] withOptions:nil]; } diff --git a/src/win32_window.c b/src/win32_window.c index 636fab07..6b275476 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -956,6 +956,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, if (window->mode == GLFW_FULLSCREEN) { // Place the window above all topmost windows + _glfwPlatformShowWindow(window); SetWindowPos(window->Win32.handle, HWND_TOPMOST, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE); } diff --git a/src/window.c b/src/window.c index 383662af..e9da2367 100644 --- a/src/window.c +++ b/src/window.c @@ -367,7 +367,7 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height, if (mode == GLFW_FULLSCREEN) glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_CAPTURED); - if (mode == GLFW_FULLSCREEN || wndconfig.visible) + if (mode == GLFW_WINDOWED && wndconfig.visible) glfwShowWindow(window); return window; diff --git a/src/x11_window.c b/src/x11_window.c index 8a0449a6..9cadaeac 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -852,6 +852,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, } #endif /*_GLFW_HAS_XRANDR*/ + _glfwPlatformShowWindow(window); enterFullscreenMode(window); }