From 31c91545be9c65c7ad3701c71286102e07186bb8 Mon Sep 17 00:00:00 2001 From: Ralph Eastwood Date: Wed, 21 Sep 2011 10:09:47 +0100 Subject: [PATCH 001/226] Added clipboard stubs. --- include/GL/glfw3.h | 8 +++++ src/CMakeLists.txt | 11 ++++--- src/clipboard.c | 68 +++++++++++++++++++++++++++++++++++++++++++ src/cocoa_clipboard.m | 56 +++++++++++++++++++++++++++++++++++ src/internal.h | 4 +++ src/win32_clipboard.c | 56 +++++++++++++++++++++++++++++++++++ src/x11_clipboard.c | 56 +++++++++++++++++++++++++++++++++++ 7 files changed, 255 insertions(+), 4 deletions(-) create mode 100644 src/clipboard.c create mode 100644 src/cocoa_clipboard.m create mode 100644 src/win32_clipboard.c create mode 100644 src/x11_clipboard.c diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 1f52e742..e3687b5c 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -469,6 +469,10 @@ extern "C" { /* Gamma ramps */ #define GLFW_GAMMA_RAMP_SIZE 256 +/* Clipboard formats */ +#define GLFW_CLIPBOARD_FORMAT_NONE 0 +#define GLFW_CLIPBOARD_FORMAT_STRING 1 + /************************************************************************* * Typedefs *************************************************************************/ @@ -591,6 +595,10 @@ GLFWAPI int glfwGetJoystickParam(int joy, int param); GLFWAPI int glfwGetJoystickPos(int joy, float* pos, int numaxes); GLFWAPI int glfwGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons); +/* Clipboard */ +GLFWAPI void glfwSetClipboardData(void *data, size_t size, int format); +GLFWAPI size_t glfwGetClipboardData(void *data, size_t size, int format); + /* Time */ GLFWAPI double glfwGetTime(void); GLFWAPI void glfwSetTime(double time); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cd50b41d..08ce8365 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,23 +27,26 @@ include_directories(${GLFW_SOURCE_DIR}/src ${GLFW_BINARY_DIR}/src ${GLFW_INCLUDE_DIR}) -set(common_SOURCES enable.c error.c fullscreen.c gamma.c init.c input.c +set(common_SOURCES clipboard.c enable.c error.c fullscreen.c gamma.c init.c input.c joystick.c opengl.c time.c window.c) if(_GLFW_COCOA_NSGL) - set(libglfw_SOURCES ${common_SOURCES} cocoa_enable.m cocoa_fullscreen.m + set(libglfw_SOURCES ${common_SOURCES} cocoa_clipboard.c + cocoa_enable.m cocoa_fullscreen.m cocoa_gamma.m cocoa_init.m cocoa_joystick.m cocoa_opengl.m cocoa_time.m cocoa_window.m) # For some reason, CMake doesn't know about .m set_source_files_properties(${libglfw_SOURCES} PROPERTIES LANGUAGE C) elseif(_GLFW_WIN32_WGL) - set(libglfw_SOURCES ${common_SOURCES} win32_enable.c win32_fullscreen.c + set(libglfw_SOURCES ${common_SOURCES} win32_clipboard.c + win32_enable.c win32_fullscreen.c win32_gamma.c win32_init.c win32_joystick.c win32_opengl.c win32_time.c win32_window.c win32_dllmain.c) elseif(_GLFW_X11_GLX) - set(libglfw_SOURCES ${common_SOURCES} x11_enable.c x11_fullscreen.c + set(libglfw_SOURCES ${common_SOURCES} x11_clipboard.c + x11_enable.c x11_fullscreen.c x11_gamma.c x11_init.c x11_joystick.c x11_keysym2unicode.c x11_opengl.c x11_time.c x11_window.c) diff --git a/src/clipboard.c b/src/clipboard.c new file mode 100644 index 00000000..5e38904f --- /dev/null +++ b/src/clipboard.c @@ -0,0 +1,68 @@ +//======================================================================== +// GLFW - An OpenGL library +// Platform: Any +// API version: 3.0 +// WWW: http://www.glfw.org/ +//------------------------------------------------------------------------ +// Copyright (c) 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" + +#include +#include + + +////////////////////////////////////////////////////////////////////////// +////// GLFW public API ////// +////////////////////////////////////////////////////////////////////////// + +//======================================================================== +// Set the clipboard contents +//======================================================================== + +GLFWAPI void glfwSetClipboardData(void *data, size_t size, int format) +{ + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED, NULL); + return; + } + _glfwPlatformSetClipboardData(data, size, format); +} + + +//======================================================================== +// Return the current clipboard contents +//======================================================================== + +GLFWAPI size_t glfwGetClipboardData(void *data, size_t size, int format) +{ + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED, NULL); + return 0; + } + + return _glfwPlatformGetClipboardData(data, size, format); +} diff --git a/src/cocoa_clipboard.m b/src/cocoa_clipboard.m new file mode 100644 index 00000000..0f78cf21 --- /dev/null +++ b/src/cocoa_clipboard.m @@ -0,0 +1,56 @@ +//======================================================================== +// GLFW - An OpenGL library +// Platform: Cocoa/NSOpenGL +// API version: 3.0 +// WWW: http://www.glfw.org/ +//------------------------------------------------------------------------ +// Copyright (c) 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" + +#include +#include + + +////////////////////////////////////////////////////////////////////////// +////// GLFW platform API ////// +////////////////////////////////////////////////////////////////////////// + +//======================================================================== +// Set the clipboard contents +//======================================================================== + +void _glfwPlatformSetClipboardData(void *data, size_t size, int format) +{ +} + +//======================================================================== +// Return the current clipboard contents +//======================================================================== + +size_t _glfwPlatformGetClipboardData(void *data, size_t size, int format) +{ + return 0; +} + diff --git a/src/internal.h b/src/internal.h index 83559ecc..3b82d47e 100644 --- a/src/internal.h +++ b/src/internal.h @@ -284,6 +284,10 @@ void _glfwPlatformGetDesktopMode(GLFWvidmode* mode); void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp); void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp); +// Clipboard +void _glfwPlatformSetClipboardData(void *data, size_t size, int format); +size_t _glfwPlatformGetClipboardData(void *data, size_t size, int format); + // Joystick int _glfwPlatformGetJoystickParam(int joy, int param); int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes); diff --git a/src/win32_clipboard.c b/src/win32_clipboard.c new file mode 100644 index 00000000..b16c51c4 --- /dev/null +++ b/src/win32_clipboard.c @@ -0,0 +1,56 @@ +//======================================================================== +// GLFW - An OpenGL library +// Platform: Win32/WGL +// API version: 3.0 +// WWW: http://www.glfw.org/ +//------------------------------------------------------------------------ +// Copyright (c) 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" + +#include +#include + + +////////////////////////////////////////////////////////////////////////// +////// GLFW platform API ////// +////////////////////////////////////////////////////////////////////////// + +//======================================================================== +// Set the clipboard contents +//======================================================================== + +void _glfwPlatformSetClipboardData(void *data, size_t size, int format) +{ +} + +//======================================================================== +// Return the current clipboard contents +//======================================================================== + +size_t _glfwPlatformGetClipboardData(void *data, size_t size, int format) +{ + return 0; +} + diff --git a/src/x11_clipboard.c b/src/x11_clipboard.c new file mode 100644 index 00000000..164bad49 --- /dev/null +++ b/src/x11_clipboard.c @@ -0,0 +1,56 @@ +//======================================================================== +// GLFW - An OpenGL library +// Platform: X11/GLX +// API version: 3.0 +// WWW: http://www.glfw.org/ +//------------------------------------------------------------------------ +// Copyright (c) 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" + +#include +#include + + +////////////////////////////////////////////////////////////////////////// +////// GLFW platform API ////// +////////////////////////////////////////////////////////////////////////// + +//======================================================================== +// Set the clipboard contents +//======================================================================== + +void _glfwPlatformSetClipboardData(void *data, size_t size, int format) +{ +} + +//======================================================================== +// Return the current clipboard contents +//======================================================================== + +size_t _glfwPlatformGetClipboardData(void *data, size_t size, int format) +{ + return 0; +} + From 57522db6e2919406efd0d44a170962ed8f480f2f Mon Sep 17 00:00:00 2001 From: Ralph Eastwood Date: Wed, 21 Sep 2011 15:43:28 +0100 Subject: [PATCH 002/226] X11 implementation of clipboard pasting. --- include/GL/glfw3.h | 1 + src/clipboard.c | 9 +++- src/x11_clipboard.c | 107 ++++++++++++++++++++++++++++++++++++++++++- src/x11_init.c | 8 ++++ src/x11_platform.h | 9 ++++ src/x11_window.c | 13 ++++++ tests/CMakeLists.txt | 5 +- 7 files changed, 147 insertions(+), 5 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index e3687b5c..21ed049a 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -465,6 +465,7 @@ extern "C" { #define GLFW_VERSION_UNAVAILABLE 0x00070007 #define GLFW_PLATFORM_ERROR 0x00070008 #define GLFW_WINDOW_NOT_ACTIVE 0x00070009 +#define GLFW_CLIPBOARD_FORMAT_UNAVAILABLE 0x00070010 /* Gamma ramps */ #define GLFW_GAMMA_RAMP_SIZE 256 diff --git a/src/clipboard.c b/src/clipboard.c index 5e38904f..79cf680c 100644 --- a/src/clipboard.c +++ b/src/clipboard.c @@ -48,6 +48,10 @@ GLFWAPI void glfwSetClipboardData(void *data, size_t size, int format) _glfwSetError(GLFW_NOT_INITIALIZED, NULL); return; } + + if (format == GLFW_CLIPBOARD_FORMAT_NONE) + return; + _glfwPlatformSetClipboardData(data, size, format); } @@ -61,8 +65,11 @@ GLFWAPI size_t glfwGetClipboardData(void *data, size_t size, int format) if (!_glfwInitialized) { _glfwSetError(GLFW_NOT_INITIALIZED, NULL); - return 0; + return 0; } + if (format == GLFW_CLIPBOARD_FORMAT_NONE) + return 0; + return _glfwPlatformGetClipboardData(data, size, format); } diff --git a/src/x11_clipboard.c b/src/x11_clipboard.c index 164bad49..467a0d52 100644 --- a/src/x11_clipboard.c +++ b/src/x11_clipboard.c @@ -29,28 +29,131 @@ #include "internal.h" +#include #include #include - +#include ////////////////////////////////////////////////////////////////////////// ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// +//======================================================================== +// Get the corresponding X11 format for a given GLFW format. +//======================================================================== + +static Atom *getInternalFormat(int fmt) +{ + // Get the necessary atoms + + switch (fmt) + { + case GLFW_CLIPBOARD_FORMAT_STRING: + return _glfwLibrary.X11.selection.stringatoms; + default: + return 0; + } +} + //======================================================================== // Set the clipboard contents //======================================================================== void _glfwPlatformSetClipboardData(void *data, size_t size, int format) { + } //======================================================================== // Return the current clipboard contents +// TODO: Incremental support? Overkill perhaps. //======================================================================== size_t _glfwPlatformGetClipboardData(void *data, size_t size, int format) { - return 0; + size_t len, rembytes, dummy; + unsigned char *d; + int fmt; + Window window; + Atom *xfmt, type; + + // Try different formats that relate to the GLFW format with preference + // for better formats first + for (xfmt = getInternalFormat(format); *xfmt; xfmt++) + { + // Specify the format we would like. + _glfwLibrary.X11.selection.request = *xfmt; + + // Convert the selection into a format we would like. + window = _glfwLibrary.activeWindow->X11.handle; + XConvertSelection(_glfwLibrary.X11.display, XA_PRIMARY, + *xfmt, None, window, + CurrentTime); + XFlush(_glfwLibrary.X11.display); + + // Process pending events until we get a SelectionNotify. + while (!_glfwLibrary.X11.selection.converted) + _glfwPlatformWaitEvents(); + + // If there is no owner to the selection/wrong request, bail out. + if (_glfwLibrary.X11.selection.converted == 2) + { + _glfwLibrary.X11.selection.converted = 0; + _glfwSetError(GLFW_CLIPBOARD_FORMAT_UNAVAILABLE, + "X11/GLX: Unavailable clipboard format"); + return 0; + } + else // Right format, stop checking + { + _glfwLibrary.X11.selection.converted = 0; + break; + } + } + + // Reset for the next selection + _glfwLibrary.X11.selection.converted = 0; + + // Check the length of data to receive + XGetWindowProperty(_glfwLibrary.X11.display, + window, + *xfmt, + 0, 0, + 0, + AnyPropertyType, + &type, + &fmt, + &len, &rembytes, + &d); + + // The number of bytes remaining (which is all of them) + if (rembytes > 0) + { + int result = XGetWindowProperty(_glfwLibrary.X11.display, window, + *xfmt, 0, rembytes, 0, + AnyPropertyType, &type, &fmt, + &len, &dummy, &d); + if (result == Success) + { + size_t s = size - 1 > rembytes ? rembytes : size - 1; + // Copy the data out. + memcpy(data, d, s); + // Null-terminate strings. + if (format == GLFW_CLIPBOARD_FORMAT_STRING) + { + ((char *)data)[s] = '\0'; + } + // Free the data allocated using X11. + XFree(d); + // Return the actual number of bytes. + return rembytes; + } + else + { + // Free the data allocated using X11. + XFree(d); + return 0; + } + } + return 0; } diff --git a/src/x11_init.c b/src/x11_init.c index 9af7783e..a824528b 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -446,6 +446,14 @@ static GLboolean initDisplay(void) // the keyboard mapping. updateKeyCodeLUT(); + // Find or create selection atoms + _glfwLibrary.X11.selection.stringatoms[0] = + XInternAtom(_glfwLibrary.X11.display, "UTF8_STRING", False); + _glfwLibrary.X11.selection.stringatoms[1] = + XInternAtom(_glfwLibrary.X11.display, "COMPOUND_STRING", False); + _glfwLibrary.X11.selection.stringatoms[2] = XA_STRING; + _glfwLibrary.X11.selection.stringatoms[3] = 0; + return GL_TRUE; } diff --git a/src/x11_platform.h b/src/x11_platform.h index b3cf642e..90b6e75c 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -89,6 +89,8 @@ #define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryX11 X11 #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX GLX +// Number of string atoms that will be checked +#define _GLFW_STRING_ATOMS_COUNT 4 //======================================================================== // GLFW platform specific types @@ -225,6 +227,13 @@ typedef struct _GLFWlibraryX11 uint64_t t0; } timer; + // Selection data + struct { + Atom stringatoms[_GLFW_STRING_ATOMS_COUNT]; + Atom request; + int converted; + } selection; + #if defined(_GLFW_DLOPEN_LIBGL) void* libGL; // dlopen handle for libGL.so #endif diff --git a/src/x11_window.c b/src/x11_window.c index a05b121c..ff54a11b 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -1381,6 +1381,19 @@ static void processSingleEvent(void) break; } + case SelectionNotify: + { + // Selection notification triggered by the XConvertSelection + + // Check if the notification property matches the request + if (event.xselection.property != _glfwLibrary.X11.selection.request) + _glfwLibrary.X11.selection.converted = 2; + else // It was successful + _glfwLibrary.X11.selection.converted = 1; + + break; + } + // Was the window destroyed? case DestroyNotify: return; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9ef07acc..23a1ebd0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,6 +5,7 @@ include_directories(${GLFW_SOURCE_DIR}/include ${GLFW_SOURCE_DIR}/support ${OPENGL_INCLUDE_DIR}) +add_executable(clipboard clipboard.c) add_executable(defaults defaults.c) add_executable(events events.c) add_executable(fsaa fsaa.c getopt.c) @@ -32,8 +33,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 clipboard defaults events fsaa fsfocus gamma iconify + joysticks listmodes peter reopen version) if(MSVC) # Tell MSVC to use main instead of WinMain for Windows subsystem executables From 9f41e5b67a89dbd93f96e39d2d1d7d6c79a872c2 Mon Sep 17 00:00:00 2001 From: Ralph Eastwood Date: Thu, 22 Sep 2011 12:03:45 +0100 Subject: [PATCH 003/226] X11 copying code and support PRIMARY & CLIPBOARD clipboards. --- include/GL/glfw3.h | 1 + src/clipboard.c | 3 + src/x11_clipboard.c | 149 +++++++++++++++++++++++++++++++++++--------- src/x11_init.c | 19 ++++-- src/x11_platform.h | 26 ++++++-- src/x11_window.c | 21 ++++++- 6 files changed, 179 insertions(+), 40 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 21ed049a..7f054e5f 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -466,6 +466,7 @@ extern "C" { #define GLFW_PLATFORM_ERROR 0x00070008 #define GLFW_WINDOW_NOT_ACTIVE 0x00070009 #define GLFW_CLIPBOARD_FORMAT_UNAVAILABLE 0x00070010 +#define GLFW_CLIPBOARD_CANNOT_OWN 0x00070011 /* Gamma ramps */ #define GLFW_GAMMA_RAMP_SIZE 256 diff --git a/src/clipboard.c b/src/clipboard.c index 79cf680c..b055c168 100644 --- a/src/clipboard.c +++ b/src/clipboard.c @@ -71,5 +71,8 @@ GLFWAPI size_t glfwGetClipboardData(void *data, size_t size, int format) if (format == GLFW_CLIPBOARD_FORMAT_NONE) return 0; + if (!data || !size) + return 0; + return _glfwPlatformGetClipboardData(data, size, format); } diff --git a/src/x11_clipboard.c b/src/x11_clipboard.c index 467a0d52..1be0ac23 100644 --- a/src/x11_clipboard.c +++ b/src/x11_clipboard.c @@ -27,6 +27,8 @@ // //======================================================================== +// TODO: Incremental support? Overkill perhaps. + #include "internal.h" #include @@ -45,28 +47,101 @@ static Atom *getInternalFormat(int fmt) { // Get the necessary atoms - switch (fmt) { case GLFW_CLIPBOARD_FORMAT_STRING: - return _glfwLibrary.X11.selection.stringatoms; + return _glfwLibrary.X11.selection.atoms.string; default: return 0; } } +//======================================================================== +// X11 selection request event +//======================================================================== + +Atom _glfwSelectionRequest(XSelectionRequestEvent *request) +{ + Atom *atoms = _glfwLibrary.X11.selection.atoms.string; + if (request->target == XA_STRING) + { + // TODO: ISO Latin-1 specific characters don't get converted + // (yet). For cleanliness, would we need something like iconv? + XChangeProperty(_glfwLibrary.X11.display, + request->requestor, + request->target, + request->target, + 8, + PropModeReplace, + (unsigned char *)_glfwLibrary.X11.selection.clipboard.string, + 8); + } + else if (request->target == atoms[_GLFW_STRING_ATOM_COMPOUND] || + request->target == atoms[_GLFW_STRING_ATOM_UTF8]) + { + XChangeProperty(_glfwLibrary.X11.display, + request->requestor, + request->target, + request->target, + 8, + PropModeReplace, + (unsigned char *)_glfwLibrary.X11.selection.clipboard.string, + _glfwLibrary.X11.selection.clipboard.stringlen); + } + else + { + // TODO: Should we set an error? Probably not. + return None; + } + return request->target; +} + //======================================================================== // Set the clipboard contents //======================================================================== void _glfwPlatformSetClipboardData(void *data, size_t size, int format) { + switch (format) + { + case GLFW_CLIPBOARD_FORMAT_STRING: + { + // Allocate memory to keep track of the clipboard + char *cb = malloc(size+1); + // Copy the clipboard data + memcpy(cb, data, size); + + // Set the string length + _glfwLibrary.X11.selection.clipboard.stringlen = size; + + // Check if existing clipboard memory needs to be freed + if (_glfwLibrary.X11.selection.clipboard.string) + free(_glfwLibrary.X11.selection.clipboard.string); + + // Now set the clipboard (awaiting the event SelectionRequest) + _glfwLibrary.X11.selection.clipboard.string = cb; + break; + } + + default: + _glfwSetError(GLFW_CLIPBOARD_FORMAT_UNAVAILABLE, + "X11/GLX: Unavailable clipboard format"); + return; + } + + // Set the selection owner to our active window + XSetSelectionOwner(_glfwLibrary.X11.display, XA_PRIMARY, + _glfwLibrary.activeWindow->X11.handle, CurrentTime); + XSetSelectionOwner(_glfwLibrary.X11.display, + _glfwLibrary.X11.selection.atoms.clipboard + [_GLFW_CLIPBOARD_ATOM_CLIPBOARD], + _glfwLibrary.activeWindow->X11.handle, CurrentTime); + XFlush(_glfwLibrary.X11.display); } //======================================================================== // Return the current clipboard contents -// TODO: Incremental support? Overkill perhaps. //======================================================================== size_t _glfwPlatformGetClipboardData(void *data, size_t size, int format) @@ -74,46 +149,60 @@ size_t _glfwPlatformGetClipboardData(void *data, size_t size, int format) size_t len, rembytes, dummy; unsigned char *d; int fmt; - Window window; - Atom *xfmt, type; + Atom type; - // Try different formats that relate to the GLFW format with preference - // for better formats first - for (xfmt = getInternalFormat(format); *xfmt; xfmt++) + // Try different clipboards and formats that relate to the GLFW + // format with preference for more appropriate formats first + Atom *xcbrd = _glfwLibrary.X11.selection.atoms.clipboard; + Atom *xcbrdend = _glfwLibrary.X11.selection.atoms.clipboard + + _GLFW_CLIPBOARD_ATOM_COUNT; + Atom *xfmt = getInternalFormat(format); + Atom *xfmtend = xfmt + _GLFW_STRING_ATOM_COUNT; + + // Get the currently active window + Window window = _glfwLibrary.activeWindow->X11.handle; + + for (; xcbrd != xcbrdend; xcbrd++) { - // Specify the format we would like. - _glfwLibrary.X11.selection.request = *xfmt; - - // Convert the selection into a format we would like. - window = _glfwLibrary.activeWindow->X11.handle; - XConvertSelection(_glfwLibrary.X11.display, XA_PRIMARY, - *xfmt, None, window, - CurrentTime); - XFlush(_glfwLibrary.X11.display); - - // Process pending events until we get a SelectionNotify. - while (!_glfwLibrary.X11.selection.converted) - _glfwPlatformWaitEvents(); - - // If there is no owner to the selection/wrong request, bail out. - if (_glfwLibrary.X11.selection.converted == 2) + for (; xfmt != xfmtend; xfmt++) { - _glfwLibrary.X11.selection.converted = 0; - _glfwSetError(GLFW_CLIPBOARD_FORMAT_UNAVAILABLE, - "X11/GLX: Unavailable clipboard format"); - return 0; + // Specify the format we would like. + _glfwLibrary.X11.selection.request = *xfmt; + + // Convert the selection into a format we would like. + XConvertSelection(_glfwLibrary.X11.display, *xcbrd, + *xfmt, None, window, CurrentTime); + XFlush(_glfwLibrary.X11.display); + + // Process pending events until we get a SelectionNotify. + while (!_glfwLibrary.X11.selection.converted) + _glfwPlatformWaitEvents(); + + // Successful? + if (_glfwLibrary.X11.selection.converted == 1) + break; } - else // Right format, stop checking + + // Successful? + if (_glfwLibrary.X11.selection.converted == 1) { _glfwLibrary.X11.selection.converted = 0; break; } } + // Unsuccessful conversion, bail with no clipboard data + if (_glfwLibrary.X11.selection.converted) + { + _glfwSetError(GLFW_CLIPBOARD_FORMAT_UNAVAILABLE, + "X11/GLX: Unavailable clipboard format"); + return 0; + } + // Reset for the next selection _glfwLibrary.X11.selection.converted = 0; - // Check the length of data to receive + // Check the length of data to receive (rembytes) XGetWindowProperty(_glfwLibrary.X11.display, window, *xfmt, diff --git a/src/x11_init.c b/src/x11_init.c index a824528b..1fa549bd 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -446,13 +446,20 @@ static GLboolean initDisplay(void) // the keyboard mapping. updateKeyCodeLUT(); + // Find or create clipboard atoms + _glfwLibrary.X11.selection.atoms.clipboard[_GLFW_CLIPBOARD_ATOM_PRIMARY] = + XA_PRIMARY; + _glfwLibrary.X11.selection.atoms.clipboard[_GLFW_CLIPBOARD_ATOM_CLIPBOARD] = + XInternAtom(_glfwLibrary.X11.display, "CLIPBOARD", False); + _glfwLibrary.X11.selection.atoms.clipboard[_GLFW_CLIPBOARD_ATOM_SECONDARY] = + XA_SECONDARY; + // Find or create selection atoms - _glfwLibrary.X11.selection.stringatoms[0] = + _glfwLibrary.X11.selection.atoms.string[_GLFW_STRING_ATOM_UTF8] = XInternAtom(_glfwLibrary.X11.display, "UTF8_STRING", False); - _glfwLibrary.X11.selection.stringatoms[1] = + _glfwLibrary.X11.selection.atoms.string[_GLFW_STRING_ATOM_COMPOUND] = XInternAtom(_glfwLibrary.X11.display, "COMPOUND_STRING", False); - _glfwLibrary.X11.selection.stringatoms[2] = XA_STRING; - _glfwLibrary.X11.selection.stringatoms[3] = 0; + _glfwLibrary.X11.selection.atoms.string[_GLFW_STRING_ATOM_STRING] = XA_STRING; return GL_TRUE; } @@ -616,6 +623,10 @@ int _glfwPlatformTerminate(void) } #endif + // Free clipboard memory + if (_glfwLibrary.X11.selection.clipboard.string) + free(_glfwLibrary.X11.selection.clipboard.string); + return GL_TRUE; } diff --git a/src/x11_platform.h b/src/x11_platform.h index 90b6e75c..6f1bf6a5 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -89,8 +89,17 @@ #define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryX11 X11 #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX GLX -// Number of string atoms that will be checked -#define _GLFW_STRING_ATOMS_COUNT 4 +// Clipboard atoms +#define _GLFW_CLIPBOARD_ATOM_PRIMARY 0 +#define _GLFW_CLIPBOARD_ATOM_CLIPBOARD 1 +#define _GLFW_CLIPBOARD_ATOM_SECONDARY 2 +#define _GLFW_CLIPBOARD_ATOM_COUNT 3 + +// String atoms +#define _GLFW_STRING_ATOM_UTF8 0 +#define _GLFW_STRING_ATOM_COMPOUND 1 +#define _GLFW_STRING_ATOM_STRING 2 +#define _GLFW_STRING_ATOM_COUNT 3 //======================================================================== // GLFW platform specific types @@ -229,8 +238,15 @@ typedef struct _GLFWlibraryX11 // Selection data struct { - Atom stringatoms[_GLFW_STRING_ATOMS_COUNT]; - Atom request; + struct { + Atom clipboard[_GLFW_CLIPBOARD_ATOM_COUNT]; + Atom string[_GLFW_STRING_ATOM_COUNT]; + } atoms; + struct { + size_t stringlen; + char *string; + } clipboard; + Atom request; int converted; } selection; @@ -273,5 +289,7 @@ void _glfwTerminateJoysticks(void); // Unicode support long _glfwKeySym2Unicode(KeySym keysym); +// Clipboard handling +Atom _glfwSelectionRequest(XSelectionRequestEvent *request); #endif // _platform_h_ diff --git a/src/x11_window.c b/src/x11_window.c index ff54a11b..cfb19980 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -41,8 +41,8 @@ #define _NET_WM_STATE_TOGGLE 2 // Additional mouse button names for XButtonEvent -#define Button6 6 -#define Button7 7 +#define Button6 6 +#define Button7 7 //======================================================================== // Error handler for BadMatch errors when requesting context with @@ -1394,6 +1394,23 @@ static void processSingleEvent(void) break; } + case SelectionRequest: + { + XSelectionRequestEvent *request = &event.xselectionrequest; + // Construct the response + XEvent response; + response.xselection.property = _glfwSelectionRequest(request); + response.xselection.type = SelectionNotify; + response.xselection.display = request->display; + response.xselection.requestor = request->requestor; + response.xselection.selection = request->selection; + response.xselection.target = request->target; + response.xselection.time = request->time; + // Send off the event + XSendEvent(_glfwLibrary.X11.display, request->requestor, 0, 0, &response); + break; + } + // Was the window destroyed? case DestroyNotify: return; From a2ffa80e82729afcca0b0929a03b21661c2d00d7 Mon Sep 17 00:00:00 2001 From: Ralph Eastwood Date: Thu, 22 Sep 2011 12:09:01 +0100 Subject: [PATCH 004/226] Some reformatting with new X11 SelectionRequest event. --- src/x11_window.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/x11_window.c b/src/x11_window.c index cfb19980..0fe4db83 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -1396,7 +1396,10 @@ static void processSingleEvent(void) case SelectionRequest: { + // Selection request triggered by someone wanting data from the + // X11 clipboard XSelectionRequestEvent *request = &event.xselectionrequest; + // Construct the response XEvent response; response.xselection.property = _glfwSelectionRequest(request); @@ -1406,8 +1409,10 @@ static void processSingleEvent(void) response.xselection.selection = request->selection; response.xselection.target = request->target; response.xselection.time = request->time; + // Send off the event XSendEvent(_glfwLibrary.X11.display, request->requestor, 0, 0, &response); + break; } From 0b752b84c308b6098e8360350a1b8c4d08f51395 Mon Sep 17 00:00:00 2001 From: Hanmac Date: Mon, 30 Jan 2012 22:18:05 +0100 Subject: [PATCH 005/226] Added API and X11 implementation of cursor enter and leave callbacks. --- include/GL/glfw3.h | 4 ++++ src/input.c | 32 ++++++++++++++++++++++++++++++++ src/internal.h | 4 ++++ src/window.c | 19 +++++++++++++++++++ src/x11_window.c | 34 +++++++++++++++++++++++++++++++++- 5 files changed, 92 insertions(+), 1 deletion(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index e49654d1..421adb4a 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -474,6 +474,8 @@ typedef void (* GLFWwindowfocusfun)(GLFWwindow,int); typedef void (* GLFWwindowiconifyfun)(GLFWwindow,int); typedef void (* GLFWmousebuttonfun)(GLFWwindow,int,int); typedef void (* GLFWmouseposfun)(GLFWwindow,int,int); +typedef void (* GLFWcursorenterfun)(GLFWwindow); +typedef void (* GLFWcursorleavefun)(GLFWwindow); typedef void (* GLFWscrollfun)(GLFWwindow,int,int); typedef void (* GLFWkeyfun)(GLFWwindow,int,int); typedef void (* GLFWcharfun)(GLFWwindow,int); @@ -574,6 +576,8 @@ GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun); GLFWAPI void glfwSetMouseButtonCallback(GLFWmousebuttonfun cbfun); GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun); GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun); +GLFWAPI void glfwSetCursorEnterCallback(GLFWcursorenterfun cbfun); +GLFWAPI void glfwSetCursorLeaveCallback(GLFWcursorleavefun cbfun); /* Joystick input */ GLFWAPI int glfwGetJoystickParam(int joy, int param); diff --git a/src/input.c b/src/input.c index 531bcc7e..2c480424 100644 --- a/src/input.c +++ b/src/input.c @@ -436,3 +436,35 @@ GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun) _glfwLibrary.scrollCallback = cbfun; } + +//======================================================================== +// Set callback function for cursor enter events +//======================================================================== + +GLFWAPI void glfwSetCursorEnterCallback(GLFWcursorenterfun cbfun) +{ + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED, NULL); + return; + } + + _glfwLibrary.cursorEnterCallback = cbfun; +} + + +//======================================================================== +// Set callback function for cursor enter events +//======================================================================== + +GLFWAPI void glfwSetCursorLeaveCallback(GLFWcursorleavefun cbfun) +{ + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED, NULL); + return; + } + + _glfwLibrary.cursorLeaveCallback = cbfun; +} + diff --git a/src/internal.h b/src/internal.h index 5992a0f4..a15dbfc6 100644 --- a/src/internal.h +++ b/src/internal.h @@ -240,6 +240,8 @@ struct _GLFWlibrary GLFWscrollfun scrollCallback; GLFWkeyfun keyCallback; GLFWcharfun charCallback; + GLFWcursorenterfun cursorEnterCallback; + GLFWcursorleavefun cursorLeaveCallback; GLFWthreadmodel threading; GLFWallocator allocator; @@ -352,6 +354,8 @@ void _glfwInputChar(_GLFWwindow* window, int character); void _glfwInputScroll(_GLFWwindow* window, int x, int y); void _glfwInputMouseClick(_GLFWwindow* window, int button, int action); void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y); +void _glfwInputCursorEnter(_GLFWwindow* window); +void _glfwInputCursorLeave(_GLFWwindow* window); // OpenGL context helpers (opengl.c) int _glfwStringInExtensionString(const char* string, const GLubyte* extensions); diff --git a/src/window.c b/src/window.c index 88b3dc18..567ec340 100644 --- a/src/window.c +++ b/src/window.c @@ -205,6 +205,25 @@ void _glfwInputWindowDamage(_GLFWwindow* window) _glfwLibrary.windowRefreshCallback(window); } +//======================================================================== +// Register cursor enter events +//======================================================================== + +void _glfwInputCursorEnter(_GLFWwindow* window) +{ + if (_glfwLibrary.cursorEnterCallback) + _glfwLibrary.cursorEnterCallback(window); +} + +//======================================================================== +// Register cursor leave events +//======================================================================== + +void _glfwInputCursorLeave(_GLFWwindow* window) +{ + if (_glfwLibrary.cursorLeaveCallback) + _glfwLibrary.cursorLeaveCallback(window); +} ////////////////////////////////////////////////////////////////////////// ////// GLFW public API ////// diff --git a/src/x11_window.c b/src/x11_window.c index 641b3c84..cbd844d3 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -679,7 +679,8 @@ static GLboolean createWindow(_GLFWwindow* window, wa.border_pixel = 0; wa.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask | - ExposureMask | FocusChangeMask | VisibilityChangeMask; + ExposureMask | FocusChangeMask | VisibilityChangeMask | + EnterWindowMask | LeaveWindowMask; if (wndconfig->mode == GLFW_WINDOWED) { @@ -1180,6 +1181,37 @@ static void processSingleEvent(void) break; } + case EnterNotify: + { + // The mouse cursor enters the Window + window = findWindow(event.xcrossing.window); + if (window == NULL) + { + fprintf(stderr, "Cannot find GLFW window structure for EnterNotify event\n"); + return; + } + if(window->cursorMode == GLFW_CURSOR_HIDDEN) + { + hideMouseCursor(window); + } + _glfwInputCursorEnter(window); + break; + } + + case LeaveNotify: + { + // The mouse cursor leave the Window + window = findWindow(event.xcrossing.window); + if (window == NULL) + { + fprintf(stderr, "Cannot find GLFW window structure for LeaveNotify event\n"); + return; + } + showMouseCursor(window); + _glfwInputCursorLeave(window); + break; + } + case MotionNotify: { // The mouse cursor was moved From 1ddafc25a68a52482a4f52d8e3dcb1bd3e9ff331 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 30 Jan 2012 22:30:40 +0100 Subject: [PATCH 006/226] Moved new cursor input code to other cursor input code. --- include/GL/glfw3.h | 2 +- src/input.c | 56 ++++++++++++++++++++++++++++++++-------------- src/internal.h | 4 ++-- src/window.c | 19 ---------------- 4 files changed, 42 insertions(+), 39 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 421adb4a..5bf080bd 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -575,9 +575,9 @@ GLFWAPI void glfwSetKeyCallback(GLFWkeyfun cbfun); GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun); GLFWAPI void glfwSetMouseButtonCallback(GLFWmousebuttonfun cbfun); GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun); -GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun); GLFWAPI void glfwSetCursorEnterCallback(GLFWcursorenterfun cbfun); GLFWAPI void glfwSetCursorLeaveCallback(GLFWcursorleavefun cbfun); +GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun); /* Joystick input */ GLFWAPI int glfwGetJoystickParam(int joy, int param); diff --git a/src/input.c b/src/input.c index 2c480424..903cb054 100644 --- a/src/input.c +++ b/src/input.c @@ -146,6 +146,28 @@ void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y) } +//======================================================================== +// Register cursor enter events +//======================================================================== + +void _glfwInputCursorEnter(_GLFWwindow* window) +{ + if (_glfwLibrary.cursorEnterCallback) + _glfwLibrary.cursorEnterCallback(window); +} + + +//======================================================================== +// Register cursor leave events +//======================================================================== + +void _glfwInputCursorLeave(_GLFWwindow* window) +{ + if (_glfwLibrary.cursorLeaveCallback) + _glfwLibrary.cursorLeaveCallback(window); +} + + ////////////////////////////////////////////////////////////////////////// ////// GLFW public API ////// ////////////////////////////////////////////////////////////////////////// @@ -420,23 +442,6 @@ GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun) } -//======================================================================== -// Set callback function for scroll events -//======================================================================== - -GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun) -{ - if (!_glfwInitialized) - { - _glfwSetError(GLFW_NOT_INITIALIZED, NULL); - return; - } - - // Set callback function - _glfwLibrary.scrollCallback = cbfun; -} - - //======================================================================== // Set callback function for cursor enter events //======================================================================== @@ -468,3 +473,20 @@ GLFWAPI void glfwSetCursorLeaveCallback(GLFWcursorleavefun cbfun) _glfwLibrary.cursorLeaveCallback = cbfun; } + +//======================================================================== +// Set callback function for scroll events +//======================================================================== + +GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun) +{ + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED, NULL); + return; + } + + // Set callback function + _glfwLibrary.scrollCallback = cbfun; +} + diff --git a/src/internal.h b/src/internal.h index a15dbfc6..db46f6c4 100644 --- a/src/internal.h +++ b/src/internal.h @@ -237,11 +237,11 @@ struct _GLFWlibrary GLFWwindowiconifyfun windowIconifyCallback; GLFWmousebuttonfun mouseButtonCallback; GLFWmouseposfun mousePosCallback; + GLFWcursorenterfun cursorEnterCallback; + GLFWcursorleavefun cursorLeaveCallback; GLFWscrollfun scrollCallback; GLFWkeyfun keyCallback; GLFWcharfun charCallback; - GLFWcursorenterfun cursorEnterCallback; - GLFWcursorleavefun cursorLeaveCallback; GLFWthreadmodel threading; GLFWallocator allocator; diff --git a/src/window.c b/src/window.c index 567ec340..88b3dc18 100644 --- a/src/window.c +++ b/src/window.c @@ -205,25 +205,6 @@ void _glfwInputWindowDamage(_GLFWwindow* window) _glfwLibrary.windowRefreshCallback(window); } -//======================================================================== -// Register cursor enter events -//======================================================================== - -void _glfwInputCursorEnter(_GLFWwindow* window) -{ - if (_glfwLibrary.cursorEnterCallback) - _glfwLibrary.cursorEnterCallback(window); -} - -//======================================================================== -// Register cursor leave events -//======================================================================== - -void _glfwInputCursorLeave(_GLFWwindow* window) -{ - if (_glfwLibrary.cursorLeaveCallback) - _glfwLibrary.cursorLeaveCallback(window); -} ////////////////////////////////////////////////////////////////////////// ////// GLFW public API ////// From 7e470518ba909381a9cce65011e1d308e998566a Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 30 Jan 2012 22:32:14 +0100 Subject: [PATCH 007/226] Formatting. --- src/x11_window.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/x11_window.c b/src/x11_window.c index cbd844d3..ccf049f9 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -1190,10 +1190,10 @@ static void processSingleEvent(void) fprintf(stderr, "Cannot find GLFW window structure for EnterNotify event\n"); return; } - if(window->cursorMode == GLFW_CURSOR_HIDDEN) - { + + if (window->cursorMode == GLFW_CURSOR_HIDDEN) hideMouseCursor(window); - } + _glfwInputCursorEnter(window); break; } @@ -1207,7 +1207,9 @@ static void processSingleEvent(void) fprintf(stderr, "Cannot find GLFW window structure for LeaveNotify event\n"); return; } + showMouseCursor(window); + _glfwInputCursorLeave(window); break; } From 1d2a9790c95243b58be03dacdd3e646d866e4ba0 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 30 Jan 2012 22:44:41 +0100 Subject: [PATCH 008/226] Only show cursor on leave in hidden mode. --- src/x11_window.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/x11_window.c b/src/x11_window.c index ccf049f9..ad34eb81 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -1208,7 +1208,8 @@ static void processSingleEvent(void) return; } - showMouseCursor(window); + if (window->cursorMode == GLFW_CURSOR_HIDDEN) + showMouseCursor(window); _glfwInputCursorLeave(window); break; From 3663d62362a0ba92775051e1be2159ce20044c5f Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 30 Jan 2012 22:44:51 +0100 Subject: [PATCH 009/226] Added cursor enter/leave support to events test. --- tests/events.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/events.c b/tests/events.c index ac758100..292da3ce 100644 --- a/tests/events.c +++ b/tests/events.c @@ -274,6 +274,16 @@ static void mouse_position_callback(GLFWwindow window, int x, int y) printf("%08x at %0.3f: Mouse position: %i %i\n", counter++, glfwGetTime(), x, y); } +static void cursor_enter_callback(GLFWwindow window) +{ + printf("%08x at %0.3f: Cursor entered window\n", counter++, glfwGetTime()); +} + +static void cursor_leave_callback(GLFWwindow window) +{ + printf("%08x at %0.3f: Cursor left window\n", counter++, glfwGetTime()); +} + static void scroll_callback(GLFWwindow window, int x, int y) { printf("%08x at %0.3f: Scroll: %i %i\n", counter++, glfwGetTime(), x, y); @@ -351,6 +361,8 @@ int main(void) glfwSetWindowIconifyCallback(window_iconify_callback); glfwSetMouseButtonCallback(mouse_button_callback); glfwSetMousePosCallback(mouse_position_callback); + glfwSetCursorEnterCallback(cursor_enter_callback); + glfwSetCursorLeaveCallback(cursor_leave_callback); glfwSetScrollCallback(scroll_callback); glfwSetKeyCallback(key_callback); glfwSetCharCallback(char_callback); From e5d85a5cc43649b25a7470e6c29d87849017ea3c Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 30 Jan 2012 22:48:59 +0100 Subject: [PATCH 010/226] Added credit. --- readme.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/readme.html b/readme.html index 4d1f4c72..49eaa376 100644 --- a/readme.html +++ b/readme.html @@ -840,6 +840,9 @@ their skills. Special thanks go out to:

  • Stefan Gustavson, for quick and thorough testing of GLFW on many and varied operating systems and hardware configurations
  • +
  • Hans 'Hanmac' Mackowiak, for the initial implementation of cursor enter + and leave callbacks on X11
  • +
  • Sylvain Hellegouarch, for support, bug reports and testing
  • Alex Holkner, for writing the code from which the Compiz/Intel fix was From c4806b95325c5db87345e494248d181035eb763d Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 30 Jan 2012 22:59:38 +0100 Subject: [PATCH 011/226] Merged cursor enter/leave callbacks. --- include/GL/glfw3.h | 4 +--- src/input.c | 35 ++++------------------------------- src/internal.h | 4 +--- src/x11_window.c | 4 ++-- tests/events.c | 13 +++++-------- 5 files changed, 13 insertions(+), 47 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 5bf080bd..31d8f199 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -474,8 +474,7 @@ typedef void (* GLFWwindowfocusfun)(GLFWwindow,int); typedef void (* GLFWwindowiconifyfun)(GLFWwindow,int); typedef void (* GLFWmousebuttonfun)(GLFWwindow,int,int); typedef void (* GLFWmouseposfun)(GLFWwindow,int,int); -typedef void (* GLFWcursorenterfun)(GLFWwindow); -typedef void (* GLFWcursorleavefun)(GLFWwindow); +typedef void (* GLFWcursorenterfun)(GLFWwindow,int); typedef void (* GLFWscrollfun)(GLFWwindow,int,int); typedef void (* GLFWkeyfun)(GLFWwindow,int,int); typedef void (* GLFWcharfun)(GLFWwindow,int); @@ -576,7 +575,6 @@ GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun); GLFWAPI void glfwSetMouseButtonCallback(GLFWmousebuttonfun cbfun); GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun); GLFWAPI void glfwSetCursorEnterCallback(GLFWcursorenterfun cbfun); -GLFWAPI void glfwSetCursorLeaveCallback(GLFWcursorleavefun cbfun); GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun); /* Joystick input */ diff --git a/src/input.c b/src/input.c index 903cb054..01d99de3 100644 --- a/src/input.c +++ b/src/input.c @@ -147,24 +147,13 @@ void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y) //======================================================================== -// Register cursor enter events +// Register cursor enter/leave events //======================================================================== -void _glfwInputCursorEnter(_GLFWwindow* window) +void _glfwInputCursorEnter(_GLFWwindow* window, int entered) { if (_glfwLibrary.cursorEnterCallback) - _glfwLibrary.cursorEnterCallback(window); -} - - -//======================================================================== -// Register cursor leave events -//======================================================================== - -void _glfwInputCursorLeave(_GLFWwindow* window) -{ - if (_glfwLibrary.cursorLeaveCallback) - _glfwLibrary.cursorLeaveCallback(window); + _glfwLibrary.cursorEnterCallback(window, entered); } @@ -443,7 +432,7 @@ GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun) //======================================================================== -// Set callback function for cursor enter events +// Set callback function for cursor enter/leave events //======================================================================== GLFWAPI void glfwSetCursorEnterCallback(GLFWcursorenterfun cbfun) @@ -458,22 +447,6 @@ GLFWAPI void glfwSetCursorEnterCallback(GLFWcursorenterfun cbfun) } -//======================================================================== -// Set callback function for cursor enter events -//======================================================================== - -GLFWAPI void glfwSetCursorLeaveCallback(GLFWcursorleavefun cbfun) -{ - if (!_glfwInitialized) - { - _glfwSetError(GLFW_NOT_INITIALIZED, NULL); - return; - } - - _glfwLibrary.cursorLeaveCallback = cbfun; -} - - //======================================================================== // Set callback function for scroll events //======================================================================== diff --git a/src/internal.h b/src/internal.h index db46f6c4..cabafeb4 100644 --- a/src/internal.h +++ b/src/internal.h @@ -238,7 +238,6 @@ struct _GLFWlibrary GLFWmousebuttonfun mouseButtonCallback; GLFWmouseposfun mousePosCallback; GLFWcursorenterfun cursorEnterCallback; - GLFWcursorleavefun cursorLeaveCallback; GLFWscrollfun scrollCallback; GLFWkeyfun keyCallback; GLFWcharfun charCallback; @@ -354,8 +353,7 @@ void _glfwInputChar(_GLFWwindow* window, int character); void _glfwInputScroll(_GLFWwindow* window, int x, int y); void _glfwInputMouseClick(_GLFWwindow* window, int button, int action); void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y); -void _glfwInputCursorEnter(_GLFWwindow* window); -void _glfwInputCursorLeave(_GLFWwindow* window); +void _glfwInputCursorEnter(_GLFWwindow* window, int entered); // OpenGL context helpers (opengl.c) int _glfwStringInExtensionString(const char* string, const GLubyte* extensions); diff --git a/src/x11_window.c b/src/x11_window.c index ad34eb81..ffe27722 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -1194,7 +1194,7 @@ static void processSingleEvent(void) if (window->cursorMode == GLFW_CURSOR_HIDDEN) hideMouseCursor(window); - _glfwInputCursorEnter(window); + _glfwInputCursorEnter(window, GL_TRUE); break; } @@ -1211,7 +1211,7 @@ static void processSingleEvent(void) if (window->cursorMode == GLFW_CURSOR_HIDDEN) showMouseCursor(window); - _glfwInputCursorLeave(window); + _glfwInputCursorEnter(window, GL_FALSE); break; } diff --git a/tests/events.c b/tests/events.c index 292da3ce..f276573e 100644 --- a/tests/events.c +++ b/tests/events.c @@ -274,14 +274,12 @@ static void mouse_position_callback(GLFWwindow window, int x, int y) printf("%08x at %0.3f: Mouse position: %i %i\n", counter++, glfwGetTime(), x, y); } -static void cursor_enter_callback(GLFWwindow window) +static void cursor_enter_callback(GLFWwindow window, int entered) { - printf("%08x at %0.3f: Cursor entered window\n", counter++, glfwGetTime()); -} - -static void cursor_leave_callback(GLFWwindow window) -{ - printf("%08x at %0.3f: Cursor left window\n", counter++, glfwGetTime()); + printf("%08x at %0.3f: Cursor %s window\n", + counter++, + glfwGetTime(), + entered ? "entered" : "left"); } static void scroll_callback(GLFWwindow window, int x, int y) @@ -362,7 +360,6 @@ int main(void) glfwSetMouseButtonCallback(mouse_button_callback); glfwSetMousePosCallback(mouse_position_callback); glfwSetCursorEnterCallback(cursor_enter_callback); - glfwSetCursorLeaveCallback(cursor_leave_callback); glfwSetScrollCallback(scroll_callback); glfwSetKeyCallback(key_callback); glfwSetCharCallback(char_callback); From 017e2b3483b2c093c32eb598e2cc039eb0305904 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 1 Feb 2012 00:48:29 +0100 Subject: [PATCH 012/226] Formatting and cleanup. --- src/cocoa_window.m | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 7d8cb991..284cbf4b 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -589,7 +589,7 @@ static GLboolean createContext(_GLFWwindow* window, ADD_ATTR2(NSOpenGLPFAAuxBuffers, fbconfig->auxBuffers); if (fbconfig->stereo) - ADD_ATTR(NSOpenGLPFAStereo ); + ADD_ATTR(NSOpenGLPFAStereo); if (fbconfig->samples > 0) { @@ -607,7 +607,7 @@ static GLboolean createContext(_GLFWwindow* window, if (window->NSGL.pixelFormat == nil) { _glfwSetError(GLFW_PLATFORM_ERROR, - "Cocoa/NSOpenGL: Failed to create pixel format"); + "Cocoa/NSOpenGL: Failed to create OpenGL pixel format"); return GL_FALSE; } @@ -640,8 +640,8 @@ static GLboolean createContext(_GLFWwindow* window, //======================================================================== int _glfwPlatformOpenWindow(_GLFWwindow* window, - const _GLFWwndconfig *wndconfig, - const _GLFWfbconfig *fbconfig) + const _GLFWwndconfig* wndconfig, + const _GLFWfbconfig* fbconfig) { // We can only have one application delegate, but we only allocate it the // first time we create a window to keep all window code in this file @@ -674,12 +674,6 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, else if (colorBits < 15) colorBits = 15; - // Ignored hints: - // OpenGLMajor, OpenGLMinor, OpenGLForward: - // pending Mac OS X support for OpenGL 3.x - // OpenGLDebug - // pending it meaning anything on Mac OS X - // Don't use accumulation buffer support; it's not accelerated // Aux buffers probably aren't accelerated either @@ -718,11 +712,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, { CGCaptureAllDisplays(); CGDisplaySwitchToMode(CGMainDisplayID(), fullscreenMode); - } - if (wndconfig->mode == GLFW_FULLSCREEN) - { - // TODO: Make this work on pre-Leopard systems [[window->NS.window contentView] enterFullScreenMode:[NSScreen mainScreen] withOptions:nil]; } From 58f78d4d15f0549c790aaa48d715696b77c0baa0 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sat, 4 Feb 2012 17:20:05 +0100 Subject: [PATCH 013/226] Updated .gitignore. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 678ddf95..fad26de1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ CMakeCache.txt Makefile cmake_uninstall.cmake .DS_Store +docs/Doxyfile src/config.h src/libglfw.pc src/libglfw.so @@ -32,6 +33,7 @@ tests/peter tests/reopen tests/sharing tests/tearing +tests/title tests/windows tests/*.app tests/*.exe From 84579305cb6532329c1e96beb0a0205fe9dfd00f Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 5 Feb 2012 02:07:50 +0100 Subject: [PATCH 014/226] Made string conversions globally available. --- src/win32_init.c | 54 ++++++++++++++++++++++++++++++++++++++++++++ src/win32_platform.h | 4 ++++ src/win32_window.c | 29 ++---------------------- 3 files changed, 60 insertions(+), 27 deletions(-) diff --git a/src/win32_init.c b/src/win32_init.c index b23e7d57..8f6015bd 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -131,6 +131,60 @@ static void freeLibraries(void) } +////////////////////////////////////////////////////////////////////////// +////// GLFW internal API ////// +////////////////////////////////////////////////////////////////////////// + +//======================================================================== +// Returns a wide string version of the specified UTF-8 string +//======================================================================== + +WCHAR* _glfwCreateWideStringFromUTF8(const char* source) +{ + WCHAR* target; + int length; + + length = MultiByteToWideChar(CP_UTF8, 0, source, -1, NULL, 0); + if (!length) + return NULL; + + target = (WCHAR*) _glfwMalloc(sizeof(WCHAR) * (length + 1)); + + if (!MultiByteToWideChar(CP_UTF8, 0, source, -1, target, length + 1)) + { + _glfwFree(target); + return NULL; + } + + return target; +} + + +//======================================================================== +// Returns a UTF-8 string version of the specified wide string +//======================================================================== + +char* _glfwCreateUTF8FromWideString(const WCHAR* source) +{ + char* target; + int length; + + length = WideCharToMultiByte(CP_UTF8, 0, source, -1, NULL, 0, NULL, NULL); + if (!length) + return NULL; + + target = (char*) _glfwMalloc(length + 1); + + if (!WideCharToMultiByte(CP_UTF8, 0, source, -1, target, length + 1, NULL, NULL)) + { + _glfwFree(target); + return NULL; + } + + return target; +} + + ////////////////////////////////////////////////////////////////////////// ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// diff --git a/src/win32_platform.h b/src/win32_platform.h index 0d63e09c..0e9a4e1f 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -325,6 +325,10 @@ typedef struct _GLFWlibraryWin32 // Prototypes for platform specific internal functions //======================================================================== +// Wide strings +WCHAR* _glfwCreateWideStringFromUTF8(const char* source); +char* _glfwCreateUTF8FromWideString(const WCHAR* source); + // Time void _glfwInitTimer(void); diff --git a/src/win32_window.c b/src/win32_window.c index 6ebe07b4..bf66fee4 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -34,31 +34,6 @@ #include -//======================================================================== -// Convert the specified UTF-8 string to a wide string -//======================================================================== - -static WCHAR* createWideStringFromUTF8(const char* source) -{ - WCHAR* target; - int length; - - length = MultiByteToWideChar(CP_UTF8, 0, source, -1, NULL, 0); - if (!length) - return NULL; - - target = (WCHAR*) _glfwMalloc(sizeof(WCHAR) * (length + 1)); - - if (!MultiByteToWideChar(CP_UTF8, 0, source, -1, target, length + 1)) - { - _glfwFree(target); - return NULL; - } - - return target; -} - - //======================================================================== // Convert BPP to RGB bits based on "best guess" //======================================================================== @@ -1357,7 +1332,7 @@ static int createWindow(_GLFWwindow* window, else SystemParametersInfo(SPI_GETWORKAREA, 0, &wa, 0); - wideTitle = createWideStringFromUTF8(wndconfig->title); + wideTitle = _glfwCreateWideStringFromUTF8(wndconfig->title); if (!wideTitle) { _glfwSetError(GLFW_PLATFORM_ERROR, @@ -1604,7 +1579,7 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window) void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) { - WCHAR* wideTitle = createWideStringFromUTF8(title); + WCHAR* wideTitle = _glfwCreateWideStringFromUTF8(title); if (!wideTitle) { _glfwSetError(GLFW_PLATFORM_ERROR, From fccef20b7604fa4552b1a2eaa75fea8a3cf39662 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 5 Feb 2012 02:41:52 +0100 Subject: [PATCH 015/226] Added explicit WINVER, avoid redefining UNICODE. --- src/win32_platform.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/win32_platform.h b/src/win32_platform.h index 0e9a4e1f..75725f6b 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -45,7 +45,13 @@ // thinks it is the only one that gets to do so #undef APIENTRY -#define UNICODE +// GLFW on Windows is Unicode only and does not work in MBCS mode +#ifndef UNICODE + #define UNICODE +#endif + +// GLFW requires Windows XP +#define WINVER 0x0501 #include #include From 32b07923ab839893afe48f652e7fb3b4ba6f2c94 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 5 Feb 2012 02:43:49 +0100 Subject: [PATCH 016/226] Formatting. --- src/win32_platform.h | 88 ++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/src/win32_platform.h b/src/win32_platform.h index 75725f6b..82b8c9ca 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -69,10 +69,10 @@ // Some old versions of w32api (used by MinGW and Cygwin) define // WH_KEYBOARD_LL without typedef:ing KBDLLHOOKSTRUCT (!) #if defined(__MINGW32__) || defined(__CYGWIN__) -#include -#if defined(WH_KEYBOARD_LL) && (__W32API_MAJOR_VERSION == 1) && (__W32API_MINOR_VERSION <= 2) -#undef WH_KEYBOARD_LL -#endif + #include + #if defined(WH_KEYBOARD_LL) && (__W32API_MAJOR_VERSION == 1) && (__W32API_MINOR_VERSION <= 2) + #undef WH_KEYBOARD_LL + #endif #endif //------------------------------------------------------------------------ @@ -92,64 +92,64 @@ typedef struct tagKBDLLHOOKSTRUCT { #endif // WH_KEYBOARD_LL #ifndef LLKHF_ALTDOWN -#define LLKHF_ALTDOWN 0x00000020 + #define LLKHF_ALTDOWN 0x00000020 #endif #ifndef SPI_SETSCREENSAVERRUNNING -#define SPI_SETSCREENSAVERRUNNING 97 + #define SPI_SETSCREENSAVERRUNNING 97 #endif #ifndef SPI_GETANIMATION -#define SPI_GETANIMATION 72 + #define SPI_GETANIMATION 72 #endif #ifndef SPI_SETANIMATION -#define SPI_SETANIMATION 73 + #define SPI_SETANIMATION 73 #endif #ifndef SPI_GETFOREGROUNDLOCKTIMEOUT -#define SPI_GETFOREGROUNDLOCKTIMEOUT 0x2000 + #define SPI_GETFOREGROUNDLOCKTIMEOUT 0x2000 #endif #ifndef SPI_SETFOREGROUNDLOCKTIMEOUT -#define SPI_SETFOREGROUNDLOCKTIMEOUT 0x2001 + #define SPI_SETFOREGROUNDLOCKTIMEOUT 0x2001 #endif #ifndef CDS_FULLSCREEN -#define CDS_FULLSCREEN 4 + #define CDS_FULLSCREEN 4 #endif #ifndef PFD_GENERIC_ACCELERATED -#define PFD_GENERIC_ACCELERATED 0x00001000 + #define PFD_GENERIC_ACCELERATED 0x00001000 #endif #ifndef PFD_DEPTH_DONTCARE -#define PFD_DEPTH_DONTCARE 0x20000000 + #define PFD_DEPTH_DONTCARE 0x20000000 #endif #ifndef ENUM_CURRENT_SETTINGS -#define ENUM_CURRENT_SETTINGS -1 + #define ENUM_CURRENT_SETTINGS -1 #endif #ifndef ENUM_REGISTRY_SETTINGS -#define ENUM_REGISTRY_SETTINGS -2 + #define ENUM_REGISTRY_SETTINGS -2 #endif #ifndef WM_MOUSEWHEEL -#define WM_MOUSEWHEEL 0x020A + #define WM_MOUSEWHEEL 0x020A #endif #ifndef WHEEL_DELTA -#define WHEEL_DELTA 120 + #define WHEEL_DELTA 120 #endif #ifndef WM_MOUSEHWHEEL -#define WM_MOUSEHWHEEL 0x020E + #define WM_MOUSEHWHEEL 0x020E #endif #ifndef WM_XBUTTONDOWN -#define WM_XBUTTONDOWN 0x020B + #define WM_XBUTTONDOWN 0x020B #endif #ifndef WM_XBUTTONUP -#define WM_XBUTTONUP 0x020C + #define WM_XBUTTONUP 0x020C #endif #ifndef XBUTTON1 -#define XBUTTON1 1 + #define XBUTTON1 1 #endif #ifndef XBUTTON2 -#define XBUTTON2 2 + #define XBUTTON2 2 #endif @@ -179,34 +179,34 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void); // gdi32.dll shortcuts #ifndef _GLFW_NO_DLOAD_GDI32 -#define _glfw_ChoosePixelFormat _glfwLibrary.Win32.gdi.ChoosePixelFormat -#define _glfw_DescribePixelFormat _glfwLibrary.Win32.gdi.DescribePixelFormat -#define _glfw_GetPixelFormat _glfwLibrary.Win32.gdi.GetPixelFormat -#define _glfw_SetPixelFormat _glfwLibrary.Win32.gdi.SetPixelFormat -#define _glfw_SwapBuffers _glfwLibrary.Win32.gdi.SwapBuffers -#define _glfw_GetDeviceGammaRamp _glfwLibrary.Win32.gdi.GetDeviceGammaRamp -#define _glfw_SetDeviceGammaRamp _glfwLibrary.Win32.gdi.SetDeviceGammaRamp + #define _glfw_ChoosePixelFormat _glfwLibrary.Win32.gdi.ChoosePixelFormat + #define _glfw_DescribePixelFormat _glfwLibrary.Win32.gdi.DescribePixelFormat + #define _glfw_GetPixelFormat _glfwLibrary.Win32.gdi.GetPixelFormat + #define _glfw_SetPixelFormat _glfwLibrary.Win32.gdi.SetPixelFormat + #define _glfw_SwapBuffers _glfwLibrary.Win32.gdi.SwapBuffers + #define _glfw_GetDeviceGammaRamp _glfwLibrary.Win32.gdi.GetDeviceGammaRamp + #define _glfw_SetDeviceGammaRamp _glfwLibrary.Win32.gdi.SetDeviceGammaRamp #else -#define _glfw_ChoosePixelFormat ChoosePixelFormat -#define _glfw_DescribePixelFormat DescribePixelFormat -#define _glfw_GetPixelFormat GetPixelFormat -#define _glfw_SetPixelFormat SetPixelFormat -#define _glfw_SwapBuffers SwapBuffers -#define _glfw_GetDeviceGammaRamp GetDeviceGammaRamp -#define _glfw_SetDeviceGammaRamp SetDeviceGammaRamp + #define _glfw_ChoosePixelFormat ChoosePixelFormat + #define _glfw_DescribePixelFormat DescribePixelFormat + #define _glfw_GetPixelFormat GetPixelFormat + #define _glfw_SetPixelFormat SetPixelFormat + #define _glfw_SwapBuffers SwapBuffers + #define _glfw_GetDeviceGammaRamp GetDeviceGammaRamp + #define _glfw_SetDeviceGammaRamp SetDeviceGammaRamp #endif // _GLFW_NO_DLOAD_GDI32 // winmm.dll shortcuts #ifndef _GLFW_NO_DLOAD_WINMM -#define _glfw_joyGetDevCaps _glfwLibrary.Win32.winmm.joyGetDevCaps -#define _glfw_joyGetPos _glfwLibrary.Win32.winmm.joyGetPos -#define _glfw_joyGetPosEx _glfwLibrary.Win32.winmm.joyGetPosEx -#define _glfw_timeGetTime _glfwLibrary.Win32.winmm.timeGetTime + #define _glfw_joyGetDevCaps _glfwLibrary.Win32.winmm.joyGetDevCaps + #define _glfw_joyGetPos _glfwLibrary.Win32.winmm.joyGetPos + #define _glfw_joyGetPosEx _glfwLibrary.Win32.winmm.joyGetPosEx + #define _glfw_timeGetTime _glfwLibrary.Win32.winmm.timeGetTime #else -#define _glfw_joyGetDevCaps joyGetDevCaps -#define _glfw_joyGetPos joyGetPos -#define _glfw_joyGetPosEx joyGetPosEx -#define _glfw_timeGetTime timeGetTime + #define _glfw_joyGetDevCaps joyGetDevCaps + #define _glfw_joyGetPos joyGetPos + #define _glfw_joyGetPosEx joyGetPosEx + #define _glfw_timeGetTime timeGetTime #endif // _GLFW_NO_DLOAD_WINMM From f6dfaf50ad8c9e24a41a45cf951a003aec01d0bd Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 5 Feb 2012 16:56:26 +0100 Subject: [PATCH 017/226] Formatting. --- src/internal.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/internal.h b/src/internal.h index 66ae954e..ec88b814 100644 --- a/src/internal.h +++ b/src/internal.h @@ -37,9 +37,9 @@ //======================================================================== #if defined(_init_c_) -#define GLFWGLOBAL + #define GLFWGLOBAL #else -#define GLFWGLOBAL extern + #define GLFWGLOBAL extern #endif @@ -66,13 +66,13 @@ #include "../support/GL/glext.h" #if defined(_GLFW_COCOA_NSGL) -#include "cocoa_platform.h" + #include "cocoa_platform.h" #elif defined(_GLFW_WIN32_WGL) -#include "win32_platform.h" + #include "win32_platform.h" #elif defined(_GLFW_X11_GLX) -#include "x11_platform.h" + #include "x11_platform.h" #else -#error "No supported platform selected" + #error "No supported platform selected" #endif typedef struct _GLFWhints _GLFWhints; From ba3a60523be2e4feeeee8256344a837723e8916f Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 6 Feb 2012 16:27:56 +0100 Subject: [PATCH 018/226] Added context state copying to sharing test. --- tests/sharing.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/sharing.c b/tests/sharing.c index 8be0e30b..02b852ef 100644 --- a/tests/sharing.c +++ b/tests/sharing.c @@ -92,8 +92,6 @@ static void draw_quad(GLuint texture) glBindTexture(GL_TEXTURE_2D, texture); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - glColor3f(0.6f, 0.f, 0.6f); - glBegin(GL_QUADS); glTexCoord2f(0.f, 0.f); @@ -142,6 +140,11 @@ int main(int argc, char** argv) exit(EXIT_FAILURE); } + // Set drawing color for the first context and copy it to the second + glfwMakeContextCurrent(windows[0]); + glColor3f(0.6f, 0.f, 0.6f); + glfwCopyContext(windows[0], windows[1], GL_CURRENT_BIT); + // Put the second window to the right of the first one glfwGetWindowPos(windows[0], &x, &y); glfwSetWindowPos(windows[1], x + WIDTH + 50, y); From 55a34c6967c73d5ccec53cc95b2f3d1ebd8ead08 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 7 Feb 2012 02:22:09 +0100 Subject: [PATCH 019/226] Made gamma test set gamma at startup. --- tests/gamma.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/gamma.c b/tests/gamma.c index dd10784e..33db05e1 100644 --- a/tests/gamma.c +++ b/tests/gamma.c @@ -124,6 +124,7 @@ int main(int argc, char** argv) exit(EXIT_FAILURE); } + glfwSetGamma(gamma); printf("Gamma: %f\n", gamma); glfwSwapInterval(1); From b35ef1ac5316237cb6de61634f2aa92672b5b336 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 7 Feb 2012 02:29:02 +0100 Subject: [PATCH 020/226] Added gamma setting function. --- tests/gamma.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/tests/gamma.c b/tests/gamma.c index 33db05e1..d6bb17f4 100644 --- a/tests/gamma.c +++ b/tests/gamma.c @@ -35,6 +35,8 @@ #include "getopt.h" +#define STEP_SIZE 0.1f + static GLfloat gamma = 1.0f; static void usage(void) @@ -42,6 +44,13 @@ static void usage(void) printf("Usage: gammatest [-h] [-f]\n"); } +static void set_gamma(float value) +{ + gamma = value; + printf("Gamma: %f\n", gamma); + glfwSetGamma(gamma); +} + static void key_callback(GLFWwindow window, int key, int action) { if (action != GLFW_PRESS) @@ -50,20 +59,26 @@ static void key_callback(GLFWwindow window, int key, int action) switch (key) { case GLFW_KEY_ESCAPE: + { glfwCloseWindow(window); break; + } + case GLFW_KEY_KP_ADD: case GLFW_KEY_Q: - gamma += 0.1f; - printf("Gamma: %f\n", gamma); - glfwSetGamma(gamma); + { + set_gamma(gamma + STEP_SIZE); break; + } + case GLFW_KEY_KP_SUBTRACT: case GLFW_KEY_W: - gamma -= 0.1f; - printf("Gamma: %f\n", gamma); - glfwSetGamma(gamma); + { + if (gamma - STEP_SIZE > 0.f) + set_gamma(gamma - STEP_SIZE); + break; + } } } @@ -124,8 +139,7 @@ int main(int argc, char** argv) exit(EXIT_FAILURE); } - glfwSetGamma(gamma); - printf("Gamma: %f\n", gamma); + set_gamma(1.f); glfwSwapInterval(1); glfwSetKeyCallback(key_callback); From 086fba40b44ae4cc4a6f5090b3001c123e4ecf60 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 7 Feb 2012 02:30:52 +0100 Subject: [PATCH 021/226] Fixed program names in help output. --- tests/gamma.c | 2 +- tests/glfwinfo.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/gamma.c b/tests/gamma.c index d6bb17f4..ef8e0b49 100644 --- a/tests/gamma.c +++ b/tests/gamma.c @@ -41,7 +41,7 @@ static GLfloat gamma = 1.0f; static void usage(void) { - printf("Usage: gammatest [-h] [-f]\n"); + printf("Usage: gamma [-h] [-f]\n"); } static void set_gamma(float value) diff --git a/tests/glfwinfo.c b/tests/glfwinfo.c index efaff6b9..e7ff0294 100644 --- a/tests/glfwinfo.c +++ b/tests/glfwinfo.c @@ -51,7 +51,7 @@ static void usage(void) { - printf("Usage: version [-h] [-m MAJOR] [-n MINOR] [-d] [-l] [-f] [-p PROFILE] [-r STRATEGY]\n"); + printf("Usage: glfwinfo [-h] [-m MAJOR] [-n MINOR] [-d] [-l] [-f] [-p PROFILE] [-r STRATEGY]\n"); printf("available profiles: " PROFILE_NAME_CORE " " PROFILE_NAME_COMPAT " " PROFILE_NAME_ES2 "\n"); printf("available strategies: " STRATEGY_NAME_NONE " " STRATEGY_NAME_LOSE "\n"); } From 0c3b1b5a0ee571289f254945a0c9046ee4e872f7 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 7 Feb 2012 14:58:58 +0100 Subject: [PATCH 022/226] Removed allocator. --- examples/boing.c | 2 +- examples/gears.c | 2 +- examples/heightmap.c | 2 +- examples/splitview.c | 2 +- examples/triangle.c | 2 +- examples/wave.c | 2 +- include/GL/glfw3.h | 11 +---------- readme.html | 1 - src/cocoa_joystick.m | 8 ++++---- src/init.c | 44 +------------------------------------------- src/internal.h | 6 ------ src/win32_window.c | 14 +++++++------- src/window.c | 4 ++-- src/x11_fullscreen.c | 12 ++++++------ src/x11_window.c | 6 +++--- tests/accuracy.c | 2 +- tests/defaults.c | 2 +- tests/dynamic.c | 2 +- tests/events.c | 2 +- tests/fsaa.c | 2 +- tests/fsfocus.c | 2 +- tests/gamma.c | 2 +- tests/glfwinfo.c | 2 +- tests/iconify.c | 2 +- tests/joysticks.c | 2 +- tests/listmodes.c | 2 +- tests/peter.c | 2 +- tests/reopen.c | 2 +- tests/sharing.c | 2 +- tests/tearing.c | 2 +- tests/title.c | 2 +- tests/windows.c | 2 +- 32 files changed, 47 insertions(+), 105 deletions(-) diff --git a/examples/boing.c b/examples/boing.c index 8cf5b1dc..33696e46 100644 --- a/examples/boing.c +++ b/examples/boing.c @@ -569,7 +569,7 @@ int main( void ) GLFWwindow window; /* Init GLFW */ - if( !glfwInit(NULL) ) + if( !glfwInit() ) { fprintf( stderr, "Failed to initialize GLFW\n" ); exit( EXIT_FAILURE ); diff --git a/examples/gears.c b/examples/gears.c index cbf9eab9..53d601f3 100644 --- a/examples/gears.c +++ b/examples/gears.c @@ -323,7 +323,7 @@ int main(int argc, char *argv[]) { GLFWwindow window; - if( !glfwInit(NULL) ) + if( !glfwInit() ) { fprintf( stderr, "Failed to initialize GLFW\n" ); exit( EXIT_FAILURE ); diff --git a/examples/heightmap.c b/examples/heightmap.c index a55df291..f4bec28c 100644 --- a/examples/heightmap.c +++ b/examples/heightmap.c @@ -573,7 +573,7 @@ int main(int argc, char** argv) } } - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "ERROR: Unable to initialize GLFW\n"); usage(); diff --git a/examples/splitview.c b/examples/splitview.c index 3fcdd1d8..2cd43fdf 100644 --- a/examples/splitview.c +++ b/examples/splitview.c @@ -442,7 +442,7 @@ int main(void) GLFWwindow window; // Initialise GLFW - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW\n"); exit(EXIT_FAILURE); diff --git a/examples/triangle.c b/examples/triangle.c index e952cc70..e61ea9ab 100644 --- a/examples/triangle.c +++ b/examples/triangle.c @@ -15,7 +15,7 @@ int main(void) GLFWwindow window; // Initialise GLFW - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW\n"); exit(EXIT_FAILURE); diff --git a/examples/wave.c b/examples/wave.c index 9ffcd3f7..1eb8b855 100644 --- a/examples/wave.c +++ b/examples/wave.c @@ -379,7 +379,7 @@ int main(int argc, char* argv[]) GLFWwindow window; double t, dt_total, t_old; - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "GLFW initialization failed\n"); exit(EXIT_FAILURE); diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 59bd6fdb..e84bdbba 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -478,8 +478,6 @@ typedef void (* GLFWmouseposfun)(GLFWwindow,int,int); typedef void (* GLFWscrollfun)(GLFWwindow,int,int); typedef void (* GLFWkeyfun)(GLFWwindow,int,int); typedef void (* GLFWcharfun)(GLFWwindow,int); -typedef void* (* GLFWmallocfun)(size_t); -typedef void (* GLFWfreefun)(void*); /* The video mode structure used by glfwGetVideoModes */ typedef struct @@ -499,20 +497,13 @@ typedef struct unsigned short blue[GLFW_GAMMA_RAMP_SIZE]; } GLFWgammaramp; -/* Custom memory allocator interface */ -typedef struct -{ - GLFWmallocfun malloc; - GLFWfreefun free; -} GLFWallocator; - /************************************************************************* * Prototypes *************************************************************************/ /* Initialization, termination and version querying */ -GLFWAPI int glfwInit(GLFWallocator* allocator); +GLFWAPI int glfwInit(void); GLFWAPI void glfwTerminate(void); GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev); GLFWAPI const char* glfwGetVersionString(void); diff --git a/readme.html b/readme.html index e342a91d..36f0ce47 100644 --- a/readme.html +++ b/readme.html @@ -272,7 +272,6 @@ version of GLFW.

  • Added glfwSetWindowFocusCallback function and GLFWwindowfocusfun type for receiving window focus events
  • Added glfwSetWindowIconifyCallback function and GLFWwindowiconifyfun type for receiving window iconification events
  • Added glfwGetCurrentContext function for retrieving the window whose OpenGL context is current
  • -
  • Added GLFWallocator type and glfwInit parameter for pluggable memory allocator
  • Added glfwCopyContext function for copying OpenGL state categories between contexts
  • Added GLFW_OPENGL_ES2_PROFILE profile for creating OpenGL ES 2.0 contexts using the GLX_EXT_create_context_es2_profile and WGL_EXT_create_context_es2_profile extensions
  • Added GLFW_OPENGL_ROBUSTNESS window hint and associated strategy tokens for GL_ARB_robustness support
  • diff --git a/src/cocoa_joystick.m b/src/cocoa_joystick.m index 0aa10a4a..a167692f 100644 --- a/src/cocoa_joystick.m +++ b/src/cocoa_joystick.m @@ -152,7 +152,7 @@ static void addJoystickElement(_glfwJoystick* joystick, CFTypeRef refElement) long number; CFTypeRef refType; - _glfwJoystickElement* element = (_glfwJoystickElement*) _glfwMalloc(sizeof(_glfwJoystickElement)); + _glfwJoystickElement* element = (_glfwJoystickElement*) malloc(sizeof(_glfwJoystickElement)); CFArrayAppendValue(elementsArray, element); @@ -242,7 +242,7 @@ static void removeJoystick(_glfwJoystick* joystick) { _glfwJoystickElement* axes = (_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->axes, i); - _glfwFree(axes); + free(axes); } CFArrayRemoveAllValues(joystick->axes); joystick->numAxes = 0; @@ -251,7 +251,7 @@ static void removeJoystick(_glfwJoystick* joystick) { _glfwJoystickElement* button = (_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->buttons, i); - _glfwFree(button); + free(button); } CFArrayRemoveAllValues(joystick->buttons); joystick->numButtons = 0; @@ -260,7 +260,7 @@ static void removeJoystick(_glfwJoystick* joystick) { _glfwJoystickElement* hat = (_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->hats, i); - _glfwFree(hat); + free(hat); } CFArrayRemoveAllValues(joystick->hats); joystick->hats = 0; diff --git a/src/init.c b/src/init.c index 8a28b5cc..336cfe25 100644 --- a/src/init.c +++ b/src/init.c @@ -35,30 +35,6 @@ #include -////////////////////////////////////////////////////////////////////////// -////// GLFW internal API ////// -////////////////////////////////////////////////////////////////////////// - -//======================================================================== -// Allocate memory using the allocator -//======================================================================== - -void* _glfwMalloc(size_t size) -{ - return _glfwLibrary.allocator.malloc(size); -} - - -//======================================================================== -// Free memory using the allocator -//======================================================================== - -void _glfwFree(void* ptr) -{ - _glfwLibrary.allocator.free(ptr); -} - - ////////////////////////////////////////////////////////////////////////// ////// GLFW public API ////// ////////////////////////////////////////////////////////////////////////// @@ -67,31 +43,13 @@ void _glfwFree(void* ptr) // Initialize various GLFW state //======================================================================== -GLFWAPI int glfwInit(GLFWallocator* allocator) +GLFWAPI int glfwInit(void) { if (_glfwInitialized) return GL_TRUE; memset(&_glfwLibrary, 0, sizeof(_glfwLibrary)); - if (allocator) - { - // Verify that the specified model is complete - if (!allocator->malloc || !allocator->free) - { - _glfwSetError(GLFW_INVALID_VALUE, NULL); - return GL_FALSE; - } - - _glfwLibrary.allocator = *allocator; - } - else - { - // Use the libc malloc and free - _glfwLibrary.allocator.malloc = malloc; - _glfwLibrary.allocator.free = free; - } - // Not all window hints have zero as their default value, so this // needs to be here despite the memset above _glfwSetDefaultWindowHints(); diff --git a/src/internal.h b/src/internal.h index ec88b814..1f13ac02 100644 --- a/src/internal.h +++ b/src/internal.h @@ -241,8 +241,6 @@ struct _GLFWlibrary GLFWkeyfun keyCallback; GLFWcharfun charCallback; - GLFWallocator allocator; - GLFWgammaramp currentRamp; GLFWgammaramp originalRamp; int originalRampSize; @@ -325,10 +323,6 @@ void _glfwPlatformCopyContext(_GLFWwindow* src, _GLFWwindow* dst, unsigned long // Prototypes for platform independent internal functions //======================================================================== -// Memory management (init.c) -void* _glfwMalloc(size_t size); -void _glfwFree(void* ptr); - // Fullscren management (fullscreen.c) void _glfwSplitBPP(int bpp, int* red, int* green, int* blue); diff --git a/src/win32_window.c b/src/win32_window.c index 6ebe07b4..caf66645 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -47,11 +47,11 @@ static WCHAR* createWideStringFromUTF8(const char* source) if (!length) return NULL; - target = (WCHAR*) _glfwMalloc(sizeof(WCHAR) * (length + 1)); + target = (WCHAR*) malloc(sizeof(WCHAR) * (length + 1)); if (!MultiByteToWideChar(CP_UTF8, 0, source, -1, target, length + 1)) { - _glfwFree(target); + free(target); return NULL; } @@ -220,7 +220,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) return NULL; } - result = (_GLFWfbconfig*) _glfwMalloc(sizeof(_GLFWfbconfig) * count); + result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count); if (!result) { _glfwSetError(GLFW_OUT_OF_MEMORY, @@ -1282,13 +1282,13 @@ static int choosePixelFormat(_GLFWwindow* window, const _GLFWfbconfig* fbconfig) closest = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount); if (!closest) { - _glfwFree(fbconfigs); + free(fbconfigs); return 0; } pixelFormat = (int) closest->platformID; - _glfwFree(fbconfigs); + free(fbconfigs); fbconfigs = NULL; closest = NULL; @@ -1383,7 +1383,7 @@ static int createWindow(_GLFWwindow* window, return GL_FALSE; } - _glfwFree(wideTitle); + free(wideTitle); window->WGL.DC = GetDC(window->Win32.handle); if (!window->WGL.DC) @@ -1614,7 +1614,7 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) SetWindowText(window->Win32.handle, wideTitle); - _glfwFree(wideTitle); + free(wideTitle); } diff --git a/src/window.c b/src/window.c index de89b069..433275b1 100644 --- a/src/window.c +++ b/src/window.c @@ -291,7 +291,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, height = 480; } - window = (_GLFWwindow*) _glfwMalloc(sizeof(_GLFWwindow)); + window = (_GLFWwindow*) malloc(sizeof(_GLFWwindow)); if (!window) { _glfwSetError(GLFW_OUT_OF_MEMORY, @@ -492,7 +492,7 @@ GLFWAPI void glfwCloseWindow(GLFWwindow handle) *prev = window->next; } - _glfwFree(window); + free(window); } diff --git a/src/x11_fullscreen.c b/src/x11_fullscreen.c index bb0a3d53..e71c2a2b 100644 --- a/src/x11_fullscreen.c +++ b/src/x11_fullscreen.c @@ -339,7 +339,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) return 0; } - rgbarray = (int*) _glfwMalloc(sizeof(int) * viscount); + rgbarray = (int*) malloc(sizeof(int) * viscount); rgbcount = 0; // Build RGB array @@ -387,7 +387,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) sc = XRRGetScreenInfo(_glfwLibrary.X11.display, _glfwLibrary.X11.root); sizelist = XRRConfigSizes(sc, &sizecount); - resarray = (struct _glfwResolution*) _glfwMalloc(sizeof(struct _glfwResolution) * sizecount); + resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * sizecount); for (k = 0; k < sizecount; k++) { @@ -407,7 +407,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen, &modecount, &modelist); - resarray = (struct _glfwResolution*) _glfwMalloc(sizeof(struct _glfwResolution) * modecount); + resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * modecount); for (k = 0; k < modecount; k++) { @@ -436,7 +436,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) if (!resarray) { rescount = 1; - resarray = (struct _glfwResolution*) _glfwMalloc(sizeof(struct _glfwResolution) * rescount); + resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * rescount); resarray[0].width = DisplayWidth(_glfwLibrary.X11.display, screen); resarray[0].height = DisplayHeight(_glfwLibrary.X11.display, screen); @@ -459,8 +459,8 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) XFree(vislist); - _glfwFree(resarray); - _glfwFree(rgbarray); + free(resarray); + free(rgbarray); return count; } diff --git a/src/x11_window.c b/src/x11_window.c index 7ad34d05..37915f6a 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -316,7 +316,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) } } - result = (_GLFWfbconfig*) _glfwMalloc(sizeof(_GLFWfbconfig) * count); + result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count); if (!result) { _glfwSetError(GLFW_OUT_OF_MEMORY, @@ -1415,12 +1415,12 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, result = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount); if (!result) { - _glfwFree(fbconfigs); + free(fbconfigs); return GL_FALSE; } closest = *result; - _glfwFree(fbconfigs); + free(fbconfigs); } if (!createContext(window, wndconfig, (GLXFBConfigID) closest.platformID)) diff --git a/tests/accuracy.c b/tests/accuracy.c index 38f1374e..f235cf75 100644 --- a/tests/accuracy.c +++ b/tests/accuracy.c @@ -59,7 +59,7 @@ int main(void) { GLFWwindow window; - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/defaults.c b/tests/defaults.c index b50abaaa..d7c5a02c 100644 --- a/tests/defaults.c +++ b/tests/defaults.c @@ -69,7 +69,7 @@ int main(void) int i, width, height; GLFWwindow window; - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/dynamic.c b/tests/dynamic.c index b4257271..8bc5568b 100644 --- a/tests/dynamic.c +++ b/tests/dynamic.c @@ -59,7 +59,7 @@ int main(void) exit(EXIT_FAILURE); } - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW\n"); exit(EXIT_FAILURE); diff --git a/tests/events.c b/tests/events.c index 41928db7..fffd9f58 100644 --- a/tests/events.c +++ b/tests/events.c @@ -330,7 +330,7 @@ int main(void) setlocale(LC_ALL, ""); - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/fsaa.c b/tests/fsaa.c index e2fcf387..6cdb77e0 100644 --- a/tests/fsaa.c +++ b/tests/fsaa.c @@ -81,7 +81,7 @@ int main(int argc, char** argv) } } - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/fsfocus.c b/tests/fsfocus.c index bf634d54..951409a6 100644 --- a/tests/fsfocus.c +++ b/tests/fsfocus.c @@ -75,7 +75,7 @@ int main(void) { GLFWwindow window; - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/gamma.c b/tests/gamma.c index ef8e0b49..b8ec6c45 100644 --- a/tests/gamma.c +++ b/tests/gamma.c @@ -111,7 +111,7 @@ int main(int argc, char** argv) } } - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/glfwinfo.c b/tests/glfwinfo.c index e7ff0294..369e6a96 100644 --- a/tests/glfwinfo.c +++ b/tests/glfwinfo.c @@ -183,7 +183,7 @@ int main(int argc, char** argv) glfwSetErrorCallback(error_callback); - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/iconify.c b/tests/iconify.c index 1ee235f1..6d001ea5 100644 --- a/tests/iconify.c +++ b/tests/iconify.c @@ -90,7 +90,7 @@ int main(int argc, char** argv) } } - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/joysticks.c b/tests/joysticks.c index d777d431..23ac88a3 100644 --- a/tests/joysticks.c +++ b/tests/joysticks.c @@ -94,7 +94,7 @@ int main(void) double update; /* Initialise GLFW */ - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/listmodes.c b/tests/listmodes.c index 6962974d..a4648ef6 100644 --- a/tests/listmodes.c +++ b/tests/listmodes.c @@ -21,7 +21,7 @@ int main(void) GLFWvidmode dtmode, modes[400]; int modecount, i; - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/peter.c b/tests/peter.c index 7c808229..5ae7ba5d 100644 --- a/tests/peter.c +++ b/tests/peter.c @@ -111,7 +111,7 @@ static GLboolean open_window(void) int main(void) { - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/reopen.c b/tests/reopen.c index 484be996..2922cb84 100644 --- a/tests/reopen.c +++ b/tests/reopen.c @@ -84,7 +84,7 @@ static GLboolean open_window(int width, int height, int mode) { double base; - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); return GL_FALSE; diff --git a/tests/sharing.c b/tests/sharing.c index 02b852ef..7d774151 100644 --- a/tests/sharing.c +++ b/tests/sharing.c @@ -115,7 +115,7 @@ int main(int argc, char** argv) GLuint texture; int x, y; - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/tearing.c b/tests/tearing.c index 044f8ecc..10170b0f 100644 --- a/tests/tearing.c +++ b/tests/tearing.c @@ -44,7 +44,7 @@ int main(void) float position; GLFWwindow window; - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/title.c b/tests/title.c index 35344a04..7b342d94 100644 --- a/tests/title.c +++ b/tests/title.c @@ -41,7 +41,7 @@ int main(void) { GLFWwindow window; - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); diff --git a/tests/windows.c b/tests/windows.c index f5844762..c7ff32b2 100644 --- a/tests/windows.c +++ b/tests/windows.c @@ -46,7 +46,7 @@ int main(void) GLboolean running = GL_TRUE; GLFWwindow windows[4]; - if (!glfwInit(NULL)) + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); From bba4a563529ea2528a346b9bb40cb332dce24fcf Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 7 Feb 2012 16:21:19 +0100 Subject: [PATCH 023/226] Added missing return value. --- 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 2ca7add6..14cf8cb9 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1337,7 +1337,7 @@ static int createWindow(_GLFWwindow* window, { _glfwSetError(GLFW_PLATFORM_ERROR, "glfwOpenWindow: Failed to convert title to wide string"); - return; + return GL_FALSE; } window->Win32.handle = CreateWindowEx(window->Win32.dwExStyle, From 0b34cb1466ac69f14f514d534009091bb47c2fb9 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 7 Feb 2012 16:21:37 +0100 Subject: [PATCH 024/226] Removed unused variable. --- 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 14cf8cb9..2fb82943 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1280,7 +1280,7 @@ static int createWindow(_GLFWwindow* window, const _GLFWfbconfig* fbconfig) { DWORD dwStyle, dwExStyle; - int length, pixelFormat, fullWidth, fullHeight; + int pixelFormat, fullWidth, fullHeight; RECT wa; POINT pos; WCHAR* wideTitle; From 5159cfc2b08f752f4e2de227b8da9b44fa23e457 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 7 Feb 2012 16:40:26 +0100 Subject: [PATCH 025/226] Added window close control. --- tests/events.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/events.c b/tests/events.c index fffd9f58..e43c52ea 100644 --- a/tests/events.c +++ b/tests/events.c @@ -42,6 +42,7 @@ static GLboolean keyrepeat = 0; static GLboolean systemkeys = 1; +static GLboolean closeable = 1; static unsigned int counter = 0; static const char* get_key_name(int key) @@ -230,7 +231,7 @@ static void window_size_callback(GLFWwindow window, int width, int height) static int window_close_callback(GLFWwindow window) { printf("%08x at %0.3f: Window close\n", counter++, glfwGetTime()); - return 1; + return closeable; } static void window_refresh_callback(GLFWwindow window) @@ -312,6 +313,14 @@ static void key_callback(GLFWwindow window, int key, int action) printf("(( system keys %s ))\n", systemkeys ? "enabled" : "disabled"); break; } + + case GLFW_KEY_C: + { + closeable = !closeable; + + printf("(( closing %s ))\n", closeable ? "enabled" : "disabled"); + break; + } } } From cd670c34a28f5b343dfd10cc51d2ed401e9bfbba Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 7 Feb 2012 16:44:22 +0100 Subject: [PATCH 026/226] Fixed Alt+F4 not being translated into WM_CLOSE. --- readme.html | 1 + src/win32_window.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/readme.html b/readme.html index 36f0ce47..eb18fced 100644 --- a/readme.html +++ b/readme.html @@ -324,6 +324,7 @@ version of GLFW.

  • [Win32] Bugfix: Window activation and iconification did not work as expected
  • [Win32] Bugfix: Software rasterizer pixel formats were not discarded by the WGL_ARB_pixel_format code path
  • [Win32] Bugfix: The array for WGL context attributes was too small and could overflow
  • +
  • [Win32] Bugfix: Alt+F4 hot key was not translated into WM_CLOSE
  • v2.7

    diff --git a/src/win32_window.c b/src/win32_window.c index 2fb82943..24788a33 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -895,7 +895,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, if (_glfwLibrary.charCallback) translateChar(window, (DWORD) wParam, (DWORD) lParam); - return 0; + break; } case WM_KEYUP: @@ -910,7 +910,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, else _glfwInputKey(window, translateKey(wParam, lParam), GLFW_RELEASE); - return 0; + break; } case WM_LBUTTONDOWN: From 30ae9bdd471866e8eb698c61ac651042d887a15a Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 7 Feb 2012 17:19:38 +0100 Subject: [PATCH 027/226] Formatting. --- tests/events.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/events.c b/tests/events.c index e43c52ea..5603258b 100644 --- a/tests/events.c +++ b/tests/events.c @@ -40,9 +40,9 @@ #include #include -static GLboolean keyrepeat = 0; -static GLboolean systemkeys = 1; -static GLboolean closeable = 1; +static GLboolean keyrepeat = GL_FALSE; +static GLboolean systemkeys = GL_TRUE; +static GLboolean closeable = GL_TRUE; static unsigned int counter = 0; static const char* get_key_name(int key) From 62e8d07f4fe35807320f6f3e41c47707dbc1c849 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 9 Feb 2012 00:49:11 +0100 Subject: [PATCH 028/226] Added swap interval toggling to tearing test. --- tests/tearing.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/tearing.c b/tests/tearing.c index 10170b0f..4917ca68 100644 --- a/tests/tearing.c +++ b/tests/tearing.c @@ -34,11 +34,30 @@ #include #include +static int swap_interval; + +static void set_swap_interval(int value) +{ + char title[256]; + + swap_interval = value; + glfwSwapInterval(swap_interval); + + sprintf(title, "Tearing detector (interval %i)", swap_interval); + glfwSetWindowTitle(glfwGetCurrentContext(), title); +} + static void window_size_callback(GLFWwindow window, int width, int height) { glViewport(0, 0, width, height); } +static void key_callback(GLFWwindow window, int key, int action) +{ + if (key == GLFW_KEY_SPACE && action == GLFW_PRESS) + set_swap_interval(!swap_interval); +} + int main(void) { float position; @@ -60,7 +79,8 @@ int main(void) } glfwSetWindowSizeCallback(window_size_callback); - glfwSwapInterval(1); + glfwSetKeyCallback(key_callback); + set_swap_interval(1); glMatrixMode(GL_PROJECTION); glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f); From 13a438c91ecb24d0966f1464e30e8eb1b9634370 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 9 Feb 2012 01:53:26 +0100 Subject: [PATCH 029/226] Replaced NSDate time source with mach_absolute_time. --- readme.html | 1 + src/cocoa_init.m | 2 ++ src/cocoa_platform.h | 6 +++++- src/cocoa_time.m | 38 ++++++++++++++++++++++++++++++++++---- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/readme.html b/readme.html index eb18fced..19e4285d 100644 --- a/readme.html +++ b/readme.html @@ -310,6 +310,7 @@ version of GLFW.

  • 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
  • [Cocoa] Added support for joysticks
  • +
  • [Cocoa] Replaced NSDate time source with mach_absolute_time
  • [Cocoa] Bugfix: The loop condition for saving video modes used the wrong index variable
  • [Cocoa] Bugfix: The OpenGL framework was not retrieved, making glfwGetProcAddress crash
  • [X11] Added support for the GLX_EXT_swap_control extension as an alternative to GLX_SGI_swap_control
  • diff --git a/src/cocoa_init.m b/src/cocoa_init.m index bf4f7c2e..2c747515 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -230,6 +230,8 @@ int _glfwPlatformInit(void) _glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp); _glfwLibrary.currentRamp = _glfwLibrary.originalRamp; + _glfwInitTimer(); + _glfwInitJoysticks(); return GL_TRUE; diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index d5daf775..93492dbb 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -85,7 +85,8 @@ typedef struct _GLFWwindowNS typedef struct _GLFWlibraryNS { struct { - double t0; + double base; + double resolution; } timer; // dlopen handle for dynamically loading OpenGL extension entry points @@ -101,6 +102,9 @@ typedef struct _GLFWlibraryNS // Prototypes for platform specific internal functions //======================================================================== +// Time +void _glfwInitTimer(void); + // Joystick input void _glfwInitJoysticks(void); void _glfwTerminateJoysticks(void); diff --git a/src/cocoa_time.m b/src/cocoa_time.m index d7e7d2b8..4facbffb 100644 --- a/src/cocoa_time.m +++ b/src/cocoa_time.m @@ -29,6 +29,36 @@ #include "internal.h" +#include + + +//======================================================================== +// Return raw time +//======================================================================== + +static uint64_t getRawTime(void) +{ + return mach_absolute_time(); +} + + +////////////////////////////////////////////////////////////////////////// +////// GLFW internal API ////// +////////////////////////////////////////////////////////////////////////// + +//======================================================================== +// Initialise timer +//======================================================================== + +void _glfwInitTimer(void) +{ + mach_timebase_info_data_t info; + mach_timebase_info(&info); + + _glfwLibrary.NS.timer.resolution = (double) info.numer / (info.denom * 1.0e9); + _glfwLibrary.NS.timer.base = getRawTime(); +} + ////////////////////////////////////////////////////////////////////////// ////// GLFW platform API ////// @@ -40,8 +70,8 @@ double _glfwPlatformGetTime(void) { - return [NSDate timeIntervalSinceReferenceDate] - - _glfwLibrary.NS.timer.t0; + return (double) (getRawTime() - _glfwLibrary.NS.timer.base) * + _glfwLibrary.NS.timer.resolution; } //======================================================================== @@ -50,7 +80,7 @@ double _glfwPlatformGetTime(void) void _glfwPlatformSetTime(double time) { - _glfwLibrary.NS.timer.t0 = - [NSDate timeIntervalSinceReferenceDate] - time; + _glfwLibrary.NS.timer.base = getRawTime() - + (uint64_t) (time / _glfwLibrary.NS.timer.resolution); } From da86ba8062f3d38ce1b70976962b5ebea9969050 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 9 Feb 2012 02:07:43 +0100 Subject: [PATCH 030/226] Added logging of window size. --- tests/iconify.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/iconify.c b/tests/iconify.c index 6d001ea5..dbc4d9cf 100644 --- a/tests/iconify.c +++ b/tests/iconify.c @@ -62,6 +62,8 @@ static void key_callback(GLFWwindow window, int key, int action) static void size_callback(GLFWwindow window, int width, int height) { + printf("%0.2f Size %ix%i\n", glfwGetTime(), width, height); + glViewport(0, 0, width, height); } From 9760c2ad5ac71e1c615dd430b913d10dce77adc6 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 9 Feb 2012 02:25:25 +0100 Subject: [PATCH 031/226] Tearing test cleanup. --- tests/tearing.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/tearing.c b/tests/tearing.c index 4917ca68..1eab454e 100644 --- a/tests/tearing.c +++ b/tests/tearing.c @@ -69,7 +69,7 @@ int main(void) exit(EXIT_FAILURE); } - window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Tearing Detector", NULL); + window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "", NULL); if (!window) { glfwTerminate(); @@ -78,9 +78,10 @@ int main(void) exit(EXIT_FAILURE); } + set_swap_interval(1); + glfwSetWindowSizeCallback(window_size_callback); glfwSetKeyCallback(key_callback); - set_swap_interval(1); glMatrixMode(GL_PROJECTION); glOrtho(-1.f, 1.f, -1.f, 1.f, 1.f, -1.f); From f2062e06b7ac24c91fc73089c8c159e991a9ce9a Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 9 Feb 2012 16:31:01 +0100 Subject: [PATCH 032/226] Removed traces of Captain Obvious. --- src/input.c | 6 ------ src/window.c | 1 - 2 files changed, 7 deletions(-) diff --git a/src/input.c b/src/input.c index 0ad3c1b8..ec894a27 100644 --- a/src/input.c +++ b/src/input.c @@ -351,10 +351,8 @@ GLFWAPI int glfwGetKey(GLFWwindow handle, int key) return GLFW_RELEASE; } - // Is it a valid key? if (key < 0 || key > GLFW_KEY_LAST) { - // TODO: Decide whether key is a value or enum _glfwSetError(GLFW_INVALID_ENUM, "glfwGetKey: The specified key is invalid"); return GLFW_RELEASE; @@ -385,7 +383,6 @@ GLFWAPI int glfwGetMouseButton(GLFWwindow handle, int button) return GLFW_RELEASE; } - // Is it a valid mouse button? if (button < 0 || button > GLFW_MOUSE_BUTTON_LAST) { _glfwSetError(GLFW_INVALID_ENUM, @@ -418,7 +415,6 @@ GLFWAPI void glfwGetMousePos(GLFWwindow handle, int* xpos, int* ypos) return; } - // Return mouse position if (xpos != NULL) *xpos = window->cursorPosX; @@ -547,7 +543,6 @@ GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun) return; } - // Set callback function _glfwLibrary.mousePosCallback = cbfun; // Call the callback function to let the application know the current @@ -574,7 +569,6 @@ GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun) return; } - // Set callback function _glfwLibrary.scrollCallback = cbfun; } diff --git a/src/window.c b/src/window.c index 433275b1..f8939e37 100644 --- a/src/window.c +++ b/src/window.c @@ -655,7 +655,6 @@ GLFWAPI void glfwRestoreWindow(GLFWwindow handle) if (!window->iconified) return; - // Restore iconified window _glfwPlatformRestoreWindow(window); if (window->mode == GLFW_FULLSCREEN) From 7302f761d95c3170d4a62d7b7c0ce56bfb701f65 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 15 Feb 2012 00:33:01 +0100 Subject: [PATCH 033/226] Cleaned up bundle resource directory logic, clarified comment. --- readme.html | 1 + src/cocoa_init.m | 42 ++++++++++++++++++++++++------------------ src/cocoa_platform.h | 2 +- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/readme.html b/readme.html index 19e4285d..36c5add2 100644 --- a/readme.html +++ b/readme.html @@ -313,6 +313,7 @@ version of GLFW.

  • [Cocoa] Replaced NSDate time source with mach_absolute_time
  • [Cocoa] Bugfix: The loop condition for saving video modes used the wrong index variable
  • [Cocoa] Bugfix: The OpenGL framework was not retrieved, making glfwGetProcAddress crash
  • +
  • [Cocoa] Bugfix: glfwInit changed the current directory for unbundled executables
  • [X11] Added support for the GLX_EXT_swap_control extension as an alternative to GLX_SGI_swap_control
  • [X11] Added the POSIX CLOCK_MONOTONIC time source as the preferred method
  • [X11] Added dependency on libm, where present
  • diff --git a/src/cocoa_init.m b/src/cocoa_init.m index 2c747515..c8d5aed7 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -72,6 +72,18 @@ NSString* GLFWNameKeys[] = }; +//======================================================================== +// Change to our application bundle's resources directory, if present +//======================================================================== +static void changeToResourcesDirectory(void) +{ + char* resourcePath = [[[NSBundle mainBundle] resourcePath] UTF8String]; + + if (access(resourcePath, R_OK) == 0) + chdir(resourcePath); +} + + //======================================================================== // Try to figure out what the calling application is called //======================================================================== @@ -87,24 +99,18 @@ static NSString* findAppName(void) [name isKindOfClass:[NSString class]] && ![@"" isEqualToString:name]) { + _glfwLibrary.NS.bundled = GL_TRUE; return name; } } // If we get here, we're unbundled - if (!_glfwLibrary.NS.unbundled) - { - // Could do this only if we discover we're unbundled, but it should - // do no harm... - ProcessSerialNumber psn = { 0, kCurrentProcess }; - TransformProcessType(&psn, kProcessTransformToForegroundApplication); + ProcessSerialNumber psn = { 0, kCurrentProcess }; + TransformProcessType(&psn, kProcessTransformToForegroundApplication); - // Having the app in front of the terminal window is also generally - // handy. There is an NSApplication API to do this, but... - SetFrontProcess(&psn); - - _glfwLibrary.NS.unbundled = GL_TRUE; - } + // Having the app in front of the terminal window is also generally + // handy. There is an NSApplication API to do this, but... + SetFrontProcess(&psn); char** progname = _NSGetProgname(); if (progname && *progname) @@ -210,16 +216,16 @@ int _glfwPlatformInit(void) return GL_FALSE; } - NSString* resourcePath = [[NSBundle mainBundle] resourcePath]; - - if (access([resourcePath cStringUsingEncoding:NSUTF8StringEncoding], R_OK) == 0) - chdir([resourcePath cStringUsingEncoding:NSUTF8StringEncoding]); - - // Setting up menu bar must go exactly here else weirdness ensues + // Setting up the menu bar must go between sharedApplication + // above and finishLaunching below, in order to properly emulate the + // behavior of NSApplicationMain setUpMenuBar(); [NSApp finishLaunching]; + if (_glfwLibrary.NS.bundled) + changeToResourcesDirectory(); + _glfwPlatformSetTime(0.0); _glfwLibrary.NS.desktopMode = diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index 93492dbb..582b338d 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -91,7 +91,7 @@ typedef struct _GLFWlibraryNS // dlopen handle for dynamically loading OpenGL extension entry points void* OpenGLFramework; - GLboolean unbundled; + GLboolean bundled; id desktopMode; id delegate; id autoreleasePool; From 65f55d03b1f9ae9d0ae1682d0631d5bd932fac8e Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 15 Feb 2012 01:11:16 +0100 Subject: [PATCH 034/226] Removed invalid timer set. --- src/cocoa_init.m | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/cocoa_init.m b/src/cocoa_init.m index c8d5aed7..41362044 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -226,8 +226,6 @@ int _glfwPlatformInit(void) if (_glfwLibrary.NS.bundled) changeToResourcesDirectory(); - _glfwPlatformSetTime(0.0); - _glfwLibrary.NS.desktopMode = (NSDictionary*) CGDisplayCurrentMode(CGMainDisplayID()); From e7f7c19de35bf175263aaab92d67864285ca4633 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 15 Feb 2012 01:20:27 +0100 Subject: [PATCH 035/226] Made C-only modules C. --- src/CMakeLists.txt | 4 ++-- src/{cocoa_gamma.m => cocoa_gamma.c} | 2 ++ src/{cocoa_time.m => cocoa_time.c} | 0 3 files changed, 4 insertions(+), 2 deletions(-) rename src/{cocoa_gamma.m => cocoa_gamma.c} (98%) rename src/{cocoa_time.m => cocoa_time.c} (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 31cd9fd9..b5569c40 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,9 +19,9 @@ set(common_SOURCES error.c fullscreen.c gamma.c init.c input.c joystick.c opengl.c time.c window.c) if(_GLFW_COCOA_NSGL) - set(libglfw_SOURCES ${common_SOURCES} cocoa_fullscreen.m cocoa_gamma.m + set(libglfw_SOURCES ${common_SOURCES} cocoa_fullscreen.m cocoa_gamma.c cocoa_init.m cocoa_input.m cocoa_joystick.m - cocoa_opengl.m cocoa_time.m cocoa_window.m) + cocoa_opengl.m cocoa_time.c cocoa_window.m) # For some reason, CMake doesn't know about .m set_source_files_properties(${libglfw_SOURCES} PROPERTIES LANGUAGE C) diff --git a/src/cocoa_gamma.m b/src/cocoa_gamma.c similarity index 98% rename from src/cocoa_gamma.m rename to src/cocoa_gamma.c index eb291082..53c47a89 100644 --- a/src/cocoa_gamma.m +++ b/src/cocoa_gamma.c @@ -32,6 +32,8 @@ #include #include +#include + //************************************************************************ //**** GLFW internal functions **** diff --git a/src/cocoa_time.m b/src/cocoa_time.c similarity index 100% rename from src/cocoa_time.m rename to src/cocoa_time.c From 4a9545317ee5a8ffb07f48d5b36a0308fd40391f Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 15 Feb 2012 01:44:55 +0100 Subject: [PATCH 036/226] Postponed AppKit init to first window creation. --- readme.html | 1 + src/cocoa_init.m | 175 +++++--------------------------------------- src/cocoa_window.m | 176 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 194 insertions(+), 158 deletions(-) diff --git a/readme.html b/readme.html index 36c5add2..5ab86c64 100644 --- a/readme.html +++ b/readme.html @@ -310,6 +310,7 @@ version of GLFW.

  • 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
  • [Cocoa] Added support for joysticks
  • +
  • [Cocoa] Postponed menu creation to first window creation
  • [Cocoa] Replaced NSDate time source with mach_absolute_time
  • [Cocoa] Bugfix: The loop condition for saving video modes used the wrong index variable
  • [Cocoa] Bugfix: The OpenGL framework was not retrieved, making glfwGetProcAddress crash
  • diff --git a/src/cocoa_init.m b/src/cocoa_init.m index 41362044..45088a4e 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -27,168 +27,39 @@ // //======================================================================== -// Needed for _NSGetProgname -#include - #include "internal.h" -//======================================================================== -// GLFW application class -//======================================================================== - -@interface GLFWApplication : NSApplication -@end - -@implementation GLFWApplication - -// From http://cocoadev.com/index.pl?GameKeyboardHandlingAlmost -// This works around an AppKit bug, where key up events while holding -// down the command key don't get sent to the key window. -- (void)sendEvent:(NSEvent *)event -{ - if ([event type] == NSKeyUp && ([event modifierFlags] & NSCommandKeyMask)) - [[self keyWindow] sendEvent:event]; - else - [super sendEvent:event]; -} - -@end - - -// Prior to Snow Leopard, we need to use this oddly-named semi-private API -// to get the application menu working properly. Need to be careful in -// case it goes away in a future OS update. -@interface NSApplication (NSAppleMenu) -- (void)setAppleMenu:(NSMenu*)m; -@end - -// Keys to search for as potential application names -NSString* GLFWNameKeys[] = -{ - @"CFBundleDisplayName", - @"CFBundleName", - @"CFBundleExecutable", -}; - - //======================================================================== // Change to our application bundle's resources directory, if present //======================================================================== static void changeToResourcesDirectory(void) { - char* resourcePath = [[[NSBundle mainBundle] resourcePath] UTF8String]; + CFBundleRef bundle = CFBundleGetMainBundle(); + if (!bundle) + return; - if (access(resourcePath, R_OK) == 0) - chdir(resourcePath); -} + CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(bundle); + char resourcesPath[MAXPATHLEN]; + CFStringRef name = CFURLCopyLastPathComponent(resourcesURL); + if (CFStringCompare(CFSTR("Resources"), name, 0) != kCFCompareEqualTo) + return; -//======================================================================== -// Try to figure out what the calling application is called -//======================================================================== -static NSString* findAppName(void) -{ - unsigned int i; - NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary]; + CFRelease(name); - for (i = 0; i < sizeof(GLFWNameKeys) / sizeof(GLFWNameKeys[0]); i++) + if (!CFURLGetFileSystemRepresentation(resourcesURL, + TRUE, + (UInt8*) resourcesPath, + MAXPATHLEN)); { - id name = [infoDictionary objectForKey:GLFWNameKeys[i]]; - if (name && - [name isKindOfClass:[NSString class]] && - ![@"" isEqualToString:name]) - { - _glfwLibrary.NS.bundled = GL_TRUE; - return name; - } + CFRelease(resourcesURL); + return; } - // If we get here, we're unbundled - ProcessSerialNumber psn = { 0, kCurrentProcess }; - TransformProcessType(&psn, kProcessTransformToForegroundApplication); + CFRelease(resourcesURL); - // Having the app in front of the terminal window is also generally - // handy. There is an NSApplication API to do this, but... - SetFrontProcess(&psn); - - char** progname = _NSGetProgname(); - if (progname && *progname) - { - // TODO: UTF-8? - return [NSString stringWithUTF8String:*progname]; - } - - // Really shouldn't get here - return @"GLFW Application"; -} - -//======================================================================== -// Set up the menu bar (manually) -// This is nasty, nasty stuff -- calls to undocumented semi-private APIs that -// could go away at any moment, lots of stuff that really should be -// localize(d|able), etc. Loading a nib would save us this horror, but that -// doesn't seem like a good thing to require of GLFW's clients. -//======================================================================== -static void setUpMenuBar(void) -{ - NSString* appName = findAppName(); - - NSMenu* bar = [[NSMenu alloc] init]; - [NSApp setMainMenu:bar]; - - NSMenuItem* appMenuItem = - [bar addItemWithTitle:@"" action:NULL keyEquivalent:@""]; - NSMenu* appMenu = [[NSMenu alloc] init]; - [appMenuItem setSubmenu:appMenu]; - - [appMenu addItemWithTitle:[NSString stringWithFormat:@"About %@", appName] - action:@selector(orderFrontStandardAboutPanel:) - keyEquivalent:@""]; - [appMenu addItem:[NSMenuItem separatorItem]]; - NSMenu* servicesMenu = [[NSMenu alloc] init]; - [NSApp setServicesMenu:servicesMenu]; - [[appMenu addItemWithTitle:@"Services" - action:NULL - keyEquivalent:@""] setSubmenu:servicesMenu]; - [appMenu addItem:[NSMenuItem separatorItem]]; - [appMenu addItemWithTitle:[NSString stringWithFormat:@"Hide %@", appName] - action:@selector(hide:) - keyEquivalent:@"h"]; - [[appMenu addItemWithTitle:@"Hide Others" - action:@selector(hideOtherApplications:) - keyEquivalent:@"h"] - setKeyEquivalentModifierMask:NSAlternateKeyMask | NSCommandKeyMask]; - [appMenu addItemWithTitle:@"Show All" - action:@selector(unhideAllApplications:) - keyEquivalent:@""]; - [appMenu addItem:[NSMenuItem separatorItem]]; - [appMenu addItemWithTitle:[NSString stringWithFormat:@"Quit %@", appName] - action:@selector(terminate:) - keyEquivalent:@"q"]; - - NSMenuItem* windowMenuItem = - [bar addItemWithTitle:@"" action:NULL keyEquivalent:@""]; - NSMenu* windowMenu = [[NSMenu alloc] initWithTitle:@"Window"]; - [NSApp setWindowsMenu:windowMenu]; - [windowMenuItem setSubmenu:windowMenu]; - - [windowMenu addItemWithTitle:@"Miniaturize" - action:@selector(performMiniaturize:) - keyEquivalent:@"m"]; - [windowMenu addItemWithTitle:@"Zoom" - action:@selector(performZoom:) - keyEquivalent:@""]; - [windowMenu addItem:[NSMenuItem separatorItem]]; - [windowMenu addItemWithTitle:@"Bring All to Front" - action:@selector(arrangeInFront:) - keyEquivalent:@""]; - - // At least guard the call to private API to avoid an exception if it - // goes away. Hopefully that means the worst we'll break in future is to - // look ugly... - if ([NSApp respondsToSelector:@selector(setAppleMenu:)]) - [NSApp setAppleMenu:appMenu]; + chdir(resourcesPath); } @@ -202,11 +73,6 @@ static void setUpMenuBar(void) int _glfwPlatformInit(void) { - _glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init]; - - // Implicitly create shared NSApplication instance - [GLFWApplication sharedApplication]; - _glfwLibrary.NS.OpenGLFramework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl")); if (_glfwLibrary.NS.OpenGLFramework == NULL) @@ -216,13 +82,6 @@ int _glfwPlatformInit(void) return GL_FALSE; } - // Setting up the menu bar must go between sharedApplication - // above and finishLaunching below, in order to properly emulate the - // behavior of NSApplicationMain - setUpMenuBar(); - - [NSApp finishLaunching]; - if (_glfwLibrary.NS.bundled) changeToResourcesDirectory(); diff --git a/src/cocoa_window.m b/src/cocoa_window.m index b5dfb436..6bfd0971 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -29,6 +29,9 @@ #include "internal.h" +// Needed for _NSGetProgname +#include + //======================================================================== // Delegate for window related notifications @@ -443,6 +446,176 @@ static int convertMacKeyCode(unsigned int macKeyCode) @end +//======================================================================== +// GLFW application class +//======================================================================== + +@interface GLFWApplication : NSApplication +@end + +@implementation GLFWApplication + +// From http://cocoadev.com/index.pl?GameKeyboardHandlingAlmost +// This works around an AppKit bug, where key up events while holding +// down the command key don't get sent to the key window. +- (void)sendEvent:(NSEvent *)event +{ + if ([event type] == NSKeyUp && ([event modifierFlags] & NSCommandKeyMask)) + [[self keyWindow] sendEvent:event]; + else + [super sendEvent:event]; +} + +@end + + +// Prior to Snow Leopard, we need to use this oddly-named semi-private API +// to get the application menu working properly. Need to be careful in +// case it goes away in a future OS update. +@interface NSApplication (NSAppleMenu) +- (void)setAppleMenu:(NSMenu*)m; +@end + +//======================================================================== +// Try to figure out what the calling application is called +//======================================================================== + +static NSString* findAppName(void) +{ + unsigned int i; + NSDictionary* infoDictionary = [[NSBundle mainBundle] infoDictionary]; + + // Keys to search for as potential application names + NSString* GLFWNameKeys[] = + { + @"CFBundleDisplayName", + @"CFBundleName", + @"CFBundleExecutable", + }; + + for (i = 0; i < sizeof(GLFWNameKeys) / sizeof(GLFWNameKeys[0]); i++) + { + id name = [infoDictionary objectForKey:GLFWNameKeys[i]]; + if (name && + [name isKindOfClass:[NSString class]] && + ![@"" isEqualToString:name]) + { + _glfwLibrary.NS.bundled = GL_TRUE; + return name; + } + } + + // If we get here, we're unbundled + ProcessSerialNumber psn = { 0, kCurrentProcess }; + TransformProcessType(&psn, kProcessTransformToForegroundApplication); + + // Having the app in front of the terminal window is also generally + // handy. There is an NSApplication API to do this, but... + SetFrontProcess(&psn); + + char** progname = _NSGetProgname(); + if (progname && *progname) + { + // TODO: UTF-8? + return [NSString stringWithUTF8String:*progname]; + } + + // Really shouldn't get here + return @"GLFW Application"; +} + +//======================================================================== +// Set up the menu bar (manually) +// This is nasty, nasty stuff -- calls to undocumented semi-private APIs that +// could go away at any moment, lots of stuff that really should be +// localize(d|able), etc. Loading a nib would save us this horror, but that +// doesn't seem like a good thing to require of GLFW's clients. +//======================================================================== +static void setUpMenuBar(void) +{ + NSString* appName = findAppName(); + + NSMenu* bar = [[NSMenu alloc] init]; + [NSApp setMainMenu:bar]; + + NSMenuItem* appMenuItem = + [bar addItemWithTitle:@"" action:NULL keyEquivalent:@""]; + NSMenu* appMenu = [[NSMenu alloc] init]; + [appMenuItem setSubmenu:appMenu]; + + [appMenu addItemWithTitle:[NSString stringWithFormat:@"About %@", appName] + action:@selector(orderFrontStandardAboutPanel:) + keyEquivalent:@""]; + [appMenu addItem:[NSMenuItem separatorItem]]; + NSMenu* servicesMenu = [[NSMenu alloc] init]; + [NSApp setServicesMenu:servicesMenu]; + [[appMenu addItemWithTitle:@"Services" + action:NULL + keyEquivalent:@""] setSubmenu:servicesMenu]; + [appMenu addItem:[NSMenuItem separatorItem]]; + [appMenu addItemWithTitle:[NSString stringWithFormat:@"Hide %@", appName] + action:@selector(hide:) + keyEquivalent:@"h"]; + [[appMenu addItemWithTitle:@"Hide Others" + action:@selector(hideOtherApplications:) + keyEquivalent:@"h"] + setKeyEquivalentModifierMask:NSAlternateKeyMask | NSCommandKeyMask]; + [appMenu addItemWithTitle:@"Show All" + action:@selector(unhideAllApplications:) + keyEquivalent:@""]; + [appMenu addItem:[NSMenuItem separatorItem]]; + [appMenu addItemWithTitle:[NSString stringWithFormat:@"Quit %@", appName] + action:@selector(terminate:) + keyEquivalent:@"q"]; + + NSMenuItem* windowMenuItem = + [bar addItemWithTitle:@"" action:NULL keyEquivalent:@""]; + NSMenu* windowMenu = [[NSMenu alloc] initWithTitle:@"Window"]; + [NSApp setWindowsMenu:windowMenu]; + [windowMenuItem setSubmenu:windowMenu]; + + [windowMenu addItemWithTitle:@"Miniaturize" + action:@selector(performMiniaturize:) + keyEquivalent:@"m"]; + [windowMenu addItemWithTitle:@"Zoom" + action:@selector(performZoom:) + keyEquivalent:@""]; + [windowMenu addItem:[NSMenuItem separatorItem]]; + [windowMenu addItemWithTitle:@"Bring All to Front" + action:@selector(arrangeInFront:) + keyEquivalent:@""]; + + // At least guard the call to private API to avoid an exception if it + // goes away. Hopefully that means the worst we'll break in future is to + // look ugly... + if ([NSApp respondsToSelector:@selector(setAppleMenu:)]) + [NSApp setAppleMenu:appMenu]; +} + + +//======================================================================== +// Initialize the Cocoa Application Kit +//======================================================================== +static GLboolean initializeCocoa(void) +{ + if (NSApp) + return GL_TRUE; + + _glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init]; + + // Implicitly create shared NSApplication instance + [GLFWApplication sharedApplication]; + + // Setting up the menu bar must go between sharedApplication + // above and finishLaunching below, in order to properly emulate the + // behavior of NSApplicationMain + setUpMenuBar(); + + [NSApp finishLaunching]; + + return GL_TRUE; +} + //======================================================================== // Create the Cocoa window //======================================================================== @@ -641,6 +814,9 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWfbconfig* fbconfig) { + if (!initializeCocoa()) + return GL_FALSE; + // We can only have one application delegate, but we only allocate it the // first time we create a window to keep all window code in this file if (_glfwLibrary.NS.delegate == nil) From 84ea69358fb3f54970dd7d3f31c30528b850709e Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 15 Feb 2012 01:57:43 +0100 Subject: [PATCH 037/226] Removed unused variable, fixed chdir regression. --- src/cocoa_init.m | 20 ++++++++++++-------- src/cocoa_platform.h | 1 - src/cocoa_window.m | 1 - 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/cocoa_init.m b/src/cocoa_init.m index 45088a4e..16ea6e68 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -35,23 +35,28 @@ //======================================================================== static void changeToResourcesDirectory(void) { + char resourcesPath[MAXPATHLEN]; + CFBundleRef bundle = CFBundleGetMainBundle(); if (!bundle) return; CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(bundle); - char resourcesPath[MAXPATHLEN]; - CFStringRef name = CFURLCopyLastPathComponent(resourcesURL); - if (CFStringCompare(CFSTR("Resources"), name, 0) != kCFCompareEqualTo) + CFStringRef last = CFURLCopyLastPathComponent(resourcesURL); + if (CFStringCompare(CFSTR("Resources"), last, 0) != kCFCompareEqualTo) + { + CFRelease(last); + CFRelease(resourcesURL); return; + } - CFRelease(name); + CFRelease(last); if (!CFURLGetFileSystemRepresentation(resourcesURL, - TRUE, + true, (UInt8*) resourcesPath, - MAXPATHLEN)); + MAXPATHLEN)) { CFRelease(resourcesURL); return; @@ -82,8 +87,7 @@ int _glfwPlatformInit(void) return GL_FALSE; } - if (_glfwLibrary.NS.bundled) - changeToResourcesDirectory(); + changeToResourcesDirectory(); _glfwLibrary.NS.desktopMode = (NSDictionary*) CGDisplayCurrentMode(CGMainDisplayID()); diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index 582b338d..1a90af01 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -91,7 +91,6 @@ typedef struct _GLFWlibraryNS // dlopen handle for dynamically loading OpenGL extension entry points void* OpenGLFramework; - GLboolean bundled; id desktopMode; id delegate; id autoreleasePool; diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 6bfd0971..221dcc5e 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -500,7 +500,6 @@ static NSString* findAppName(void) [name isKindOfClass:[NSString class]] && ![@"" isEqualToString:name]) { - _glfwLibrary.NS.bundled = GL_TRUE; return name; } } From d608eb00861306d10c57a6483d1e572452824ed4 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 19 Feb 2012 05:28:15 +0100 Subject: [PATCH 038/226] Replaced hand rolled X extension detection with built-in version. --- CMake/CheckX11Extensions.cmake | 88 ---------------------------------- CMakeLists.txt | 25 +++++----- 2 files changed, 13 insertions(+), 100 deletions(-) delete mode 100644 CMake/CheckX11Extensions.cmake diff --git a/CMake/CheckX11Extensions.cmake b/CMake/CheckX11Extensions.cmake deleted file mode 100644 index a6f9b18b..00000000 --- a/CMake/CheckX11Extensions.cmake +++ /dev/null @@ -1,88 +0,0 @@ -# - Check if X11 RandR extension is available -# Check if the X11 extension RandR is available. -# This macro defines : -# - X11_RANDR_FOUND, If set to NO RandR is not available. -# - X11_RANDR_INCLUDE_DIR, includes directory containing the RandR header. -# - X11_RANDR_LIBRARIES, libraries to link in the library to use RandR. -# -# Created by Olivier Delannoy. -macro(CHECK_X11_XRANDR) - message(STATUS "Checking for X11 extension XRandR") - set(X11_XRANDR_FOUND "NO") - find_path(X11_XRANDR_INCLUDE_DIR "X11/extensions/Xrandr.h" - PATHS - /usr/local/include - /usr/local/X11/include - /usr/local/X11R6/include - /usr/include - /usr/X11/include - /usr/X11R6/include) - - find_library(X11_XRANDR_LIBRARIES NAMES Xrandr - PATHS - /usr/local/lib - /usr/local/X11/lib - /usr/local/X11R6/lib - /usr/lib - /usr/X11/lib - /usr/X11R6/lib) - # Create check if file compiles with randr - - if (X11_XRANDR_LIBRARIES AND X11_XRANDR_INCLUDE_DIR) - set(X11_XRANDR_FOUND "YES") - endif (X11_XRANDR_LIBRARIES AND X11_XRANDR_INCLUDE_DIR) - - if (X11_XRANDR_FOUND) - message(STATUS "Checking for X11 extension XRandR -- found") - else (X11_XRANDR_FOUND) - message(STATUS "Checking for X11 extension XRandR -- not found") - endif (X11_XRANDR_FOUND) - - mark_as_advanced(X11_XRANDR_LIBRARIES X11_XRANDR_INCLUDE_DIR) -endmacro(CHECK_X11_XRANDR) - - -# - Check if X11 VidMod extension is available -# Check if the X11 extension VidMod is available. -# This macro defines : -# - X11_VIDMOD_FOUND, If set to NO VidMod is not available. -# - X11_VIDMOD_INCLUDE_DIR, includes directory containing the headers. -# - X11_VIDMOD_LIBRARIES, libraries to link in the libraries. -# -# Created by Olivier Delannoy. -macro(CHECK_X11_XF86VIDMODE) - message(STATUS "Checking for X11 extension xf86vidmode") - set(X11_XF86VIDMODE_FOUND "NO") - find_path(X11_XF86VIDMODE_INCLUDE_DIR "X11/extensions/xf86vmode.h" - PATHS - /usr/local/include - /usr/local/X11/include - /usr/local/X11R6/include - /usr/include - /usr/X11/include - /usr/X11R6/include) - - find_library(X11_XF86VIDMODE_LIBRARIES NAMES Xxf86vm PATHS - /usr/local/lib - /usr/local/X11/lib - /usr/local/X11R6/lib - /usr/lib - /usr/X11/lib - /usr/X11R6/lib) - # Add a test case here - if (X11_XF86VIDMODE_LIBRARIES AND X11_XF86VIDMODE_INCLUDE_DIR) - set(X11_XF86VIDMODE_FOUND "YES") - endif (X11_XF86VIDMODE_LIBRARIES AND X11_XF86VIDMODE_INCLUDE_DIR) - - if (X11_XF86VIDMODE_FOUND) - message(STATUS "Checking for X11 extension xf86vidmode -- found") - else (X11_XF86VIDMODE_FOUND) - message(STATUS "Checking for X11 extension xf86vidmode -- not found") - endif(X11_XF86VIDMODE_FOUND) - - mark_as_advanced( - X11_XF86VIDMODE_LIBRARIES - X11_XF86VIDMODE_INCLUDE_DIR - ) - -endmacro(CHECK_X11_XF86VIDMODE) diff --git a/CMakeLists.txt b/CMakeLists.txt index 57967600..5e6554c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,8 @@ if (UNIX AND NOT APPLE) # Define the platform identifier set(_GLFW_X11_GLX 1) + find_package(X11 REQUIRED) + # Set up library and include paths list(APPEND GLFW_INCLUDE_DIR ${X11_X11_INCLUDE_PATH} ${OPENGL_INCLUDE_DIR}) list(APPEND GLFW_LIBRARIES ${X11_X11_LIB} ${OPENGL_gl_LIBRARY}) @@ -55,27 +57,26 @@ if (UNIX AND NOT APPLE) include(CheckFunctionExists) include(CheckSymbolExists) - include(${GLFW_SOURCE_DIR}/CMake/CheckX11Extensions.cmake) set(CMAKE_REQUIRED_LIBRARIES ${GLFW_LIBRARIES}) # Check for XRandR (modern resolution switching extension) - check_x11_xrandr() - if (X11_XRANDR_FOUND) + if (X11_Xrandr_FOUND) set(_GLFW_HAS_XRANDR 1) - list(APPEND GLFW_INCLUDE_DIR ${X11_XRANDR_INCLUDE_DIR}) - list(APPEND GLFW_LIBRARIES ${X11_XRANDR_LIBRARIES}) - endif(X11_XRANDR_FOUND) + list(APPEND GLFW_INCLUDE_DIR ${X11_Xrandr_INCLUDE_PATH}) + list(APPEND GLFW_LIBRARIES ${X11_Xrandr_LIB}) + endif() # Check for Xf86VidMode (fallback legacy resolution switching extension) - check_x11_xf86vidmode() - if (X11_XF86VIDMODE_FOUND) + if (X11_xf86vmode_FOUND) set(_GLFW_HAS_XF86VIDMODE 1) - list(APPEND GLFW_INCLUDE_DIR ${X11_XF86VIDMODE_INCLUDE_DIR}) - list(APPEND GLFW_LIBRARIES ${X11_XF86VIDMODE_LIBRARIES}) - endif(X11_XF86VIDMODE_FOUND) + list(APPEND GLFW_INCLUDE_DIR ${X11_xf86vmode_INCLUDE_PATH}) + endif() # Check for Xkb (X keyboard extension) - check_function_exists(XkbQueryExtension _GLFW_HAS_XKB) + if (X11_Xkb_FOUND) + set(_GLFW_HAS_XKB 1) + list(APPEND GLFW_INCLUDE_DIR ${X11_Xkb_INCLUDE_PATH}) + endif() # Check for glXGetProcAddress check_function_exists(glXGetProcAddress _GLFW_HAS_GLXGETPROCADDRESS) From f332e0009d46f71ee23e91eafc50821dcc2a0acd Mon Sep 17 00:00:00 2001 From: Tai Chi Minh Ralph Eastwood Date: Sun, 19 Feb 2012 05:39:21 +0000 Subject: [PATCH 039/226] Add mising clipboard test program. --- tests/clipboard.c | 147 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 tests/clipboard.c diff --git a/tests/clipboard.c b/tests/clipboard.c new file mode 100644 index 00000000..cdbba6d2 --- /dev/null +++ b/tests/clipboard.c @@ -0,0 +1,147 @@ +//======================================================================== +// Gamma correction test program +// Copyright (c) Camilla Berglund +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would +// be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not +// be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. +// +//======================================================================== +// +// This program is used to test the clipboard functionality. +// +//======================================================================== + +#include + +#include +#include + +#include "getopt.h" + +static void usage(void) +{ + printf("Usage: clipboard [-h]\n"); +} + +static void key_callback(GLFWwindow window, int key, int action) +{ + static int control = GL_FALSE; + if (key == GLFW_KEY_LEFT_CONTROL) + { + control = (action == GLFW_PRESS); + return; + } + + if (action != GLFW_PRESS) + return; + + switch (key) + { + case GLFW_KEY_ESCAPE: + glfwCloseWindow(window); + break; + case GLFW_KEY_V: + if (control) + { + char buffer[4096]; + size_t size; + printf("Paste test.\n"); + size = glfwGetClipboardData(buffer, sizeof(buffer), GLFW_CLIPBOARD_FORMAT_STRING); + if (size >= sizeof(buffer)) + { + printf("Buffer wasn't big enough to hold clipboard data.\n"); + } + printf("[%ld]: %s\n", size, buffer); + } + break; + case GLFW_KEY_C: + if (control) + { + glfwSetClipboardData("Hello GLFW World!", sizeof("Hello GLFW World!"), + GLFW_CLIPBOARD_FORMAT_STRING); + printf("Setting clipboard to: %s\n", "Hello GLFW World!"); + } + break; + } +} + +static void size_callback(GLFWwindow window, int width, int height) +{ + glViewport(0, 0, width, height); +} + +int main(int argc, char** argv) +{ + int ch; + GLFWwindow window; + + while ((ch = getopt(argc, argv, "h")) != -1) + { + switch (ch) + { + case 'h': + usage(); + exit(EXIT_SUCCESS); + + default: + usage(); + exit(EXIT_FAILURE); + } + } + + if (!glfwInit()) + { + fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); + exit(EXIT_FAILURE); + } + + window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Clipboard Test", NULL); + if (!window) + { + glfwTerminate(); + + fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError())); + exit(EXIT_FAILURE); + } + + glfwSwapInterval(1); + glfwSetKeyCallback(key_callback); + glfwSetWindowSizeCallback(size_callback); + + glMatrixMode(GL_PROJECTION); + glOrtho(-1.f, 1.f, -1.f, 1.f, -1.f, 1.f); + glMatrixMode(GL_MODELVIEW); + + glClearColor(0.5f, 0.5f, 0.5f, 0); + + while (glfwIsWindow(window)) + { + glClear(GL_COLOR_BUFFER_BIT); + + glColor3f(0.8f, 0.2f, 0.4f); + glRectf(-0.5f, -0.5f, 0.5f, 0.5f); + + glfwSwapBuffers(); + glfwPollEvents(); + } + + glfwTerminate(); + exit(EXIT_SUCCESS); +} + From a3430c2dec9991cc9ed2aef2019dd7ce95f4591e Mon Sep 17 00:00:00 2001 From: Tai Chi Minh Ralph Eastwood Date: Sun, 19 Feb 2012 05:40:11 +0000 Subject: [PATCH 040/226] No idea why this file changed... or should it be changed at all. --- src/libglfw.pc.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libglfw.pc.cmake b/src/libglfw.pc.cmake index 47cfb4f5..7538b885 100644 --- a/src/libglfw.pc.cmake +++ b/src/libglfw.pc.cmake @@ -9,4 +9,5 @@ Version: 3.0.0 URL: http://www.glfw.org/ Requires.private: gl x11 @GLFW_PKGLIBS@ Libs: -L${libdir} -lglfw +Libs.private: @GLFW_LIBRARIES@ Cflags: -I${includedir} From 8b7fc5d6013bf99af5c538dd73d24a38d835cd32 Mon Sep 17 00:00:00 2001 From: Tai Chi Minh Ralph Eastwood Date: Sun, 19 Feb 2012 06:30:45 +0000 Subject: [PATCH 041/226] Trailing whitespace. --- src/libglfw.pc.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libglfw.pc.cmake b/src/libglfw.pc.cmake index 7538b885..1a712d9d 100644 --- a/src/libglfw.pc.cmake +++ b/src/libglfw.pc.cmake @@ -8,6 +8,6 @@ Description: A portable library for OpenGL, window and input Version: 3.0.0 URL: http://www.glfw.org/ Requires.private: gl x11 @GLFW_PKGLIBS@ -Libs: -L${libdir} -lglfw +Libs: -L${libdir} -lglfw Libs.private: @GLFW_LIBRARIES@ Cflags: -I${includedir} From 7e0ca6705b0a687a15acde6a90b908f5b6f138d6 Mon Sep 17 00:00:00 2001 From: Hanmac Date: Tue, 31 Jan 2012 10:00:52 +0100 Subject: [PATCH 042/226] Added use of XkbKeycodeToKeysym when Xkb is available. --- src/x11_init.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/x11_init.c b/src/x11_init.c index 4d3c0f74..3ed9ab13 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -79,7 +79,11 @@ static int keyCodeToGLFWKeyCode(int keyCode) // Note: This way we always force "NumLock = ON", which is intentional // since the returned key code should correspond to a physical // location. +#if defined(_GLFW_HAS_XKB) + keySym = XkbKeycodeToKeysym(_glfwLibrary.X11.display, keyCode, 1, 0); +#else keySym = XKeycodeToKeysym(_glfwLibrary.X11.display, keyCode, 1); +#endif switch (keySym) { case XK_KP_0: return GLFW_KEY_KP_0; @@ -102,7 +106,12 @@ static int keyCodeToGLFWKeyCode(int keyCode) // Now try pimary keysym for function keys (non-printable keys). These // should not be layout dependent (i.e. US layout and international // layouts should give the same result). +#if defined(_GLFW_HAS_XKB) + keySym = XkbKeycodeToKeysym(_glfwLibrary.X11.display, keyCode, 0, 0); +#else keySym = XKeycodeToKeysym(_glfwLibrary.X11.display, keyCode, 0); +#endif + switch (keySym) { case XK_Escape: return GLFW_KEY_ESCAPE; From a202799f4577ef8ec5941709c9f4d05c08b19940 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 26 Feb 2012 03:24:42 +0100 Subject: [PATCH 043/226] Renamed AppKit init function. --- src/cocoa_window.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 221dcc5e..578d1c41 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -595,7 +595,7 @@ static void setUpMenuBar(void) //======================================================================== // Initialize the Cocoa Application Kit //======================================================================== -static GLboolean initializeCocoa(void) +static GLboolean initializeAppKit(void) { if (NSApp) return GL_TRUE; @@ -813,7 +813,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWfbconfig* fbconfig) { - if (!initializeCocoa()) + if (!initializeAppKit()) return GL_FALSE; // We can only have one application delegate, but we only allocate it the From f47f5d9f59623e9a46f095c0840413ac3cc631af Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 26 Feb 2012 18:41:33 +0100 Subject: [PATCH 044/226] Updated changelog. --- readme.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/readme.html b/readme.html index 5ab86c64..19c438f5 100644 --- a/readme.html +++ b/readme.html @@ -869,7 +869,8 @@ their skills. Special thanks go out to:

  • Tristam MacDonald, for his bug reports and feedback on the Cocoa port
  • -
  • Hans 'Hanmac' Mackowiak, for adding UTF-8 window title support on X11
  • +
  • Hans 'Hanmac' Mackowiak, for adding UTF-8 window title support on X11 and + a fix for the Xkb support
  • David Medlock, for doing the initial Lua port
  • From 98fbc07aa4d73e61b514f90f7678fa542799f0a6 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 27 Feb 2012 02:21:26 +0100 Subject: [PATCH 045/226] Fixed GLFW_WINDOW_NO_RESIZE state not being saved. --- readme.html | 2 ++ src/cocoa_window.m | 2 ++ src/win32_window.c | 1 + 3 files changed, 5 insertions(+) diff --git a/readme.html b/readme.html index 19c438f5..d23f982a 100644 --- a/readme.html +++ b/readme.html @@ -315,6 +315,7 @@ version of GLFW.

  • [Cocoa] Bugfix: The loop condition for saving video modes used the wrong index variable
  • [Cocoa] Bugfix: The OpenGL framework was not retrieved, making glfwGetProcAddress crash
  • [Cocoa] Bugfix: glfwInit changed the current directory for unbundled executables
  • +
  • [Cocoa] Bugfix: The GLFW_WINDOW_NO_RESIZE window parameter was always zero
  • [X11] Added support for the GLX_EXT_swap_control extension as an alternative to GLX_SGI_swap_control
  • [X11] Added the POSIX CLOCK_MONOTONIC time source as the preferred method
  • [X11] Added dependency on libm, where present
  • @@ -328,6 +329,7 @@ version of GLFW.

  • [Win32] Bugfix: Software rasterizer pixel formats were not discarded by the WGL_ARB_pixel_format code path
  • [Win32] Bugfix: The array for WGL context attributes was too small and could overflow
  • [Win32] Bugfix: Alt+F4 hot key was not translated into WM_CLOSE
  • +
  • [Win32] Bugfix: The GLFW_WINDOW_NO_RESIZE window parameter was always zero
  • v2.7

    diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 221dcc5e..bf3b0fbc 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -816,6 +816,8 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, if (!initializeCocoa()) return GL_FALSE; + window->resizable = wndconfig->resizable; + // We can only have one application delegate, but we only allocate it the // first time we create a window to keep all window code in this file if (_glfwLibrary.NS.delegate == nil) diff --git a/src/win32_window.c b/src/win32_window.c index 24788a33..0f3c67d0 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1441,6 +1441,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, GLboolean recreateContext = GL_FALSE; window->Win32.desiredRefreshRate = wndconfig->refreshRate; + window->resizable = wndconfig->resizable; if (!_glfwLibrary.Win32.classAtom) { From a82598ea24d08b82c9e28f3943a70e5bd7ae1f5f Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 29 Feb 2012 19:52:34 +0100 Subject: [PATCH 046/226] Disable dynamic loading for Win32 DLL. --- src/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b5569c40..79a5c314 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -47,9 +47,10 @@ set_target_properties(libglfwStatic libglfwShared PROPERTIES OUTPUT_NAME glfw) if(WIN32) + target_link_libraries(libglfwShared winmm) # The GLFW DLL needs a special compile-time macro and import library name set_target_properties(libglfwShared PROPERTIES - DEFINE_SYMBOL GLFW_BUILD_DLL + COMPILE_DEFINITIONS "GLFW_BUILD_DLL;_GLFW_NO_DLOAD_GDI32;_GLFW_NO_DLOAD_WINMM" PREFIX "" IMPORT_PREFIX "" IMPORT_SUFFIX "dll.lib") From cd7b9b1568a8145bb22393fed1be27223a6f0d3b Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 29 Feb 2012 20:15:39 +0100 Subject: [PATCH 047/226] CMake file formatting. --- CMakeLists.txt | 28 +++++++++++++--------------- examples/CMakeLists.txt | 10 +++++----- src/CMakeLists.txt | 20 ++++++++++---------- tests/CMakeLists.txt | 4 ++-- 4 files changed, 30 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e6554c5..a4454365 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ if (WIN32) # Set up library and include paths list(APPEND GLFW_INCLUDE_DIR ${OPENGL_INCLUDE_DIR}) list(APPEND GLFW_LIBRARIES ${OPENGL_gl_LIBRARY}) -endif (WIN32) +endif() #-------------------------------------------------------------------- # Set up GLFW for Xlib and GLX on Unix-like systems with X Windows @@ -47,12 +47,12 @@ if (UNIX AND NOT APPLE) find_library(MATH_LIBRARY m) if (MATH_LIBRARY) list(APPEND GLFW_LIBRARIES ${MATH_LIBRARY}) - endif(MATH_LIBRARY) + endif() find_library(RT_LIBRARY rt) if (RT_LIBRARY) list(APPEND GLFW_LIBRARIES ${RT_LIBRARY}) - endif(RT_LIBRARY) + endif() include(CheckFunctionExists) include(CheckSymbolExists) @@ -83,24 +83,22 @@ if (UNIX AND NOT APPLE) if (NOT _GLFW_HAS_GLXGETPROCADDRESS) check_function_exists(glXGetProcAddressARB _GLFW_HAS_GLXGETPROCADDRESSARB) - endif (NOT _GLFW_HAS_GLXGETPROCADDRESS) + endif() if (NOT _GLFW_HAS_GLXGETPROCADDRESS AND NOT _GLFW_HAS_GLXGETPROCADDRESSARB) check_function_exists(glXGetProcAddressEXT _GLFW_HAS_GLXGETPROCADDRESSEXT) - endif (NOT _GLFW_HAS_GLXGETPROCADDRESS AND NOT _GLFW_HAS_GLXGETPROCADDRESSARB) + endif() if (NOT _GLFW_HAS_GLXGETPROCADDRESS AND NOT _GLFW_HAS_GLXGETPROCADDRESSARB AND NOT _GLFW_HAS_GLXGETPROCADDRESSEXT) message(WARNING "No glXGetProcAddressXXX variant found") - endif (NOT _GLFW_HAS_GLXGETPROCADDRESS AND - NOT _GLFW_HAS_GLXGETPROCADDRESSARB AND - NOT _GLFW_HAS_GLXGETPROCADDRESSEXT) + endif() if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") set(_GLFW_USE_LINUX_JOYSTICKS 1) - endif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") -endif(UNIX AND NOT APPLE) + endif() +endif() #-------------------------------------------------------------------- # Set up GLFW for Cocoa and NSOpenGL on Mac OS X @@ -121,7 +119,7 @@ if (UNIX AND APPLE) set(CMAKE_C_FLAGS "-mmacosx-version-min=10.5") else(GLFW_BUILD_UNIVERSAL) message(STATUS "Building GLFW only for the native architecture") - endif(GLFW_BUILD_UNIVERSAL) + endif() # Set up library and include paths find_library(COCOA_FRAMEWORK Cocoa) @@ -131,7 +129,7 @@ if (UNIX AND APPLE) list(APPEND GLFW_LIBRARIES ${OPENGL_gl_LIBRARY}) list(APPEND GLFW_LIBRARIES ${IOKIT_FRAMEWORK}) list(APPEND GLFW_LIBRARIES ${CORE_FOUNDATION_FRAMEWORK}) -endif(UNIX AND APPLE) +endif() #-------------------------------------------------------------------- # Add subdirectories @@ -140,11 +138,11 @@ add_subdirectory(src) if (GLFW_BUILD_EXAMPLES) add_subdirectory(examples) -endif(GLFW_BUILD_EXAMPLES) +endif() if (GLFW_BUILD_TESTS) add_subdirectory(tests) -endif(GLFW_BUILD_TESTS) +endif() #-------------------------------------------------------------------- # Create shared configuration header @@ -175,7 +173,7 @@ configure_file("${GLFW_SOURCE_DIR}/docs/Doxyfile.in" # Uninstall operation # Don't generate this target if a higher-level project already has #-------------------------------------------------------------------- -if(NOT TARGET uninstall) +if (NOT TARGET uninstall) configure_file(${GLFW_SOURCE_DIR}/cmake_uninstall.cmake.in ${GLFW_BINARY_DIR}/cmake_uninstall.cmake IMMEDIATE @ONLY) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index d511b22d..37b7f754 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -7,14 +7,14 @@ include_directories(${GLFW_SOURCE_DIR}/include ${GLFW_SOURCE_DIR}/support ${OPENGL_INCLUDE_DIR}) -if(APPLE) +if (APPLE) # Set fancy names for bundles add_executable(Boing MACOSX_BUNDLE boing.c) add_executable(Gears MACOSX_BUNDLE gears.c) add_executable("Split View" MACOSX_BUNDLE splitview.c) add_executable(Triangle MACOSX_BUNDLE triangle.c) add_executable(Wave MACOSX_BUNDLE wave.c) -else(APPLE) +else() # Set boring names for executables add_executable(boing WIN32 boing.c) add_executable(gears WIN32 gears.c) @@ -22,13 +22,13 @@ else(APPLE) add_executable(splitview WIN32 splitview.c) add_executable(triangle WIN32 triangle.c) add_executable(wave WIN32 wave.c) -endif(APPLE) +endif() set(WINDOWS_BINARIES boing gears heightmap splitview triangle wave) -if(MSVC) +if (MSVC) # Tell MSVC to use main instead of WinMain for Windows subsystem executables set_target_properties(${WINDOWS_BINARIES} PROPERTIES LINK_FLAGS "/ENTRY:mainCRTStartup") -endif(MSVC) +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 79a5c314..bdc4d5fe 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,15 +1,15 @@ if(UNIX) - if(_GLFW_HAS_XRANDR) + if (_GLFW_HAS_XRANDR) set(GLFW_PKGLIBS "${GLFW_PKGLIBS} xrandr") - endif(_GLFW_HAS_XRANDR) - if(_GLFW_HAS_XF86VIDMODE) + endif() + if (_GLFW_HAS_XF86VIDMODE) set(GLFW_PKGLIBS "${GLFW_PKGLIBS} xxf86vm") - endif(_GLFW_HAS_XF86VIDMODE) + endif() configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libglfw.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc DESTINATION lib/pkgconfig) -endif(UNIX) +endif() include_directories(${GLFW_SOURCE_DIR}/src ${GLFW_BINARY_DIR}/src @@ -37,7 +37,7 @@ elseif(_GLFW_X11_GLX) x11_window.c) else() message(FATAL_ERROR "No supported platform was selected") -endif(_GLFW_COCOA_NSGL) +endif() add_library(libglfwStatic STATIC ${libglfw_SOURCES}) add_library(libglfwShared SHARED ${libglfw_SOURCES}) @@ -54,16 +54,16 @@ if(WIN32) PREFIX "" IMPORT_PREFIX "" IMPORT_SUFFIX "dll.lib") -endif(WIN32) +endif() if(APPLE) # Append -fno-common to the compile flags to work around a bug in the Apple GCC get_target_property(CFLAGS libglfwShared COMPILE_FLAGS) - if(NOT CFLAGS) + if (NOT CFLAGS) set(CFLAGS "") - endif(NOT CFLAGS) + endif() set_target_properties(libglfwShared PROPERTIES COMPILE_FLAGS "${CFLAGS} -fno-common") -endif(APPLE) +endif() install(TARGETS libglfwStatic libglfwShared DESTINATION lib) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d7ac0954..58631603 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -61,9 +61,9 @@ set(WINDOWS_BINARIES accuracy sharing tearing title windows) set(CONSOLE_BINARIES defaults events fsaa fsfocus gamma glfwinfo iconify joysticks listmodes peter reopen) -if(MSVC) +if (MSVC) # Tell MSVC to use main instead of WinMain for Windows subsystem executables set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES LINK_FLAGS "/ENTRY:mainCRTStartup") -endif(MSVC) +endif() From 537754aab84f7edbca100c7c70682f0331c05a20 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 29 Feb 2012 20:17:09 +0100 Subject: [PATCH 048/226] Require CMake 2.8. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a4454365..25f83279 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ project(GLFW C) -cmake_minimum_required(VERSION 2.4) +cmake_minimum_required(VERSION 2.8) cmake_policy(VERSION 2.4) set(GLFW_VERSION_MAJOR "3") From a27c444af41434eb270df8dd7a48954585aa4ec3 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 29 Feb 2012 20:19:05 +0100 Subject: [PATCH 049/226] Updated comment. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 25f83279..03870594 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -160,7 +160,7 @@ install(DIRECTORY include/GL DESTINATION include install(FILES COPYING.txt readme.html DESTINATION share/doc/glfw-${GLFW_VERSION_FULL}/) -# The respective port's CMakeLists.txt file installs the library +# The src directory's CMakeLists.txt file installs the library #-------------------------------------------------------------------- # -- Documentation generation From e7fb35a5d8075cd2d2cb28181213b75356d26769 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 1 Mar 2012 03:41:36 +0100 Subject: [PATCH 050/226] Removed legacy CMake policy. --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 03870594..f27cf7cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,6 @@ project(GLFW C) cmake_minimum_required(VERSION 2.8) -cmake_policy(VERSION 2.4) set(GLFW_VERSION_MAJOR "3") set(GLFW_VERSION_MINOR "0") From f49119107f6b214a179affc6aba798c2dca70eec Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 1 Mar 2012 03:45:06 +0100 Subject: [PATCH 051/226] Removed misplaced Win32 configuration macros. --- src/config.h.in | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/config.h.in b/src/config.h.in index f966356c..46a6e2aa 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -60,11 +60,6 @@ // Define this to 1 if the Linux joystick API is available #cmakedefine _GLFW_USE_LINUX_JOYSTICKS 1 -// Define this to 1 to not load gdi32.dll dynamically -#cmakedefine _GLFW_NO_DLOAD_GDI32 1 -// Define this to 1 to not load winmm.dll dynamically -#cmakedefine _GLFW_NO_DLOAD_WINMM 1 - // The GLFW version as used by glfwGetVersionString #define _GLFW_VERSION_FULL "@GLFW_VERSION_FULL@" From b5a3249f2e8a28d1a1324449e80f3b610cc7d40f Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 1 Mar 2012 03:51:35 +0100 Subject: [PATCH 052/226] Removed unused header. --- include/GL/glfw3.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index e84bdbba..cc817521 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -136,10 +136,6 @@ extern "C" { /* -------------------- END SYSTEM/COMPILER SPECIFIC --------------------- */ -/* Include the declaration of the size_t type used below. - */ -#include - /* Include standard OpenGL headers: GLFW uses GL_FALSE/GL_TRUE, and it is * convenient for the user to only have to include . This also * solves the problem with Windows and needing some From 6f3f68bad1c3aef37c7299cdcdb30b8b28e8e85c Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 1 Mar 2012 17:03:42 +0100 Subject: [PATCH 053/226] Gave CMake toolchain file clearer name. --- CMake/{linux-mingw32msvc.cmake => linux-i586-mingw32msvc.cmake} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename CMake/{linux-mingw32msvc.cmake => linux-i586-mingw32msvc.cmake} (100%) diff --git a/CMake/linux-mingw32msvc.cmake b/CMake/linux-i586-mingw32msvc.cmake similarity index 100% rename from CMake/linux-mingw32msvc.cmake rename to CMake/linux-i586-mingw32msvc.cmake From 4ac5ea331bdd6e117e5ef36431f051058b30be1b Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 1 Mar 2012 17:15:37 +0100 Subject: [PATCH 054/226] Updated toolchain file README. --- CMake/README.txt | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/CMake/README.txt b/CMake/README.txt index d24854ed..9581f832 100644 --- a/CMake/README.txt +++ b/CMake/README.txt @@ -1,10 +1,19 @@ -This folder contains a collection of toolchains definition in order to -support cross compilation. The naming scheme is the following: +This directory contains a collection of toolchain definitions for cross +compilation, currently limited to compiling Win32 binaries on Linux. + +The toolchain file naming scheme is as follows: + host-system-compiler.cmake -to use this at the time you run the initial cmake command use the -following parameter - -DCMAKE_TOOLCHAIN_FILE=./toolchains/XXX-XXX-XXX.cmake - which maps to file in this folder. +To use these files you add a special parameter when configuring the source tree: + + cmake -DCMAKE_TOOLCHAIN_FILE= . + +For example, to use the Debian GNU/Linux MinGW package, run CMake like this: + + cmake -DCMAKE_TOOLCHAIN_FILE=CMake/linux-i586-mingw32msvc.cmake . + +For more details see this article: + + http://www.paraview.org/Wiki/CMake_Cross_Compiling -For more details see: http://www.paraview.org/Wiki/CMake_Cross_Compiling From c0db61bd6e07e78ff9a47c8e9ebb26e5859da744 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 5 Mar 2012 16:26:15 +0100 Subject: [PATCH 055/226] Moved autorelease pool back to glfwInit. --- src/cocoa_init.m | 2 ++ src/cocoa_window.m | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cocoa_init.m b/src/cocoa_init.m index 16ea6e68..3251115f 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -78,6 +78,8 @@ static void changeToResourcesDirectory(void) int _glfwPlatformInit(void) { + _glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init]; + _glfwLibrary.NS.OpenGLFramework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl")); if (_glfwLibrary.NS.OpenGLFramework == NULL) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 578d1c41..c74138b3 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -600,8 +600,6 @@ static GLboolean initializeAppKit(void) if (NSApp) return GL_TRUE; - _glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init]; - // Implicitly create shared NSApplication instance [GLFWApplication sharedApplication]; From 7af82fdade34454deaabe5aed09f04d766fe3a9d Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 5 Mar 2012 16:27:53 +0100 Subject: [PATCH 056/226] Replaced deprecated CoreGraphics calls in video mode enumeration. --- readme.html | 1 + src/cocoa_fullscreen.m | 85 ++++++++++++++++++++++++++++-------------- src/cocoa_init.m | 9 ++++- src/cocoa_platform.h | 9 +++-- 4 files changed, 69 insertions(+), 35 deletions(-) diff --git a/readme.html b/readme.html index 5ab86c64..12f726bf 100644 --- a/readme.html +++ b/readme.html @@ -312,6 +312,7 @@ version of GLFW.

  • [Cocoa] Added support for joysticks
  • [Cocoa] Postponed menu creation to first window creation
  • [Cocoa] Replaced NSDate time source with mach_absolute_time
  • +
  • [Cocoa] Replaced deprecated CoreGraphics calls in video mode enumeration
  • [Cocoa] Bugfix: The loop condition for saving video modes used the wrong index variable
  • [Cocoa] Bugfix: The OpenGL framework was not retrieved, making glfwGetProcAddress crash
  • [Cocoa] Bugfix: glfwInit changed the current directory for unbundled executables
  • diff --git a/src/cocoa_fullscreen.m b/src/cocoa_fullscreen.m index 370296b8..cc5df538 100644 --- a/src/cocoa_fullscreen.m +++ b/src/cocoa_fullscreen.m @@ -34,38 +34,59 @@ // Check whether the display mode should be included in enumeration //======================================================================== -static BOOL modeIsGood(NSDictionary* mode) +static GLboolean modeIsGood(CGDisplayModeRef mode) { - // This is a bit controversial, if you've got something other than an - // LCD computer monitor as an output device you might not want these - // checks. You might also want to reject modes which are interlaced, - // or TV out. There is no one-size-fits-all policy that can work here. - // This seems like a decent compromise, but certain applications may - // wish to patch this... - return [[mode objectForKey:(id)kCGDisplayBitsPerPixel] intValue] >= 15 && - [mode objectForKey:(id)kCGDisplayModeIsSafeForHardware] != nil && - [mode objectForKey:(id)kCGDisplayModeIsStretched] == nil; + uint32_t flags = CGDisplayModeGetIOFlags(mode); + if (!(flags & kDisplayModeValidFlag) || !(flags & kDisplayModeSafeFlag)) + return GL_FALSE; + + if (flags & kDisplayModeInterlacedFlag) + return GL_FALSE; + + if (flags & kDisplayModeTelevisionFlag) + return GL_FALSE; + + if (flags & kDisplayModeStretchedFlag) + return GL_FALSE; + + CFStringRef format = CGDisplayModeCopyPixelEncoding(mode); + if (CFStringCompare(format, CFSTR(IO16BitDirectPixels), 0) && + CFStringCompare(format, CFSTR(IO32BitDirectPixels), 0)) + { + CFRelease(format); + return GL_FALSE; + } + + CFRelease(format); + return GL_TRUE; } //======================================================================== // Convert Core Graphics display mode to GLFW video mode //======================================================================== -static GLFWvidmode vidmodeFromCGDisplayMode(NSDictionary* mode) +static GLFWvidmode vidmodeFromCGDisplayMode(CGDisplayModeRef mode) { - unsigned int width = - [[mode objectForKey:(id)kCGDisplayWidth] unsignedIntValue]; - unsigned int height = - [[mode objectForKey:(id)kCGDisplayHeight] unsignedIntValue]; - unsigned int bps = - [[mode objectForKey:(id)kCGDisplayBitsPerSample] unsignedIntValue]; - GLFWvidmode result; - result.width = width; - result.height = height; - result.redBits = bps; - result.greenBits = bps; - result.blueBits = bps; + result.width = CGDisplayModeGetWidth(mode); + result.height = CGDisplayModeGetHeight(mode); + + CFStringRef format = CGDisplayModeCopyPixelEncoding(mode); + + if (CFStringCompare(format, CFSTR(IO16BitDirectPixels), 0) == 0) + { + result.redBits = 5; + result.greenBits = 5; + result.blueBits = 5; + } + else + { + result.redBits = 8; + result.greenBits = 8; + result.blueBits = 8; + } + + CFRelease(format); return result; } @@ -80,17 +101,23 @@ static GLFWvidmode vidmodeFromCGDisplayMode(NSDictionary* mode) int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) { - NSArray* modes = (NSArray*) CGDisplayAvailableModes(CGMainDisplayID()); - unsigned int i, j = 0, n = [modes count]; + CGDisplayModeRef mode; + CFArrayRef modes; + CFIndex count, i; + int stored = 0; - for (i = 0; i < n && j < (unsigned)maxcount; i++) + modes = CGDisplayCopyAllDisplayModes(CGMainDisplayID(), NULL); + count = CFArrayGetCount(modes); + + for (i = 0; i < count && stored < maxcount; i++) { - NSDictionary *mode = [modes objectAtIndex:i]; + mode = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i); if (modeIsGood(mode)) - list[j++] = vidmodeFromCGDisplayMode(mode); + list[stored++] = vidmodeFromCGDisplayMode(mode); } - return j; + CFRelease(modes); + return stored; } //======================================================================== diff --git a/src/cocoa_init.m b/src/cocoa_init.m index 3251115f..067d4dde 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -91,8 +91,7 @@ int _glfwPlatformInit(void) changeToResourcesDirectory(); - _glfwLibrary.NS.desktopMode = - (NSDictionary*) CGDisplayCurrentMode(CGMainDisplayID()); + _glfwLibrary.NS.desktopMode = CGDisplayCopyDisplayMode(CGMainDisplayID()); // Save the original gamma ramp _glfwLibrary.originalRampSize = CGDisplayGammaTableCapacity(CGMainDisplayID()); @@ -117,6 +116,12 @@ int _glfwPlatformTerminate(void) // Restore the original gamma ramp _glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp); + if (_glfwLibrary.NS.desktopMode) + { + CFRelease(_glfwLibrary.NS.desktopMode); + _glfwLibrary.NS.desktopMode = NULL; + } + [NSApp setDelegate:nil]; [_glfwLibrary.NS.delegate release]; _glfwLibrary.NS.delegate = nil; diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index 1a90af01..5a753707 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -37,6 +37,7 @@ #if defined(__OBJC__) #import #else +#include typedef void* id; #endif @@ -90,10 +91,10 @@ typedef struct _GLFWlibraryNS } timer; // dlopen handle for dynamically loading OpenGL extension entry points - void* OpenGLFramework; - id desktopMode; - id delegate; - id autoreleasePool; + void* OpenGLFramework; + CGDisplayModeRef desktopMode; + id delegate; + id autoreleasePool; } _GLFWlibraryNS; From e55396d75432a3386af70c3737054f5ff3d7db01 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 5 Mar 2012 20:09:06 +0100 Subject: [PATCH 057/226] Shortened call to setAppleMenu:. --- src/cocoa_window.m | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 239e883a..defe8fce 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -469,13 +469,6 @@ static int convertMacKeyCode(unsigned int macKeyCode) @end -// Prior to Snow Leopard, we need to use this oddly-named semi-private API -// to get the application menu working properly. Need to be careful in -// case it goes away in a future OS update. -@interface NSApplication (NSAppleMenu) -- (void)setAppleMenu:(NSMenu*)m; -@end - //======================================================================== // Try to figure out what the calling application is called //======================================================================== @@ -584,11 +577,9 @@ static void setUpMenuBar(void) action:@selector(arrangeInFront:) keyEquivalent:@""]; - // At least guard the call to private API to avoid an exception if it - // goes away. Hopefully that means the worst we'll break in future is to - // look ugly... - if ([NSApp respondsToSelector:@selector(setAppleMenu:)]) - [NSApp setAppleMenu:appMenu]; + // Prior to Snow Leopard, we need to use this oddly-named semi-private API + // to get the application menu working properly. + [NSApp performSelector:NSSelectorFromString(@"setAppleMenu:") withObject:appMenu]; } From 4b21ccbe19706dc8bc59c80c814d298e8c56e49d Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 5 Mar 2012 20:22:23 +0100 Subject: [PATCH 058/226] Output fix. --- tests/glfwinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/glfwinfo.c b/tests/glfwinfo.c index 369e6a96..45cb8616 100644 --- a/tests/glfwinfo.c +++ b/tests/glfwinfo.c @@ -263,7 +263,7 @@ int main(int argc, char** argv) if (major > 3 || (major == 3 && minor >= 2)) { glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask); - printf("OpenGL profile mask: 0x%08x (%s)\n", mask, get_profile_name(mask)); + printf("OpenGL profile mask: %s (0x%08x)\n", get_profile_name(mask), mask); printf("OpenGL profile parsed by GLFW: %s\n", get_glfw_profile_name(glfwGetWindowParam(window, GLFW_OPENGL_PROFILE))); From cb9bae5c71382a517e8a22a2773cb6521b6b1d6c Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 5 Mar 2012 20:27:47 +0100 Subject: [PATCH 059/226] Made glfwOpenWindow enforce the forward-compat and profile hints. --- readme.html | 1 + src/cocoa_window.m | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/readme.html b/readme.html index 5943be58..5762b023 100644 --- a/readme.html +++ b/readme.html @@ -313,6 +313,7 @@ version of GLFW.

  • [Cocoa] Postponed menu creation to first window creation
  • [Cocoa] Replaced NSDate time source with mach_absolute_time
  • [Cocoa] Replaced deprecated CoreGraphics calls in video mode enumeration
  • +
  • [Cocoa] Bugfix: glfwOpenWindow did not properly enforce the forward-compatible and context profile hints
  • [Cocoa] Bugfix: The loop condition for saving video modes used the wrong index variable
  • [Cocoa] Bugfix: The OpenGL framework was not retrieved, making glfwGetProcAddress crash
  • [Cocoa] Bugfix: glfwInit changed the current directory for unbundled executables
  • diff --git a/src/cocoa_window.m b/src/cocoa_window.m index defe8fce..46532778 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -675,14 +675,23 @@ static GLboolean createContext(_GLFWwindow* window, return GL_FALSE; } - if (wndconfig->glProfile) + if (wndconfig->glMajor > 2) { - // Fail if a profile other than core was explicitly selected + if (!wndconfig->glForward) + { + _glfwSetError(GLFW_VERSION_UNAVAILABLE, + "Cocoa/NSOpenGL: The targeted version of Mac OS X " + "only supports OpenGL 3.2 contexts if they are " + "forward-compatible"); + return GL_FALSE; + } + if (wndconfig->glProfile != GLFW_OPENGL_CORE_PROFILE) { _glfwSetError(GLFW_VERSION_UNAVAILABLE, "Cocoa/NSOpenGL: The targeted version of Mac OS X " - "only supports the OpenGL core profile"); + "only supports OpenGL 3.2 contexts if they use the " + "core profile"); return GL_FALSE; } } From 3383e59a73b18eb3a49288339ed06b7c677278db Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 5 Mar 2012 20:30:59 +0100 Subject: [PATCH 060/226] Renamed function. --- src/cocoa_window.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 46532778..2907e941 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -523,7 +523,7 @@ static NSString* findAppName(void) // localize(d|able), etc. Loading a nib would save us this horror, but that // doesn't seem like a good thing to require of GLFW's clients. //======================================================================== -static void setUpMenuBar(void) +static void createMenuBar(void) { NSString* appName = findAppName(); @@ -597,7 +597,7 @@ static GLboolean initializeAppKit(void) // Setting up the menu bar must go between sharedApplication // above and finishLaunching below, in order to properly emulate the // behavior of NSApplicationMain - setUpMenuBar(); + createMenuBar(); [NSApp finishLaunching]; From a90675c526445495fd6e1fc0d8b4a94338f82a4a Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 5 Mar 2012 22:05:40 +0100 Subject: [PATCH 061/226] Shortened the shortening. --- src/cocoa_window.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 2907e941..94a11118 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -579,7 +579,7 @@ static void createMenuBar(void) // Prior to Snow Leopard, we need to use this oddly-named semi-private API // to get the application menu working properly. - [NSApp performSelector:NSSelectorFromString(@"setAppleMenu:") withObject:appMenu]; + [NSApp performSelector:@selector(setAppleMenu:) withObject:appMenu]; } From adf4899f4c94cba654f777632c245d7382c11de4 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 5 Mar 2012 22:37:48 +0100 Subject: [PATCH 062/226] Added name and version to test and example bundles. --- examples/CMakeLists.txt | 18 ++++++++++++++++-- tests/CMakeLists.txt | 11 +++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 37b7f754..39cad943 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -14,6 +14,12 @@ if (APPLE) add_executable("Split View" MACOSX_BUNDLE splitview.c) add_executable(Triangle MACOSX_BUNDLE triangle.c) add_executable(Wave MACOSX_BUNDLE wave.c) + + set_target_properties(Boing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Boing") + set_target_properties(Gears PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Gears") + set_target_properties("Split View" PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Split View") + set_target_properties(Triangle PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Triangle") + set_target_properties(Wave PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Wave") else() # Set boring names for executables add_executable(boing WIN32 boing.c) @@ -24,11 +30,19 @@ else() add_executable(wave WIN32 wave.c) endif() -set(WINDOWS_BINARIES boing gears heightmap splitview triangle wave) - if (MSVC) + set(WINDOWS_BINARIES boing gears heightmap splitview triangle wave) + # Tell MSVC to use main instead of WinMain for Windows subsystem executables set_target_properties(${WINDOWS_BINARIES} PROPERTIES LINK_FLAGS "/ENTRY:mainCRTStartup") endif() +if (APPLE) + set(BUNDLE_BINARIES Boing Gears "Split View" Triangle Wave) + + set_target_properties(${BUNDLE_BINARIES} PROPERTIES + MACOSX_BUNDLE_SHORT_VERSION_STRING ${GLFW_VERSION} + MACOSX_BUNDLE_LONG_VERSION_STRING ${GLFW_VERSION_FULL}) +endif() + diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 58631603..44a79972 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -44,18 +44,23 @@ target_link_libraries(reopen ${STATIC_DEPS}) add_executable(accuracy WIN32 MACOSX_BUNDLE accuracy.c) target_link_libraries(accuracy ${STATIC_DEPS}) +set_target_properties(accuracy PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Accuracy") add_executable(sharing WIN32 MACOSX_BUNDLE sharing.c) target_link_libraries(sharing ${STATIC_DEPS}) +set_target_properties(sharing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Sharing") add_executable(tearing WIN32 MACOSX_BUNDLE tearing.c) target_link_libraries(tearing ${STATIC_DEPS}) +set_target_properties(tearing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Tearing") add_executable(title WIN32 MACOSX_BUNDLE title.c) target_link_libraries(title ${STATIC_DEPS}) +set_target_properties(title PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Title") add_executable(windows WIN32 MACOSX_BUNDLE windows.c) target_link_libraries(windows ${STATIC_DEPS}) +set_target_properties(windows PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Windows") set(WINDOWS_BINARIES accuracy sharing tearing title windows) set(CONSOLE_BINARIES defaults events fsaa fsfocus gamma glfwinfo iconify @@ -67,3 +72,9 @@ if (MSVC) LINK_FLAGS "/ENTRY:mainCRTStartup") endif() +if (APPLE) + set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES + MACOSX_BUNDLE_SHORT_VERSION_STRING ${GLFW_VERSION} + MACOSX_BUNDLE_LONG_VERSION_STRING ${GLFW_VERSION_FULL}) +endif() + From c286c716cde8681e0c503024c95f10f05fbac59e Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 5 Mar 2012 23:41:05 +0100 Subject: [PATCH 063/226] Formatting. --- examples/CMakeLists.txt | 52 ++++++++++++++++++++--------------------- tests/CMakeLists.txt | 12 +++++----- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 39cad943..a644b987 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -8,41 +8,41 @@ include_directories(${GLFW_SOURCE_DIR}/include ${OPENGL_INCLUDE_DIR}) if (APPLE) - # Set fancy names for bundles - add_executable(Boing MACOSX_BUNDLE boing.c) - add_executable(Gears MACOSX_BUNDLE gears.c) - add_executable("Split View" MACOSX_BUNDLE splitview.c) - add_executable(Triangle MACOSX_BUNDLE triangle.c) - add_executable(Wave MACOSX_BUNDLE wave.c) + # Set fancy names for bundles + add_executable(Boing MACOSX_BUNDLE boing.c) + add_executable(Gears MACOSX_BUNDLE gears.c) + add_executable("Split View" MACOSX_BUNDLE splitview.c) + add_executable(Triangle MACOSX_BUNDLE triangle.c) + add_executable(Wave MACOSX_BUNDLE wave.c) - set_target_properties(Boing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Boing") - set_target_properties(Gears PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Gears") - set_target_properties("Split View" PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Split View") - set_target_properties(Triangle PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Triangle") - set_target_properties(Wave PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Wave") + set_target_properties(Boing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Boing") + set_target_properties(Gears PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Gears") + set_target_properties("Split View" PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Split View") + set_target_properties(Triangle PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Triangle") + set_target_properties(Wave PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Wave") else() - # Set boring names for executables - add_executable(boing WIN32 boing.c) - add_executable(gears WIN32 gears.c) - add_executable(heightmap WIN32 heightmap.c getopt.c) - add_executable(splitview WIN32 splitview.c) - add_executable(triangle WIN32 triangle.c) - add_executable(wave WIN32 wave.c) + # Set boring names for executables + add_executable(boing WIN32 boing.c) + add_executable(gears WIN32 gears.c) + add_executable(heightmap WIN32 heightmap.c getopt.c) + add_executable(splitview WIN32 splitview.c) + add_executable(triangle WIN32 triangle.c) + add_executable(wave WIN32 wave.c) endif() if (MSVC) - set(WINDOWS_BINARIES boing gears heightmap splitview triangle wave) + set(WINDOWS_BINARIES boing gears heightmap splitview triangle wave) - # Tell MSVC to use main instead of WinMain for Windows subsystem executables - set_target_properties(${WINDOWS_BINARIES} PROPERTIES - LINK_FLAGS "/ENTRY:mainCRTStartup") + # Tell MSVC to use main instead of WinMain for Windows subsystem executables + set_target_properties(${WINDOWS_BINARIES} PROPERTIES + LINK_FLAGS "/ENTRY:mainCRTStartup") endif() if (APPLE) - set(BUNDLE_BINARIES Boing Gears "Split View" Triangle Wave) + set(BUNDLE_BINARIES Boing Gears "Split View" Triangle Wave) - set_target_properties(${BUNDLE_BINARIES} PROPERTIES - MACOSX_BUNDLE_SHORT_VERSION_STRING ${GLFW_VERSION} - MACOSX_BUNDLE_LONG_VERSION_STRING ${GLFW_VERSION_FULL}) + set_target_properties(${BUNDLE_BINARIES} PROPERTIES + MACOSX_BUNDLE_SHORT_VERSION_STRING ${GLFW_VERSION} + MACOSX_BUNDLE_LONG_VERSION_STRING ${GLFW_VERSION_FULL}) endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 44a79972..663f9a11 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -67,14 +67,14 @@ 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 - set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES - LINK_FLAGS "/ENTRY:mainCRTStartup") + # Tell MSVC to use main instead of WinMain for Windows subsystem executables + set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES + LINK_FLAGS "/ENTRY:mainCRTStartup") endif() if (APPLE) - set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES - MACOSX_BUNDLE_SHORT_VERSION_STRING ${GLFW_VERSION} - MACOSX_BUNDLE_LONG_VERSION_STRING ${GLFW_VERSION_FULL}) + set_target_properties(${WINDOWS_BINARIES} ${CONSOLE_BINARIES} PROPERTIES + MACOSX_BUNDLE_SHORT_VERSION_STRING ${GLFW_VERSION} + MACOSX_BUNDLE_LONG_VERSION_STRING ${GLFW_VERSION_FULL}) endif() From 5f854b2bbf2ea9b6129a990271119f462ef4520e Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 6 Mar 2012 00:58:04 +0100 Subject: [PATCH 064/226] Replaced CFRelease with CGDisplayModeRelease. --- src/cocoa_init.m | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/cocoa_init.m b/src/cocoa_init.m index 067d4dde..89260c56 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -116,11 +116,7 @@ int _glfwPlatformTerminate(void) // Restore the original gamma ramp _glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp); - if (_glfwLibrary.NS.desktopMode) - { - CFRelease(_glfwLibrary.NS.desktopMode); - _glfwLibrary.NS.desktopMode = NULL; - } + CGDisplayModeRelease(_glfwLibrary.NS.desktopMode); [NSApp setDelegate:nil]; [_glfwLibrary.NS.delegate release]; From be547da9d2ead0ee17371111a06b85d088ba47a8 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 6 Mar 2012 02:21:01 +0100 Subject: [PATCH 065/226] Replaced more deprecated CoreGraphics calls. --- readme.html | 2 +- src/cocoa_fullscreen.m | 97 ++++++++++++++++++++++++++++++++++++++++++ src/cocoa_platform.h | 3 ++ src/cocoa_window.m | 37 +++++----------- 4 files changed, 111 insertions(+), 28 deletions(-) diff --git a/readme.html b/readme.html index 5762b023..5f3af632 100644 --- a/readme.html +++ b/readme.html @@ -312,7 +312,7 @@ version of GLFW.

  • [Cocoa] Added support for joysticks
  • [Cocoa] Postponed menu creation to first window creation
  • [Cocoa] Replaced NSDate time source with mach_absolute_time
  • -
  • [Cocoa] Replaced deprecated CoreGraphics calls in video mode enumeration
  • +
  • [Cocoa] Replaced deprecated CoreGraphics calls in video mode enumeration and setting
  • [Cocoa] Bugfix: glfwOpenWindow did not properly enforce the forward-compatible and context profile hints
  • [Cocoa] Bugfix: The loop condition for saving video modes used the wrong index variable
  • [Cocoa] Bugfix: The OpenGL framework was not retrieved, making glfwGetProcAddress crash
  • diff --git a/src/cocoa_fullscreen.m b/src/cocoa_fullscreen.m index cc5df538..d3a715ba 100644 --- a/src/cocoa_fullscreen.m +++ b/src/cocoa_fullscreen.m @@ -29,6 +29,9 @@ #include "internal.h" +#include +#include + //======================================================================== // Check whether the display mode should be included in enumeration @@ -91,6 +94,100 @@ static GLFWvidmode vidmodeFromCGDisplayMode(CGDisplayModeRef mode) } +////////////////////////////////////////////////////////////////////////// +////// GLFW internal API ////// +////////////////////////////////////////////////////////////////////////// + +//======================================================================== +// Change the current video mode +//======================================================================== + +GLboolean _glfwSetVideoMode(int* width, int* height, int* bpp, int* refreshRate) +{ + CGDisplayModeRef bestMode = NULL; + CFArrayRef modes; + CFIndex count, i; + unsigned int leastSizeDiff = UINT_MAX; + double leastRateDiff = DBL_MAX; + + modes = CGDisplayCopyAllDisplayModes(CGMainDisplayID(), NULL); + count = CFArrayGetCount(modes); + + for (i = 0; i < count; i++) + { + CGDisplayModeRef mode = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i); + if (!modeIsGood(mode)) + continue; + + int modeBPP; + + // Identify display mode pixel encoding + { + CFStringRef format = CGDisplayModeCopyPixelEncoding(mode); + + if (CFStringCompare(format, CFSTR(IO16BitDirectPixels), 0) == 0) + modeBPP = 16; + else + modeBPP = 32; + + CFRelease(format); + } + + int modeWidth = (int) CGDisplayModeGetWidth(mode); + int modeHeight = (int) CGDisplayModeGetHeight(mode); + + unsigned int sizeDiff = (abs(modeBPP - *bpp) << 25) | + ((modeWidth - *width) * (modeWidth - *width) + + (modeHeight - *height) * (modeHeight - *height)); + + double rateDiff; + + if (*refreshRate > 0) + rateDiff = fabs(CGDisplayModeGetRefreshRate(mode) - *refreshRate); + else + { + // If no refresh rate was specified, then they're all the same + rateDiff = 0; + } + + if ((sizeDiff < leastSizeDiff) || + (sizeDiff == leastSizeDiff && (rateDiff < leastRateDiff))) + { + bestMode = mode; + + leastSizeDiff = sizeDiff; + leastRateDiff = rateDiff; + } + } + + if (!bestMode) + { + CFRelease(modes); + return GL_FALSE; + } + + CGDisplayCapture(CGMainDisplayID()); + CGDisplaySetDisplayMode(CGMainDisplayID(), bestMode, NULL); + + CFRelease(modes); + return GL_TRUE; +} + + +//======================================================================== +// Restore the previously saved (original) video mode +//======================================================================== + +void _glfwRestoreVideoMode(void) +{ + CGDisplaySetDisplayMode(CGMainDisplayID(), + _glfwLibrary.NS.desktopMode, + NULL); + + CGDisplayRelease(CGMainDisplayID()); +} + + ////////////////////////////////////////////////////////////////////////// ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index 5a753707..a06c13a0 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -109,5 +109,8 @@ void _glfwInitTimer(void); void _glfwInitJoysticks(void); void _glfwTerminateJoysticks(void); +// Fullscreen +GLboolean _glfwSetVideoMode(int* width, int* height, int* bpp, int* refreshRate); +void _glfwRestoreVideoMode(void); #endif // _platform_h_ diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 94a11118..c1d710c0 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -850,28 +850,6 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, // Don't use accumulation buffer support; it's not accelerated // Aux buffers probably aren't accelerated either - CFDictionaryRef fullscreenMode = NULL; - if (wndconfig->mode == GLFW_FULLSCREEN) - { - // I think it's safe to pass 0 to the refresh rate for this function - // rather than conditionalizing the code to call the version which - // doesn't specify refresh... - fullscreenMode = - CGDisplayBestModeForParametersAndRefreshRateWithProperty( - CGMainDisplayID(), - colorBits + fbconfig->alphaBits, - window->width, window->height, - wndconfig->refreshRate, - // Controversial, see macosx_fullscreen.m for discussion - kCGDisplayModeIsSafeForHardware, - NULL); - - window->width = - [[(id)fullscreenMode objectForKey:(id)kCGDisplayWidth] intValue]; - window->height = - [[(id)fullscreenMode objectForKey:(id)kCGDisplayHeight] intValue]; - } - if (!createWindow(window, wndconfig)) return GL_FALSE; @@ -883,8 +861,15 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, if (wndconfig->mode == GLFW_FULLSCREEN) { - CGCaptureAllDisplays(); - CGDisplaySwitchToMode(CGMainDisplayID(), fullscreenMode); + int bpp = colorBits + fbconfig->alphaBits; + + if (!_glfwSetVideoMode(&window->width, + &window->height, + &bpp, + &window->refreshRate)) + { + return GL_FALSE; + } [[window->NS.window contentView] enterFullScreenMode:[NSScreen mainScreen] withOptions:nil]; @@ -914,9 +899,7 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window) { [[window->NS.window contentView] exitFullScreenModeWithOptions:nil]; - CGDisplaySwitchToMode(CGMainDisplayID(), - (CFDictionaryRef) _glfwLibrary.NS.desktopMode); - CGReleaseAllDisplays(); + _glfwRestoreVideoMode(); } [window->NSGL.pixelFormat release]; From 8155f90bf33c07724d9f6e7e69fcddebc6fde0c4 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 7 Mar 2012 15:04:14 +0100 Subject: [PATCH 066/226] Formatting. --- src/cocoa_fullscreen.m | 2 ++ src/cocoa_init.m | 2 ++ src/cocoa_joystick.m | 1 - src/cocoa_opengl.m | 4 ++++ src/cocoa_time.c | 1 + src/cocoa_window.m | 20 ++++++++++++++++++++ 6 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/cocoa_fullscreen.m b/src/cocoa_fullscreen.m index d3a715ba..147913fb 100644 --- a/src/cocoa_fullscreen.m +++ b/src/cocoa_fullscreen.m @@ -64,6 +64,7 @@ static GLboolean modeIsGood(CGDisplayModeRef mode) return GL_TRUE; } + //======================================================================== // Convert Core Graphics display mode to GLFW video mode //======================================================================== @@ -217,6 +218,7 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) return stored; } + //======================================================================== // Get the desktop video mode //======================================================================== diff --git a/src/cocoa_init.m b/src/cocoa_init.m index 89260c56..d9530f62 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -33,6 +33,7 @@ //======================================================================== // Change to our application bundle's resources directory, if present //======================================================================== + static void changeToResourcesDirectory(void) { char resourcesPath[MAXPATHLEN]; @@ -105,6 +106,7 @@ int _glfwPlatformInit(void) return GL_TRUE; } + //======================================================================== // Close window, if open, and shut down GLFW //======================================================================== diff --git a/src/cocoa_joystick.m b/src/cocoa_joystick.m index a167692f..45b3be0f 100644 --- a/src/cocoa_joystick.m +++ b/src/cocoa_joystick.m @@ -579,4 +579,3 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, return numbuttons; } - diff --git a/src/cocoa_opengl.m b/src/cocoa_opengl.m index bd3827fc..0ea39076 100644 --- a/src/cocoa_opengl.m +++ b/src/cocoa_opengl.m @@ -59,6 +59,7 @@ void _glfwPlatformSwapBuffers(void) [window->NSGL.context flushBuffer]; } + //======================================================================== // Set double buffering swap interval //======================================================================== @@ -71,6 +72,7 @@ void _glfwPlatformSwapInterval(int interval) [window->NSGL.context setValues:&sync forParameter:NSOpenGLCPSwapInterval]; } + //======================================================================== // Check if an OpenGL extension is available at runtime //======================================================================== @@ -81,6 +83,7 @@ int _glfwPlatformExtensionSupported(const char* extension) return GL_FALSE; } + //======================================================================== // Get the function pointer to an OpenGL function //======================================================================== @@ -99,6 +102,7 @@ void* _glfwPlatformGetProcAddress(const char* procname) return symbol; } + //======================================================================== // Copies the specified OpenGL state categories from src to dst //======================================================================== diff --git a/src/cocoa_time.c b/src/cocoa_time.c index 4facbffb..745b4239 100644 --- a/src/cocoa_time.c +++ b/src/cocoa_time.c @@ -74,6 +74,7 @@ double _glfwPlatformGetTime(void) _glfwLibrary.NS.timer.resolution; } + //======================================================================== // Set timer value in seconds //======================================================================== diff --git a/src/cocoa_window.m b/src/cocoa_window.m index c1d710c0..d2bcbb3d 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -112,6 +112,7 @@ @end + //======================================================================== // Delegate for application related notifications //======================================================================== @@ -133,6 +134,7 @@ @end + //======================================================================== // Keyboard symbol translation table //======================================================================== @@ -270,6 +272,7 @@ static const unsigned int MAC_TO_GLFW_KEYCODE_MAPPING[128] = /* 7f */ -1, }; + //======================================================================== // Converts a Mac OS X keycode to a GLFW keycode //======================================================================== @@ -285,6 +288,7 @@ static int convertMacKeyCode(unsigned int macKeyCode) return MAC_TO_GLFW_KEYCODE_MAPPING[macKeyCode]; } + //======================================================================== // Content view class for the GLFW window //======================================================================== @@ -446,6 +450,7 @@ static int convertMacKeyCode(unsigned int macKeyCode) @end + //======================================================================== // GLFW application class //======================================================================== @@ -516,6 +521,7 @@ static NSString* findAppName(void) return @"GLFW Application"; } + //======================================================================== // Set up the menu bar (manually) // This is nasty, nasty stuff -- calls to undocumented semi-private APIs that @@ -523,6 +529,7 @@ static NSString* findAppName(void) // localize(d|able), etc. Loading a nib would save us this horror, but that // doesn't seem like a good thing to require of GLFW's clients. //======================================================================== + static void createMenuBar(void) { NSString* appName = findAppName(); @@ -586,6 +593,7 @@ static void createMenuBar(void) //======================================================================== // Initialize the Cocoa Application Kit //======================================================================== + static GLboolean initializeAppKit(void) { if (NSApp) @@ -604,6 +612,7 @@ static GLboolean initializeAppKit(void) return GL_TRUE; } + //======================================================================== // Create the Cocoa window //======================================================================== @@ -647,6 +656,7 @@ static GLboolean createWindow(_GLFWwindow* window, return GL_TRUE; } + //======================================================================== // Create the OpenGL context //======================================================================== @@ -919,6 +929,7 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window) // TODO: Probably more cleanup } + //======================================================================== // Set the window title //======================================================================== @@ -928,6 +939,7 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title) [window->NS.window setTitle:[NSString stringWithUTF8String:title]]; } + //======================================================================== // Set the window size //======================================================================== @@ -937,6 +949,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) [window->NS.window setContentSize:NSMakeSize(width, height)]; } + //======================================================================== // Set the window position //======================================================================== @@ -957,6 +970,7 @@ void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y) display:YES]; } + //======================================================================== // Iconify the window //======================================================================== @@ -966,6 +980,7 @@ void _glfwPlatformIconifyWindow(_GLFWwindow* window) [window->NS.window miniaturize:nil]; } + //======================================================================== // Restore (un-iconify) the window //======================================================================== @@ -975,6 +990,7 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window) [window->NS.window deminiaturize:nil]; } + //======================================================================== // Write back window parameters into GLFW window structure //======================================================================== @@ -1049,6 +1065,7 @@ void _glfwPlatformRefreshWindowParams(void) window->glDebug = GL_FALSE; } + //======================================================================== // Poll for new window and input events //======================================================================== @@ -1073,6 +1090,7 @@ void _glfwPlatformPollEvents(void) _glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init]; } + //======================================================================== // Wait for new window and input events //======================================================================== @@ -1091,6 +1109,7 @@ void _glfwPlatformWaitEvents( void ) _glfwPlatformPollEvents(); } + //======================================================================== // Set physical mouse cursor position //======================================================================== @@ -1123,6 +1142,7 @@ void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y) CGDisplayMoveCursorToPoint(CGMainDisplayID(), targetPoint); } + //======================================================================== // Set physical mouse cursor mode //======================================================================== From 89eec8af09c82a9193cc7c7ae6d5436375f91fa8 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 7 Mar 2012 15:10:53 +0100 Subject: [PATCH 067/226] Made more consistent use of key code conversion. --- src/cocoa_window.m | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index d2bcbb3d..411e600d 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -392,11 +392,11 @@ static int convertMacKeyCode(unsigned int macKeyCode) { NSUInteger i, length; NSString* characters; - int code = convertMacKeyCode([event keyCode]); + int key = convertMacKeyCode([event keyCode]); - if (code != -1) + if (key != -1) { - _glfwInputKey(window, code, GLFW_PRESS); + _glfwInputKey(window, key, GLFW_PRESS); if ([event modifierFlags] & NSCommandKeyMask) { @@ -416,7 +416,7 @@ static int convertMacKeyCode(unsigned int macKeyCode) - (void)flagsChanged:(NSEvent *)event { - int mode; + int mode, key; unsigned int newModifierFlags = [event modifierFlags] | NSDeviceIndependentModifierFlagsMask; @@ -426,14 +426,17 @@ static int convertMacKeyCode(unsigned int macKeyCode) mode = GLFW_RELEASE; window->NS.modifierFlags = newModifierFlags; - _glfwInputKey(window, MAC_TO_GLFW_KEYCODE_MAPPING[[event keyCode]], mode); + + key = convertMacKeyCode([event keyCode]); + if (key != -1) + _glfwInputKey(window, key, mode); } - (void)keyUp:(NSEvent *)event { - int code = convertMacKeyCode([event keyCode]); - if (code != -1) - _glfwInputKey(window, code, GLFW_RELEASE); + int key = convertMacKeyCode([event keyCode]); + if (key != -1) + _glfwInputKey(window, key, GLFW_RELEASE); } - (void)scrollWheel:(NSEvent *)event From 339fb7d246af11248d42d5d2131f85dba8e0dc56 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 7 Mar 2012 15:13:41 +0100 Subject: [PATCH 068/226] Made key code translation table private to function. --- src/cocoa_window.m | 274 ++++++++++++++++++++++----------------------- 1 file changed, 135 insertions(+), 139 deletions(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 411e600d..b8ccdea6 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -135,157 +135,153 @@ @end -//======================================================================== -// Keyboard symbol translation table -//======================================================================== - -// TODO: Need to find mappings for F13-F15, volume down/up/mute, and eject. -static const unsigned int MAC_TO_GLFW_KEYCODE_MAPPING[128] = -{ - /* 00 */ GLFW_KEY_A, - /* 01 */ GLFW_KEY_S, - /* 02 */ GLFW_KEY_D, - /* 03 */ GLFW_KEY_F, - /* 04 */ GLFW_KEY_H, - /* 05 */ GLFW_KEY_G, - /* 06 */ GLFW_KEY_Z, - /* 07 */ GLFW_KEY_X, - /* 08 */ GLFW_KEY_C, - /* 09 */ GLFW_KEY_V, - /* 0a */ GLFW_KEY_GRAVE_ACCENT, - /* 0b */ GLFW_KEY_B, - /* 0c */ GLFW_KEY_Q, - /* 0d */ GLFW_KEY_W, - /* 0e */ GLFW_KEY_E, - /* 0f */ GLFW_KEY_R, - /* 10 */ GLFW_KEY_Y, - /* 11 */ GLFW_KEY_T, - /* 12 */ GLFW_KEY_1, - /* 13 */ GLFW_KEY_2, - /* 14 */ GLFW_KEY_3, - /* 15 */ GLFW_KEY_4, - /* 16 */ GLFW_KEY_6, - /* 17 */ GLFW_KEY_5, - /* 18 */ GLFW_KEY_EQUAL, - /* 19 */ GLFW_KEY_9, - /* 1a */ GLFW_KEY_7, - /* 1b */ GLFW_KEY_MINUS, - /* 1c */ GLFW_KEY_8, - /* 1d */ GLFW_KEY_0, - /* 1e */ GLFW_KEY_RIGHT_BRACKET, - /* 1f */ GLFW_KEY_O, - /* 20 */ GLFW_KEY_U, - /* 21 */ GLFW_KEY_LEFT_BRACKET, - /* 22 */ GLFW_KEY_I, - /* 23 */ GLFW_KEY_P, - /* 24 */ GLFW_KEY_ENTER, - /* 25 */ GLFW_KEY_L, - /* 26 */ GLFW_KEY_J, - /* 27 */ GLFW_KEY_APOSTROPHE, - /* 28 */ GLFW_KEY_K, - /* 29 */ GLFW_KEY_SEMICOLON, - /* 2a */ GLFW_KEY_BACKSLASH, - /* 2b */ GLFW_KEY_COMMA, - /* 2c */ GLFW_KEY_SLASH, - /* 2d */ GLFW_KEY_N, - /* 2e */ GLFW_KEY_M, - /* 2f */ GLFW_KEY_PERIOD, - /* 30 */ GLFW_KEY_TAB, - /* 31 */ GLFW_KEY_SPACE, - /* 32 */ GLFW_KEY_WORLD_1, - /* 33 */ GLFW_KEY_BACKSPACE, - /* 34 */ -1, - /* 35 */ GLFW_KEY_ESCAPE, - /* 36 */ GLFW_KEY_RIGHT_SUPER, - /* 37 */ GLFW_KEY_LEFT_SUPER, - /* 38 */ GLFW_KEY_LEFT_SHIFT, - /* 39 */ GLFW_KEY_CAPS_LOCK, - /* 3a */ GLFW_KEY_LEFT_ALT, - /* 3b */ GLFW_KEY_LEFT_CONTROL, - /* 3c */ GLFW_KEY_RIGHT_SHIFT, - /* 3d */ GLFW_KEY_RIGHT_ALT, - /* 3e */ GLFW_KEY_RIGHT_CONTROL, - /* 3f */ -1, /* Function */ - /* 40 */ GLFW_KEY_F17, - /* 41 */ GLFW_KEY_KP_DECIMAL, - /* 42 */ -1, - /* 43 */ GLFW_KEY_KP_MULTIPLY, - /* 44 */ -1, - /* 45 */ GLFW_KEY_KP_ADD, - /* 46 */ -1, - /* 47 */ GLFW_KEY_NUM_LOCK, /* Really KeypadClear... */ - /* 48 */ -1, /* VolumeUp */ - /* 49 */ -1, /* VolumeDown */ - /* 4a */ -1, /* Mute */ - /* 4b */ GLFW_KEY_KP_DIVIDE, - /* 4c */ GLFW_KEY_KP_ENTER, - /* 4d */ -1, - /* 4e */ GLFW_KEY_KP_SUBTRACT, - /* 4f */ GLFW_KEY_F18, - /* 50 */ GLFW_KEY_F19, - /* 51 */ GLFW_KEY_KP_EQUAL, - /* 52 */ GLFW_KEY_KP_0, - /* 53 */ GLFW_KEY_KP_1, - /* 54 */ GLFW_KEY_KP_2, - /* 55 */ GLFW_KEY_KP_3, - /* 56 */ GLFW_KEY_KP_4, - /* 57 */ GLFW_KEY_KP_5, - /* 58 */ GLFW_KEY_KP_6, - /* 59 */ GLFW_KEY_KP_7, - /* 5a */ GLFW_KEY_F20, - /* 5b */ GLFW_KEY_KP_8, - /* 5c */ GLFW_KEY_KP_9, - /* 5d */ -1, - /* 5e */ -1, - /* 5f */ -1, - /* 60 */ GLFW_KEY_F5, - /* 61 */ GLFW_KEY_F6, - /* 62 */ GLFW_KEY_F7, - /* 63 */ GLFW_KEY_F3, - /* 64 */ GLFW_KEY_F8, - /* 65 */ GLFW_KEY_F9, - /* 66 */ -1, - /* 67 */ GLFW_KEY_F11, - /* 68 */ -1, - /* 69 */ GLFW_KEY_F13, - /* 6a */ GLFW_KEY_F16, - /* 6b */ GLFW_KEY_F14, - /* 6c */ -1, - /* 6d */ GLFW_KEY_F10, - /* 6e */ -1, - /* 6f */ GLFW_KEY_F12, - /* 70 */ -1, - /* 71 */ GLFW_KEY_F15, - /* 72 */ GLFW_KEY_INSERT, /* Really Help... */ - /* 73 */ GLFW_KEY_HOME, - /* 74 */ GLFW_KEY_PAGE_UP, - /* 75 */ GLFW_KEY_DELETE, - /* 76 */ GLFW_KEY_F4, - /* 77 */ GLFW_KEY_END, - /* 78 */ GLFW_KEY_F2, - /* 79 */ GLFW_KEY_PAGE_DOWN, - /* 7a */ GLFW_KEY_F1, - /* 7b */ GLFW_KEY_LEFT, - /* 7c */ GLFW_KEY_RIGHT, - /* 7d */ GLFW_KEY_DOWN, - /* 7e */ GLFW_KEY_UP, - /* 7f */ -1, -}; - - //======================================================================== // Converts a Mac OS X keycode to a GLFW keycode //======================================================================== static int convertMacKeyCode(unsigned int macKeyCode) { + // Keyboard symbol translation table + // TODO: Need to find mappings for F13-F15, volume down/up/mute, and eject. + static const unsigned int table[128] = + { + /* 00 */ GLFW_KEY_A, + /* 01 */ GLFW_KEY_S, + /* 02 */ GLFW_KEY_D, + /* 03 */ GLFW_KEY_F, + /* 04 */ GLFW_KEY_H, + /* 05 */ GLFW_KEY_G, + /* 06 */ GLFW_KEY_Z, + /* 07 */ GLFW_KEY_X, + /* 08 */ GLFW_KEY_C, + /* 09 */ GLFW_KEY_V, + /* 0a */ GLFW_KEY_GRAVE_ACCENT, + /* 0b */ GLFW_KEY_B, + /* 0c */ GLFW_KEY_Q, + /* 0d */ GLFW_KEY_W, + /* 0e */ GLFW_KEY_E, + /* 0f */ GLFW_KEY_R, + /* 10 */ GLFW_KEY_Y, + /* 11 */ GLFW_KEY_T, + /* 12 */ GLFW_KEY_1, + /* 13 */ GLFW_KEY_2, + /* 14 */ GLFW_KEY_3, + /* 15 */ GLFW_KEY_4, + /* 16 */ GLFW_KEY_6, + /* 17 */ GLFW_KEY_5, + /* 18 */ GLFW_KEY_EQUAL, + /* 19 */ GLFW_KEY_9, + /* 1a */ GLFW_KEY_7, + /* 1b */ GLFW_KEY_MINUS, + /* 1c */ GLFW_KEY_8, + /* 1d */ GLFW_KEY_0, + /* 1e */ GLFW_KEY_RIGHT_BRACKET, + /* 1f */ GLFW_KEY_O, + /* 20 */ GLFW_KEY_U, + /* 21 */ GLFW_KEY_LEFT_BRACKET, + /* 22 */ GLFW_KEY_I, + /* 23 */ GLFW_KEY_P, + /* 24 */ GLFW_KEY_ENTER, + /* 25 */ GLFW_KEY_L, + /* 26 */ GLFW_KEY_J, + /* 27 */ GLFW_KEY_APOSTROPHE, + /* 28 */ GLFW_KEY_K, + /* 29 */ GLFW_KEY_SEMICOLON, + /* 2a */ GLFW_KEY_BACKSLASH, + /* 2b */ GLFW_KEY_COMMA, + /* 2c */ GLFW_KEY_SLASH, + /* 2d */ GLFW_KEY_N, + /* 2e */ GLFW_KEY_M, + /* 2f */ GLFW_KEY_PERIOD, + /* 30 */ GLFW_KEY_TAB, + /* 31 */ GLFW_KEY_SPACE, + /* 32 */ GLFW_KEY_WORLD_1, + /* 33 */ GLFW_KEY_BACKSPACE, + /* 34 */ -1, + /* 35 */ GLFW_KEY_ESCAPE, + /* 36 */ GLFW_KEY_RIGHT_SUPER, + /* 37 */ GLFW_KEY_LEFT_SUPER, + /* 38 */ GLFW_KEY_LEFT_SHIFT, + /* 39 */ GLFW_KEY_CAPS_LOCK, + /* 3a */ GLFW_KEY_LEFT_ALT, + /* 3b */ GLFW_KEY_LEFT_CONTROL, + /* 3c */ GLFW_KEY_RIGHT_SHIFT, + /* 3d */ GLFW_KEY_RIGHT_ALT, + /* 3e */ GLFW_KEY_RIGHT_CONTROL, + /* 3f */ -1, /* Function */ + /* 40 */ GLFW_KEY_F17, + /* 41 */ GLFW_KEY_KP_DECIMAL, + /* 42 */ -1, + /* 43 */ GLFW_KEY_KP_MULTIPLY, + /* 44 */ -1, + /* 45 */ GLFW_KEY_KP_ADD, + /* 46 */ -1, + /* 47 */ GLFW_KEY_NUM_LOCK, /* Really KeypadClear... */ + /* 48 */ -1, /* VolumeUp */ + /* 49 */ -1, /* VolumeDown */ + /* 4a */ -1, /* Mute */ + /* 4b */ GLFW_KEY_KP_DIVIDE, + /* 4c */ GLFW_KEY_KP_ENTER, + /* 4d */ -1, + /* 4e */ GLFW_KEY_KP_SUBTRACT, + /* 4f */ GLFW_KEY_F18, + /* 50 */ GLFW_KEY_F19, + /* 51 */ GLFW_KEY_KP_EQUAL, + /* 52 */ GLFW_KEY_KP_0, + /* 53 */ GLFW_KEY_KP_1, + /* 54 */ GLFW_KEY_KP_2, + /* 55 */ GLFW_KEY_KP_3, + /* 56 */ GLFW_KEY_KP_4, + /* 57 */ GLFW_KEY_KP_5, + /* 58 */ GLFW_KEY_KP_6, + /* 59 */ GLFW_KEY_KP_7, + /* 5a */ GLFW_KEY_F20, + /* 5b */ GLFW_KEY_KP_8, + /* 5c */ GLFW_KEY_KP_9, + /* 5d */ -1, + /* 5e */ -1, + /* 5f */ -1, + /* 60 */ GLFW_KEY_F5, + /* 61 */ GLFW_KEY_F6, + /* 62 */ GLFW_KEY_F7, + /* 63 */ GLFW_KEY_F3, + /* 64 */ GLFW_KEY_F8, + /* 65 */ GLFW_KEY_F9, + /* 66 */ -1, + /* 67 */ GLFW_KEY_F11, + /* 68 */ -1, + /* 69 */ GLFW_KEY_F13, + /* 6a */ GLFW_KEY_F16, + /* 6b */ GLFW_KEY_F14, + /* 6c */ -1, + /* 6d */ GLFW_KEY_F10, + /* 6e */ -1, + /* 6f */ GLFW_KEY_F12, + /* 70 */ -1, + /* 71 */ GLFW_KEY_F15, + /* 72 */ GLFW_KEY_INSERT, /* Really Help... */ + /* 73 */ GLFW_KEY_HOME, + /* 74 */ GLFW_KEY_PAGE_UP, + /* 75 */ GLFW_KEY_DELETE, + /* 76 */ GLFW_KEY_F4, + /* 77 */ GLFW_KEY_END, + /* 78 */ GLFW_KEY_F2, + /* 79 */ GLFW_KEY_PAGE_DOWN, + /* 7a */ GLFW_KEY_F1, + /* 7b */ GLFW_KEY_LEFT, + /* 7c */ GLFW_KEY_RIGHT, + /* 7d */ GLFW_KEY_DOWN, + /* 7e */ GLFW_KEY_UP, + /* 7f */ -1, + }; + if (macKeyCode >= 128) return -1; // This treats keycodes as *positional*; that is, we'll return 'a' // for the key left of 's', even on an AZERTY keyboard. The charInput // function should still get 'q' though. - return MAC_TO_GLFW_KEYCODE_MAPPING[macKeyCode]; + return table[macKeyCode]; } From 5fd66f7d3067e6504e9e18335688c226ce78c045 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 7 Mar 2012 18:38:08 +0100 Subject: [PATCH 069/226] Free visual list earlier. --- src/x11_fullscreen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/x11_fullscreen.c b/src/x11_fullscreen.c index e71c2a2b..f7855c4b 100644 --- a/src/x11_fullscreen.c +++ b/src/x11_fullscreen.c @@ -372,6 +372,8 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) } } + XFree(vislist); + rescount = 0; resarray = NULL; @@ -457,8 +459,6 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) } } - XFree(vislist); - free(resarray); free(rgbarray); From 18efa516a2ce62ea6f5131691ac66013f8d64442 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 8 Mar 2012 01:01:42 +0100 Subject: [PATCH 070/226] Added modes test. --- readme.html | 1 + tests/CMakeLists.txt | 5 +- tests/modes.c | 225 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 230 insertions(+), 1 deletion(-) create mode 100644 tests/modes.c diff --git a/readme.html b/readme.html index 5f3af632..8af1c2e4 100644 --- a/readme.html +++ b/readme.html @@ -280,6 +280,7 @@ version of GLFW.

  • Added windows simple multi-window test program
  • Added sharing simple OpenGL object sharing test program
  • Added dynamic simple dynamic linking test program
  • +
  • Added modes video mode enumeration and setting test program
  • Added a parameter to glfwOpenWindow for specifying a context the new window's context will share objects with
  • Added initial window title parameter to glfwOpenWindow
  • Added glfwSetGamma, glfwSetGammaRamp and glfwGetGammaRamp functions and GLFWgammaramp type for monitor gamma ramp control
  • diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 663f9a11..7a166881 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -36,6 +36,9 @@ target_link_libraries(joysticks ${STATIC_DEPS}) add_executable(listmodes listmodes.c) target_link_libraries(listmodes ${STATIC_DEPS}) +add_executable(modes modes.c getopt.c) +target_link_libraries(modes ${STATIC_DEPS}) + add_executable(peter peter.c) target_link_libraries(peter ${STATIC_DEPS}) @@ -64,7 +67,7 @@ set_target_properties(windows PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Windows") set(WINDOWS_BINARIES accuracy sharing tearing title windows) set(CONSOLE_BINARIES defaults events fsaa fsfocus gamma glfwinfo iconify - joysticks listmodes peter reopen) + joysticks listmodes modes peter reopen) if (MSVC) # Tell MSVC to use main instead of WinMain for Windows subsystem executables diff --git a/tests/modes.c b/tests/modes.c new file mode 100644 index 00000000..de3aec8a --- /dev/null +++ b/tests/modes.c @@ -0,0 +1,225 @@ +//======================================================================== +// Video mode test +// Copyright (c) Camilla Berglund +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would +// be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not +// be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. +// +//======================================================================== +// +// This test enumerates or verifies video modes +// +//======================================================================== + +#include + +#include +#include + +#include "getopt.h" + +static GLFWwindow window = NULL; + +enum Mode +{ + NO_MODE, + LIST_MODE, + TEST_MODE +}; + +static void usage(void) +{ + printf("Usage: modes -l\n"); + printf(" modes -t\n"); + printf(" modes -h\n"); +} + +static void print_mode(GLFWvidmode* mode) +{ + printf("%i x %i x %i (%i %i %i)", + mode->width, mode->height, + mode->redBits + mode->greenBits + mode->blueBits, + mode->redBits, mode->greenBits, mode->blueBits); +} + +static void error_callback(int error, const char* description) +{ + fprintf(stderr, "Error: %s\n", description); +} + +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) +{ + window = NULL; + return GL_TRUE; +} + +static void list_modes(GLFWvidmode* modes, int count) +{ + int i; + GLFWvidmode mode; + + glfwGetDesktopMode(&mode); + printf("Desktop mode: "); + print_mode(&mode); + putchar('\n'); + + for (i = 0; i < count; i++) + { + printf("%3i: ", i); + print_mode(modes + i); + putchar('\n'); + } +} + +static void test_modes(GLFWvidmode* modes, int count) +{ + int i, width, height; + + glfwSetWindowSizeCallback(window_size_callback); + glfwSetWindowCloseCallback(window_close_callback); + + for (i = 0; i < count; i++) + { + glfwOpenWindowHint(GLFW_RED_BITS, modes[i].redBits); + glfwOpenWindowHint(GLFW_GREEN_BITS, modes[i].greenBits); + glfwOpenWindowHint(GLFW_BLUE_BITS, modes[i].blueBits); + + printf("Opening "); + print_mode(modes + i); + printf(" window\n"); + + window = glfwOpenWindow(modes[i].width, modes[i].height, + GLFW_FULLSCREEN, "Video Mode Test", + NULL); + if (!window) + { + printf("Failed to enter mode %i: ", i); + print_mode(modes + i); + putchar('\n'); + continue; + } + + glfwSetTime(0.0); + glfwSwapInterval(1); + + while (glfwGetTime() < 5.0) + { + glClear(GL_COLOR_BUFFER_BIT); + glfwSwapBuffers(); + glfwPollEvents(); + + if (!window) + { + printf("User terminated program\n"); + exit(EXIT_SUCCESS); + } + } + + if (glfwGetWindowParam(window, GLFW_RED_BITS) != modes[i].redBits || + glfwGetWindowParam(window, GLFW_GREEN_BITS) != modes[i].greenBits || + glfwGetWindowParam(window, GLFW_BLUE_BITS) != modes[i].blueBits) + { + printf("*** Color bit mismatch: (%i %i %i) instead of (%i %i %i)\n", + glfwGetWindowParam(window, GLFW_RED_BITS), + glfwGetWindowParam(window, GLFW_GREEN_BITS), + glfwGetWindowParam(window, GLFW_BLUE_BITS), + modes[i].redBits, + modes[i].greenBits, + modes[i].blueBits); + } + + glfwGetWindowSize(window, &width, &height); + + if (width != modes[i].width || height != height) + { + printf("*** Size mismatch: %ix%i instead of %ix%i\n", + width, height, + modes[i].width, modes[i].height); + } + + printf("Closing window\n"); + + glfwCloseWindow(window); + glfwPollEvents(); + window = NULL; + + sleep(5); + } +} + +int main(int argc, char** argv) +{ + int ch, found, count = 0, mode = NO_MODE; + GLFWvidmode* modes = NULL; + + while ((ch = getopt(argc, argv, "lth")) != -1) + { + switch (ch) + { + case 'h': + usage(); + exit(EXIT_SUCCESS); + case 'l': + mode = LIST_MODE; + break; + case 't': + mode = TEST_MODE; + break; + default: + usage(); + exit(EXIT_FAILURE); + } + } + + argc -= optind; + argv += optind; + + glfwSetErrorCallback(error_callback); + + if (!glfwInit()) + exit(EXIT_FAILURE); + + for (;;) + { + count += 256; + modes = realloc(modes, sizeof(GLFWvidmode) * count); + + found = glfwGetVideoModes(modes, count); + if (found < count) + break; + } + + if (mode == LIST_MODE) + list_modes(modes, found); + else if (mode == TEST_MODE) + test_modes(modes, found); + + free(modes); + modes = NULL; + + exit(EXIT_SUCCESS); +} + From 21f2327e563f1b3c996bbb535d14daa417434edb Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sat, 10 Mar 2012 16:23:09 +0100 Subject: [PATCH 071/226] Formatting. --- src/input.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/input.c b/src/input.c index ec894a27..ded88712 100644 --- a/src/input.c +++ b/src/input.c @@ -167,7 +167,7 @@ void _glfwInputKey(_GLFWwindow* window, int key, int action) return; // Register key action - if(action == GLFW_RELEASE && window->stickyKeys) + if (action == GLFW_RELEASE && window->stickyKeys) window->key[key] = GLFW_STICK; else { From eb83a3e8f9ba5aa68e0a17a2c935be93cb6c5aeb Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 20 Mar 2012 15:23:35 +0100 Subject: [PATCH 072/226] Replaced final deprecated Core Graphics call. --- readme.html | 2 +- src/cocoa_init.m | 13 +++++++++++++ src/cocoa_platform.h | 1 + src/cocoa_window.m | 5 ----- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/readme.html b/readme.html index 5f3af632..bde16bcf 100644 --- a/readme.html +++ b/readme.html @@ -312,7 +312,7 @@ version of GLFW.

  • [Cocoa] Added support for joysticks
  • [Cocoa] Postponed menu creation to first window creation
  • [Cocoa] Replaced NSDate time source with mach_absolute_time
  • -
  • [Cocoa] Replaced deprecated CoreGraphics calls in video mode enumeration and setting
  • +
  • [Cocoa] Replaced all deprecated CoreGraphics calls with non-deprecated counterparts
  • [Cocoa] Bugfix: glfwOpenWindow did not properly enforce the forward-compatible and context profile hints
  • [Cocoa] Bugfix: The loop condition for saving video modes used the wrong index variable
  • [Cocoa] Bugfix: The OpenGL framework was not retrieved, making glfwGetProcAddress crash
  • diff --git a/src/cocoa_init.m b/src/cocoa_init.m index 89260c56..00898778 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -102,6 +102,13 @@ int _glfwPlatformInit(void) _glfwInitJoysticks(); + _glfwLibrary.NS.eventSource = CGEventSourceCreate(kCGEventSourceStateHIDSystemState); + if (!_glfwLibrary.NS.eventSource) + return GL_FALSE; + + CGEventSourceSetLocalEventsSuppressionInterval(_glfwLibrary.NS.eventSource, + 0.0); + return GL_TRUE; } @@ -113,6 +120,12 @@ int _glfwPlatformTerminate(void) { // TODO: Probably other cleanup + if (_glfwLibrary.NS.eventSource) + { + CFRelease(_glfwLibrary.NS.eventSource); + _glfwLibrary.NS.eventSource = NULL; + } + // Restore the original gamma ramp _glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp); diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index a06c13a0..b70fb184 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -93,6 +93,7 @@ typedef struct _GLFWlibraryNS // dlopen handle for dynamically loading OpenGL extension entry points void* OpenGLFramework; CGDisplayModeRef desktopMode; + CGEventSourceRef eventSource; id delegate; id autoreleasePool; } _GLFWlibraryNS; diff --git a/src/cocoa_window.m b/src/cocoa_window.m index c1d710c0..9d5ee5ec 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -1108,11 +1108,6 @@ void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y) // calculating the maximum y coordinate of all screens, since Cocoa's // "global coordinates" are upside down from CG's... - // Without this (once per app run, but it's convenient to do it here) - // events will be suppressed for a default of 0.25 seconds after we - // move the cursor. - CGSetLocalEventsSuppressionInterval(0.0); - NSPoint localPoint = NSMakePoint(x, y); NSPoint globalPoint = [window->NS.window convertBaseToScreen:localPoint]; CGPoint mainScreenOrigin = CGDisplayBounds(CGMainDisplayID()).origin; From c58750ef927579a60a8a58d9fc5253094e49424e Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 20 Mar 2012 15:30:46 +0100 Subject: [PATCH 073/226] Applied fix for pixel format creation failure. --- readme.html | 1 + src/cocoa_window.m | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.html b/readme.html index 33832689..0f0838de 100644 --- a/readme.html +++ b/readme.html @@ -314,6 +314,7 @@ version of GLFW.

  • [Cocoa] Postponed menu creation to first window creation
  • [Cocoa] Replaced NSDate time source with mach_absolute_time
  • [Cocoa] Replaced all deprecated CoreGraphics calls with non-deprecated counterparts
  • +
  • [Cocoa] Bugfix: The NSOpenGLPFAFullScreen pixel format attribute caused creation to fail on some machines
  • [Cocoa] Bugfix: glfwOpenWindow did not properly enforce the forward-compatible and context profile hints
  • [Cocoa] Bugfix: The loop condition for saving video modes used the wrong index variable
  • [Cocoa] Bugfix: The OpenGL framework was not retrieved, making glfwGetProcAddress crash
  • diff --git a/src/cocoa_window.m b/src/cocoa_window.m index dd548361..5bb33097 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -734,7 +734,6 @@ static GLboolean createContext(_GLFWwindow* window, if (wndconfig->mode == GLFW_FULLSCREEN) { - ADD_ATTR(NSOpenGLPFAFullScreen); ADD_ATTR(NSOpenGLPFANoRecovery); ADD_ATTR2(NSOpenGLPFAScreenMask, CGDisplayIDToOpenGLDisplayMask(CGMainDisplayID())); From 3a8b4b3a843d34a3a8d458b0ff59b4061dbdcc56 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 20 Mar 2012 15:44:25 +0100 Subject: [PATCH 074/226] Added credit. --- readme.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.html b/readme.html index 0f0838de..d7442d3b 100644 --- a/readme.html +++ b/readme.html @@ -823,6 +823,8 @@ their skills. Special thanks go out to:

      +
    • artblanc, for a patch replacing a deprecated Core Graphics call
    • +
    • Bobyshev Alexander and Martins Mozeiko, for the original proposal of an FSAA hint and their work on the Win32 implementation of FSAA
    • From df1af5ca7597899b3e254fe8cb58b42ea64a5368 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 20 Mar 2012 20:00:04 +0100 Subject: [PATCH 075/226] I am POSIXed. --- src/x11_time.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/x11_time.c b/src/x11_time.c index e2203941..4184d326 100644 --- a/src/x11_time.c +++ b/src/x11_time.c @@ -39,7 +39,7 @@ static uint64_t getRawTime(void) { -#if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK) +#if defined(CLOCK_MONOTONIC) if (_glfwLibrary.X11.timer.monotonic) { struct timespec ts; @@ -64,7 +64,7 @@ static uint64_t getRawTime(void) void _glfwInitTimer(void) { -#if defined(_POSIX_TIMERS) && defined(_POSIX_MONOTONIC_CLOCK) +#if defined(CLOCK_MONOTONIC) struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) From 742299faaaa5fc835219d5cc262a9e33614e33ac Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 22 Mar 2012 13:17:44 +0100 Subject: [PATCH 076/226] Merged implementation for Win32. --- readme.html | 3 +++ src/win32_platform.h | 1 + src/win32_window.c | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/readme.html b/readme.html index ea2d34da..fd788bae 100644 --- a/readme.html +++ b/readme.html @@ -846,6 +846,9 @@ their skills. Special thanks go out to:

    • Ralph Eastwood, for the initial design and implementation of the gamma correction API
    • +
    • GeO4d, for the implementation of cursor enter/leave notifications on + Win32.
    • +
    • Gerald Franz, who made GLFW compile under IRIX, and supplied patches for the X11 keyboard translation routine
    • diff --git a/src/win32_platform.h b/src/win32_platform.h index 82b8c9ca..aa551a09 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -268,6 +268,7 @@ typedef struct _GLFWwindowWin32 // Various platform specific internal variables int desiredRefreshRate; // Desired vertical monitor refresh rate GLboolean cursorCentered; + GLboolean cursorInside; int oldMouseX, oldMouseY; } _GLFWwindowWin32; diff --git a/src/win32_window.c b/src/win32_window.c index 0f3c67d0..66326278 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1021,6 +1021,26 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, _glfwInputCursorMotion(window, x, y); } + if (!window->Win32.cursorInside) + { + TRACKMOUSEEVENT tme; + ZeroMemory(&tme, sizeof(tme)); + tme.cbSize = sizeof(tme); + tme.dwFlags = TME_LEAVE; + tme.hwndTrack = window->Win32.handle; + TrackMouseEvent(&tme); + + window->Win32.cursorInside = GL_TRUE; + _glfwInputCursorEnter(window, GL_TRUE); + } + + return 0; + } + + case WM_MOUSELEAVE: + { + window->Win32.cursorInside = GL_FALSE; + _glfwInputCursorEnter(window, GL_FALSE); return 0; } From d976a7a86df4de24e20ba14ba99e5c5290b5705e Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 22 Mar 2012 14:27:19 +0100 Subject: [PATCH 077/226] Added Win32 library binaries. --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index fad26de1..0496a03c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,9 @@ src/libglfw.pc src/libglfw.so src/libglfw.a src/libglfw.dylib +src/glfw.lib +src/glfw.dll +src/glfwdll.lib examples/boing examples/gears examples/heightmap From 812ad163ebefa787437ecb6e5d58426b9e23f7d8 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 22 Mar 2012 14:29:23 +0100 Subject: [PATCH 078/226] Formatting. --- src/CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bdc4d5fe..7c66ba97 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,5 @@ -if(UNIX) +if (UNIX) if (_GLFW_HAS_XRANDR) set(GLFW_PKGLIBS "${GLFW_PKGLIBS} xrandr") endif() @@ -18,19 +18,19 @@ include_directories(${GLFW_SOURCE_DIR}/src set(common_SOURCES error.c fullscreen.c gamma.c init.c input.c joystick.c opengl.c time.c window.c) -if(_GLFW_COCOA_NSGL) +if (_GLFW_COCOA_NSGL) set(libglfw_SOURCES ${common_SOURCES} cocoa_fullscreen.m cocoa_gamma.c cocoa_init.m cocoa_input.m cocoa_joystick.m cocoa_opengl.m cocoa_time.c cocoa_window.m) # For some reason, CMake doesn't know about .m set_source_files_properties(${libglfw_SOURCES} PROPERTIES LANGUAGE C) -elseif(_GLFW_WIN32_WGL) +elseif (_GLFW_WIN32_WGL) set(libglfw_SOURCES ${common_SOURCES} 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) -elseif(_GLFW_X11_GLX) +elseif (_GLFW_X11_GLX) set(libglfw_SOURCES ${common_SOURCES} x11_fullscreen.c x11_gamma.c x11_init.c x11_input.c x11_joystick.c x11_keysym2unicode.c x11_opengl.c x11_time.c @@ -46,7 +46,7 @@ set_target_properties(libglfwStatic libglfwShared PROPERTIES CLEAN_DIRECT_OUTPUT 1 OUTPUT_NAME glfw) -if(WIN32) +if (WIN32) target_link_libraries(libglfwShared winmm) # The GLFW DLL needs a special compile-time macro and import library name set_target_properties(libglfwShared PROPERTIES @@ -56,7 +56,7 @@ if(WIN32) IMPORT_SUFFIX "dll.lib") endif() -if(APPLE) +if (APPLE) # Append -fno-common to the compile flags to work around a bug in the Apple GCC get_target_property(CFLAGS libglfwShared COMPILE_FLAGS) if (NOT CFLAGS) From 8d2c2791c2566109d91ff3033f7e81d10fdd4346 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 22 Mar 2012 14:58:14 +0100 Subject: [PATCH 079/226] Added initial Linux MinGW-w64 support. --- CMake/linux-amd64-mingw32msvc.cmake | 15 +++++++++++++++ include/GL/glfw3.h | 6 ++++++ src/win32_init.c | 4 ++-- src/win32_platform.h | 2 ++ 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 CMake/linux-amd64-mingw32msvc.cmake diff --git a/CMake/linux-amd64-mingw32msvc.cmake b/CMake/linux-amd64-mingw32msvc.cmake new file mode 100644 index 00000000..5b68540e --- /dev/null +++ b/CMake/linux-amd64-mingw32msvc.cmake @@ -0,0 +1,15 @@ +# Define the cross compilation environment for cross compiling from linux +# to Win64 it is to be used when Debian cross compilation toolchain is +# available. +SET(CMAKE_SYSTEM_NAME Windows) # Target system name +SET(CMAKE_SYSTEM_VERSION 1) # Not really used. +SET(CMAKE_C_COMPILER "amd64-mingw32msvc-gcc") +SET(CMAKE_CXX_COMPILER "amd64-mingw32msvc-g++") +SET(CMAKE_RANLIB "amd64-mingw32msvc-ranlib") + + +#Configure the behaviour of the find commands +SET(CMAKE_FIND_ROOT_PATH "/usr/amd64-mingw32msvc") +SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index cc817521..44e26b62 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -67,6 +67,12 @@ extern "C" { #endif #endif /* APIENTRY */ +/* TEMPORARY MinGW-w64 hacks. + */ +#if __MINGW64__ + #define WINAPI +#include +#endif /* The following three defines are here solely to make some Windows-based * files happy. Theoretically we could include , but diff --git a/src/win32_init.c b/src/win32_init.c index 4e1b7863..4fab9b74 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -200,7 +200,7 @@ int _glfwPlatformInit(void) // as possible in the hope of still being the foreground process) SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, &_glfwLibrary.Win32.foregroundLockTimeout, 0); - SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID) 0, + SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, UIntToPtr(0), SPIF_SENDCHANGE); if (!initLibraries()) @@ -246,7 +246,7 @@ int _glfwPlatformTerminate(void) // Restore previous FOREGROUNDLOCKTIMEOUT system setting SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, - (LPVOID) _glfwLibrary.Win32.foregroundLockTimeout, + UIntToPtr(_glfwLibrary.Win32.foregroundLockTimeout), SPIF_SENDCHANGE); return GL_TRUE; diff --git a/src/win32_platform.h b/src/win32_platform.h index 82b8c9ca..0f6362c1 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -51,7 +51,9 @@ #endif // GLFW requires Windows XP +#ifndef WINVER #define WINVER 0x0501 +#endif #include #include From d204d5a434f51b0ddaab6537bd7acff0e288c55b Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 22 Mar 2012 23:25:39 +0100 Subject: [PATCH 080/226] Enabled all warnings on GNU C and compatibles. --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f27cf7cd..57b8755f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,10 @@ option(GLFW_BUILD_TESTS "Build the GLFW test programs" ON) find_package(OpenGL REQUIRED) +if (CMAKE_COMPILER_IS_GNUCC) + add_definitions(-Wall) +endif() + #-------------------------------------------------------------------- # Set up GLFW for Win32 and WGL on Windows #-------------------------------------------------------------------- From 08942fcabe4474310a0d57176ae10b7842451276 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 22 Mar 2012 23:28:43 +0100 Subject: [PATCH 081/226] Removed call to non-portable function. --- tests/modes.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/modes.c b/tests/modes.c index de3aec8a..9c558d47 100644 --- a/tests/modes.c +++ b/tests/modes.c @@ -165,8 +165,6 @@ static void test_modes(GLFWvidmode* modes, int count) glfwCloseWindow(window); glfwPollEvents(); window = NULL; - - sleep(5); } } From c2a2114590ed289a14e64fcce614b852237f7b0f Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 22 Mar 2012 23:30:00 +0100 Subject: [PATCH 082/226] Fixed GCC warnings. --- src/x11_fullscreen.c | 2 +- src/x11_init.c | 4 ++-- src/x11_time.c | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/x11_fullscreen.c b/src/x11_fullscreen.c index f7855c4b..37a3ae98 100644 --- a/src/x11_fullscreen.c +++ b/src/x11_fullscreen.c @@ -323,7 +323,7 @@ struct _glfwResolution int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) { int count, k, l, r, g, b, rgba, gl; - int depth, screen; + int depth, screen = DefaultScreen(_glfwLibrary.X11.display); XVisualInfo* vislist; XVisualInfo dummy; int viscount, rgbcount, rescount; diff --git a/src/x11_init.c b/src/x11_init.c index 3ed9ab13..d57af27e 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -470,8 +470,8 @@ static void initGammaRamp(void) // RandR gamma support is only available with version 1.2 and above if (_glfwLibrary.X11.RandR.available && (_glfwLibrary.X11.RandR.majorVersion > 1 || - _glfwLibrary.X11.RandR.majorVersion == 1 && - _glfwLibrary.X11.RandR.minorVersion >= 2)) + (_glfwLibrary.X11.RandR.majorVersion == 1 && + _glfwLibrary.X11.RandR.minorVersion >= 2))) { // FIXME: Assumes that all monitors have the same size gamma tables // This is reasonable as I suspect the that if they did differ, it diff --git a/src/x11_time.c b/src/x11_time.c index 4184d326..f1445233 100644 --- a/src/x11_time.c +++ b/src/x11_time.c @@ -30,6 +30,7 @@ #include "internal.h" +#include #include From 29d38c3b649cbe5fecd315bab47c263852e24d2e Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 23 Mar 2012 15:27:50 +0100 Subject: [PATCH 083/226] Increased Cocoa pixel format attribute array size. --- src/cocoa_window.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 5bb33097..98c220ed 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -728,7 +728,7 @@ static GLboolean createContext(_GLFWwindow* window, #define ADD_ATTR2(x, y) { ADD_ATTR(x); ADD_ATTR(y); } // Arbitrary array size here - NSOpenGLPixelFormatAttribute attributes[24]; + NSOpenGLPixelFormatAttribute attributes[40]; ADD_ATTR(NSOpenGLPFADoubleBuffer); From c175084e1310abdd98e5560416bf6e484cc113a1 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 25 Mar 2012 13:47:13 +0200 Subject: [PATCH 084/226] Added workaround for CMake bug 0006976. --- CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 57b8755f..d30b1ee0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,14 @@ if (UNIX AND NOT APPLE) if (X11_xf86vmode_FOUND) set(_GLFW_HAS_XF86VIDMODE 1) list(APPEND GLFW_INCLUDE_DIR ${X11_xf86vmode_INCLUDE_PATH}) + + # NOTE: This is a workaround for CMake bug 0006976 (missing + # X11_xf86vmode_LIB variable) + if (X11_xf86vmode_LIB) + list(APPEND GLFW_LIBRARIES ${X11_xf86vmode_LIB}) + else() + list(APPEND GLFW_LIBRARIES Xxf86vm) + endif() endif() # Check for Xkb (X keyboard extension) From 7f1d91e67b9904a6c64f3aab1f9df1da3603b8be Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 25 Mar 2012 13:49:35 +0200 Subject: [PATCH 085/226] Formatting. --- CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d30b1ee0..d09ba186 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,7 +120,7 @@ if (UNIX AND APPLE) # Define the platform identifier set(_GLFW_COCOA_NSGL 1) - option(GLFW_BUILD_UNIVERSAL "Build the GLFW library and examples as Universal Binaries" FALSE) + option(GLFW_BUILD_UNIVERSAL "Build GLFW as a Universal Binary" OFF) # Universal build if (GLFW_BUILD_UNIVERSAL) @@ -136,10 +136,10 @@ if (UNIX AND APPLE) find_library(COCOA_FRAMEWORK Cocoa) find_library(IOKIT_FRAMEWORK IOKit) find_library(CORE_FOUNDATION_FRAMEWORK CoreFoundation) - list(APPEND GLFW_LIBRARIES ${COCOA_FRAMEWORK}) - list(APPEND GLFW_LIBRARIES ${OPENGL_gl_LIBRARY}) - list(APPEND GLFW_LIBRARIES ${IOKIT_FRAMEWORK}) - list(APPEND GLFW_LIBRARIES ${CORE_FOUNDATION_FRAMEWORK}) + list(APPEND GLFW_LIBRARIES ${COCOA_FRAMEWORK} + ${OPENGL_gl_LIBRARY} + ${IOKIT_FRAMEWORK} + ${CORE_FOUNDATION_FRAMEWORK}) endif() #-------------------------------------------------------------------- From f21f196036234077083ac9d70d536b773cde0307 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 25 Mar 2012 13:52:35 +0200 Subject: [PATCH 086/226] Added comment. --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index d09ba186..fc9fa103 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,9 @@ option(GLFW_BUILD_TESTS "Build the GLFW test programs" ON) find_package(OpenGL REQUIRED) +#-------------------------------------------------------------------- +# Enable all warnings on GCC, regardless of OS +#-------------------------------------------------------------------- if (CMAKE_COMPILER_IS_GNUCC) add_definitions(-Wall) endif() From 7b46a184cb0d1637ebb416b9ed578cbf2142046e Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 25 Mar 2012 13:53:53 +0200 Subject: [PATCH 087/226] Added standard option to switch between static and dynamic library, dropped dynamic test. --- CMakeLists.txt | 5 +++ examples/CMakeLists.txt | 12 ++++-- readme.html | 1 - src/CMakeLists.txt | 45 ++++++++++---------- tests/CMakeLists.txt | 40 ++++-------------- tests/dynamic.c | 91 ----------------------------------------- 6 files changed, 43 insertions(+), 151 deletions(-) delete mode 100644 tests/dynamic.c diff --git a/CMakeLists.txt b/CMakeLists.txt index fc9fa103..509ce57f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,7 @@ set(GLFW_VERSION_FULL "${GLFW_VERSION}.${GLFW_VERSION_PATCH}${GLFW_VERSION_EXTRA option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" ON) option(GLFW_BUILD_TESTS "Build the GLFW test programs" ON) +option(BUILD_SHARED_LIBS "Build shared libraries" OFF) find_package(OpenGL REQUIRED) @@ -33,6 +34,10 @@ if (WIN32) # Set up library and include paths list(APPEND GLFW_INCLUDE_DIR ${OPENGL_INCLUDE_DIR}) list(APPEND GLFW_LIBRARIES ${OPENGL_gl_LIBRARY}) + + if (BUILD_SHARED_LIBS) + list(APPEND GLFW_LIBRARIES winmm) + endif() endif() #-------------------------------------------------------------------- diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index a644b987..b677addd 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,7 +1,11 @@ -# This line is used to link with static libraries -# Note that the library list should be updated to be obtained from -# the main CMakeLists.txt -link_libraries(libglfwStatic ${GLFW_LIBRARIES} ${OPENGL_glu_LIBRARY}) + +link_libraries(glfw ${OPENGL_glu_LIBRARY}) + +if (BUILD_SHARED_LIBS) + add_definitions(-DGLFW_DLL) +else() + link_libraries(${GLFW_LIBRARIES}) +endif() include_directories(${GLFW_SOURCE_DIR}/include ${GLFW_SOURCE_DIR}/support diff --git a/readme.html b/readme.html index d7442d3b..84cc2a66 100644 --- a/readme.html +++ b/readme.html @@ -279,7 +279,6 @@ version of GLFW.

    • Added GLFW_INCLUDE_GL3 macro for telling the GLFW header to include gl3.h header instead of gl.h
    • Added windows simple multi-window test program
    • Added sharing simple OpenGL object sharing test program
    • -
    • Added dynamic simple dynamic linking test program
    • Added modes video mode enumeration and setting test program
    • Added a parameter to glfwOpenWindow for specifying a context the new window's context will share objects with
    • Added initial window title parameter to glfwOpenWindow
    • diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7c66ba97..e508f259 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -39,31 +39,32 @@ else() message(FATAL_ERROR "No supported platform was selected") endif() -add_library(libglfwStatic STATIC ${libglfw_SOURCES}) -add_library(libglfwShared SHARED ${libglfw_SOURCES}) -target_link_libraries(libglfwShared ${GLFW_LIBRARIES}) -set_target_properties(libglfwStatic libglfwShared PROPERTIES - CLEAN_DIRECT_OUTPUT 1 - OUTPUT_NAME glfw) +add_library(glfw ${libglfw_SOURCES}) -if (WIN32) - target_link_libraries(libglfwShared winmm) - # The GLFW DLL needs a special compile-time macro and import library name - set_target_properties(libglfwShared PROPERTIES - COMPILE_DEFINITIONS "GLFW_BUILD_DLL;_GLFW_NO_DLOAD_GDI32;_GLFW_NO_DLOAD_WINMM" - PREFIX "" - IMPORT_PREFIX "" - IMPORT_SUFFIX "dll.lib") -endif() +if (BUILD_SHARED_LIBS) -if (APPLE) - # Append -fno-common to the compile flags to work around a bug in the Apple GCC - get_target_property(CFLAGS libglfwShared COMPILE_FLAGS) - if (NOT CFLAGS) - set(CFLAGS "") + if (WIN32) + # The GLFW DLL needs a special compile-time macro and import library name + set_target_properties(glfw PROPERTIES + COMPILE_DEFINITIONS "GLFW_BUILD_DLL;_GLFW_NO_DLOAD_GDI32;_GLFW_NO_DLOAD_WINMM" + PREFIX "" + IMPORT_PREFIX "" + IMPORT_SUFFIX "dll.lib") endif() - set_target_properties(libglfwShared PROPERTIES COMPILE_FLAGS "${CFLAGS} -fno-common") + + if (APPLE) + # Append -fno-common to the compile flags to work around a bug in the Apple GCC + get_target_property(CFLAGS glfw COMPILE_FLAGS) + if (NOT CFLAGS) + set(CFLAGS "") + endif() + set_target_properties(glfw PROPERTIES COMPILE_FLAGS "${CFLAGS} -fno-common") + endif() + + target_link_libraries(glfw ${GLFW_LIBRARIES}) + target_link_libraries(glfw LINK_INTERFACE_LIBRARIES) + endif() -install(TARGETS libglfwStatic libglfwShared DESTINATION lib) +install(TARGETS glfw DESTINATION lib) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7a166881..43db9d22 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,68 +1,42 @@ -set(STATIC_DEPS libglfwStatic ${GLFW_LIBRARIES} ${OPENGL_glu_LIBRARY}) -set(SHARED_DEPS libglfwShared ${GLFW_LIBRARIES} ${OPENGL_glu_LIBRARY}) +link_libraries(glfw ${OPENGL_glu_LIBRARY}) + +if (BUILD_SHARED_LIBS) + add_definitions(-DGLFW_DLL) +else() + link_libraries(${GLFW_LIBRARIES}) +endif() include_directories(${GLFW_SOURCE_DIR}/include ${GLFW_SOURCE_DIR}/support ${OPENGL_INCLUDE_DIR}) add_executable(defaults defaults.c) -target_link_libraries(defaults ${STATIC_DEPS}) - -add_executable(dynamic dynamic.c) -target_link_libraries(dynamic ${SHARED_DEPS}) - add_executable(events events.c) -target_link_libraries(events ${STATIC_DEPS}) - add_executable(fsaa fsaa.c getopt.c) -target_link_libraries(fsaa ${STATIC_DEPS}) - add_executable(fsfocus fsfocus.c) -target_link_libraries(fsfocus ${STATIC_DEPS}) - add_executable(gamma gamma.c getopt.c) -target_link_libraries(gamma ${STATIC_DEPS}) - add_executable(glfwinfo glfwinfo.c getopt.c) -target_link_libraries(glfwinfo ${STATIC_DEPS}) - add_executable(iconify iconify.c getopt.c) -target_link_libraries(iconify ${STATIC_DEPS}) - add_executable(joysticks joysticks.c) -target_link_libraries(joysticks ${STATIC_DEPS}) - add_executable(listmodes listmodes.c) -target_link_libraries(listmodes ${STATIC_DEPS}) - add_executable(modes modes.c getopt.c) -target_link_libraries(modes ${STATIC_DEPS}) - add_executable(peter peter.c) -target_link_libraries(peter ${STATIC_DEPS}) - add_executable(reopen reopen.c) -target_link_libraries(reopen ${STATIC_DEPS}) add_executable(accuracy WIN32 MACOSX_BUNDLE accuracy.c) -target_link_libraries(accuracy ${STATIC_DEPS}) set_target_properties(accuracy PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Accuracy") add_executable(sharing WIN32 MACOSX_BUNDLE sharing.c) -target_link_libraries(sharing ${STATIC_DEPS}) set_target_properties(sharing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Sharing") add_executable(tearing WIN32 MACOSX_BUNDLE tearing.c) -target_link_libraries(tearing ${STATIC_DEPS}) set_target_properties(tearing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Tearing") add_executable(title WIN32 MACOSX_BUNDLE title.c) -target_link_libraries(title ${STATIC_DEPS}) set_target_properties(title PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Title") add_executable(windows WIN32 MACOSX_BUNDLE windows.c) -target_link_libraries(windows ${STATIC_DEPS}) set_target_properties(windows PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Windows") set(WINDOWS_BINARIES accuracy sharing tearing title windows) diff --git a/tests/dynamic.c b/tests/dynamic.c deleted file mode 100644 index 8bc5568b..00000000 --- a/tests/dynamic.c +++ /dev/null @@ -1,91 +0,0 @@ -//======================================================================== -// Dynamic linking test -// Copyright (c) Camilla Berglund -// -// This software is provided 'as-is', without any express or implied -// warranty. In no event will the authors be held liable for any damages -// arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it -// freely, subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; you must not -// claim that you wrote the original software. If you use this software -// in a product, an acknowledgment in the product documentation would -// be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, and must not -// be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source -// distribution. -// -//======================================================================== -// -// This test came about as the result of bug #3060461 -// -//======================================================================== - -#define GLFW_DLL -#include - -#include -#include - -static void window_size_callback(GLFWwindow window, int width, int height) -{ - glViewport(0, 0, width, height); -} - -int main(void) -{ - GLFWwindow window; - int major, minor, rev; - glfwGetVersion(&major, &minor, &rev); - - printf("GLFW header version: %i.%i.%i\n", - GLFW_VERSION_MAJOR, - GLFW_VERSION_MINOR, - GLFW_VERSION_REVISION); - printf("GLFW library version: %i.%i.%i\n", major, minor, rev); - printf("GLFW library version string: %s\n", glfwGetVersionString()); - - if (major != GLFW_VERSION_MAJOR || - minor != GLFW_VERSION_MINOR || - rev != GLFW_VERSION_REVISION) - { - fprintf(stderr, "GLFW library version mismatch\n"); - exit(EXIT_FAILURE); - } - - if (!glfwInit()) - { - fprintf(stderr, "Failed to initialize GLFW\n"); - exit(EXIT_FAILURE); - } - - window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Dynamic Linking Test", NULL); - if (!window) - { - glfwTerminate(); - - fprintf(stderr, "Failed to open GLFW window\n"); - exit(EXIT_FAILURE); - } - - glfwSetWindowSizeCallback(window_size_callback); - glfwSwapInterval(1); - - while (glfwIsWindow(window)) - { - glClear(GL_COLOR_BUFFER_BIT); - - glfwSwapBuffers(); - glfwPollEvents(); - } - - glfwTerminate(); - exit(EXIT_SUCCESS); -} - From 23776f67e3708883dad557d1e0ed748f0bf3a7ac Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 25 Mar 2012 13:58:07 +0200 Subject: [PATCH 088/226] Formatting. --- CMakeLists.txt | 2 +- examples/CMakeLists.txt | 4 ++-- tests/CMakeLists.txt | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 509ce57f..2cd65cb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,7 @@ find_package(OpenGL REQUIRED) # Enable all warnings on GCC, regardless of OS #-------------------------------------------------------------------- if (CMAKE_COMPILER_IS_GNUCC) - add_definitions(-Wall) + add_definitions(-Wall) endif() #-------------------------------------------------------------------- diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index b677addd..2bdd95e9 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -2,9 +2,9 @@ link_libraries(glfw ${OPENGL_glu_LIBRARY}) if (BUILD_SHARED_LIBS) - add_definitions(-DGLFW_DLL) + add_definitions(-DGLFW_DLL) else() - link_libraries(${GLFW_LIBRARIES}) + link_libraries(${GLFW_LIBRARIES}) endif() include_directories(${GLFW_SOURCE_DIR}/include diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 43db9d22..f6749e54 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,9 +2,9 @@ link_libraries(glfw ${OPENGL_glu_LIBRARY}) if (BUILD_SHARED_LIBS) - add_definitions(-DGLFW_DLL) + add_definitions(-DGLFW_DLL) else() - link_libraries(${GLFW_LIBRARIES}) + link_libraries(${GLFW_LIBRARIES}) endif() include_directories(${GLFW_SOURCE_DIR}/include From 9e8f5477748814f87ddc362df264b2dc01448bdd Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 25 Mar 2012 13:59:34 +0200 Subject: [PATCH 089/226] Formatting. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2cd65cb3..85311188 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -177,7 +177,7 @@ install(DIRECTORY include/GL DESTINATION include FILES_MATCHING PATTERN glfw3.h) install(FILES COPYING.txt readme.html - DESTINATION share/doc/glfw-${GLFW_VERSION_FULL}/) + DESTINATION share/doc/glfw-${GLFW_VERSION_FULL}) # The src directory's CMakeLists.txt file installs the library From 4a905d2e28144d6deeb962e4d073386b798a328b Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 25 Mar 2012 14:43:23 +0200 Subject: [PATCH 090/226] Comment update. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 85311188..f5b08c1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,6 +68,7 @@ if (UNIX AND NOT APPLE) include(CheckFunctionExists) include(CheckSymbolExists) + # This is needed by the GLX function checks below set(CMAKE_REQUIRED_LIBRARIES ${GLFW_LIBRARIES}) # Check for XRandR (modern resolution switching extension) @@ -97,7 +98,6 @@ if (UNIX AND NOT APPLE) list(APPEND GLFW_INCLUDE_DIR ${X11_Xkb_INCLUDE_PATH}) endif() - # Check for glXGetProcAddress check_function_exists(glXGetProcAddress _GLFW_HAS_GLXGETPROCADDRESS) if (NOT _GLFW_HAS_GLXGETPROCADDRESS) From d743793e71ad3b0089a39f443c75391b832c3ee4 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 25 Mar 2012 14:51:56 +0200 Subject: [PATCH 091/226] Pkg-config dependency generation fixes. --- CMakeLists.txt | 25 ++++++++++++++++--------- src/CMakeLists.txt | 9 ++------- src/libglfw.pc.cmake | 2 +- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f5b08c1e..5aa640b7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,15 +55,7 @@ if (UNIX AND NOT APPLE) list(APPEND GLFW_INCLUDE_DIR ${X11_X11_INCLUDE_PATH} ${OPENGL_INCLUDE_DIR}) list(APPEND GLFW_LIBRARIES ${X11_X11_LIB} ${OPENGL_gl_LIBRARY}) - find_library(MATH_LIBRARY m) - if (MATH_LIBRARY) - list(APPEND GLFW_LIBRARIES ${MATH_LIBRARY}) - endif() - - find_library(RT_LIBRARY rt) - if (RT_LIBRARY) - list(APPEND GLFW_LIBRARIES ${RT_LIBRARY}) - endif() + set(GLFW_PKGLIBS "gl x11") include(CheckFunctionExists) include(CheckSymbolExists) @@ -76,6 +68,7 @@ if (UNIX AND NOT APPLE) set(_GLFW_HAS_XRANDR 1) list(APPEND GLFW_INCLUDE_DIR ${X11_Xrandr_INCLUDE_PATH}) list(APPEND GLFW_LIBRARIES ${X11_Xrandr_LIB}) + set(GLFW_PKGLIBS "${GLFW_PKGLIBS} xrandr") endif() # Check for Xf86VidMode (fallback legacy resolution switching extension) @@ -90,6 +83,8 @@ if (UNIX AND NOT APPLE) else() list(APPEND GLFW_LIBRARIES Xxf86vm) endif() + + set(GLFW_PKGLIBS "${GLFW_PKGLIBS} xxf86vm") endif() # Check for Xkb (X keyboard extension) @@ -98,6 +93,18 @@ if (UNIX AND NOT APPLE) list(APPEND GLFW_INCLUDE_DIR ${X11_Xkb_INCLUDE_PATH}) endif() + find_library(RT_LIBRARY rt) + if (RT_LIBRARY) + list(APPEND GLFW_LIBRARIES ${RT_LIBRARY}) + set(GLFW_PKGLIBS "${GLFW_PKGLIBS} rt") + endif() + + find_library(MATH_LIBRARY m) + if (MATH_LIBRARY) + list(APPEND GLFW_LIBRARIES ${MATH_LIBRARY}) + set(GLFW_PKGLIBS "${GLFW_PKGLIBS} m") + endif() + check_function_exists(glXGetProcAddress _GLFW_HAS_GLXGETPROCADDRESS) if (NOT _GLFW_HAS_GLXGETPROCADDRESS) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e508f259..aa7fbf30 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,14 +1,9 @@ if (UNIX) - if (_GLFW_HAS_XRANDR) - set(GLFW_PKGLIBS "${GLFW_PKGLIBS} xrandr") - endif() - if (_GLFW_HAS_XF86VIDMODE) - set(GLFW_PKGLIBS "${GLFW_PKGLIBS} xxf86vm") - endif() configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libglfw.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc @ONLY) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc DESTINATION lib/pkgconfig) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc + DESTINATION lib/pkgconfig) endif() include_directories(${GLFW_SOURCE_DIR}/src diff --git a/src/libglfw.pc.cmake b/src/libglfw.pc.cmake index 47cfb4f5..164fdc26 100644 --- a/src/libglfw.pc.cmake +++ b/src/libglfw.pc.cmake @@ -7,6 +7,6 @@ Name: GLFW Description: A portable library for OpenGL, window and input Version: 3.0.0 URL: http://www.glfw.org/ -Requires.private: gl x11 @GLFW_PKGLIBS@ +Requires.private: @GLFW_PKGLIBS@ Libs: -L${libdir} -lglfw Cflags: -I${includedir} From 441452467a7127affa5957cdb24e184963b001c6 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 25 Mar 2012 15:05:48 +0200 Subject: [PATCH 092/226] Marked library variables as advanced. --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5aa640b7..d1034aad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,12 +94,14 @@ if (UNIX AND NOT APPLE) endif() find_library(RT_LIBRARY rt) + mark_as_advanced(RT_LIBRARY) if (RT_LIBRARY) list(APPEND GLFW_LIBRARIES ${RT_LIBRARY}) set(GLFW_PKGLIBS "${GLFW_PKGLIBS} rt") endif() find_library(MATH_LIBRARY m) + mark_as_advanced(MATH_LIBRARY) if (MATH_LIBRARY) list(APPEND GLFW_LIBRARIES ${MATH_LIBRARY}) set(GLFW_PKGLIBS "${GLFW_PKGLIBS} m") From 20e685d37bbfc5c377b085148fb2d66c8cd92abe Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 25 Mar 2012 16:34:36 +0200 Subject: [PATCH 093/226] Formatted variables not used outside of the local CMake project. --- CMakeLists.txt | 30 +++++++++++++++--------------- src/CMakeLists.txt | 39 ++++++++++++++++++++------------------- 2 files changed, 35 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d1034aad..e7149dd6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,11 +32,11 @@ if (WIN32) set(_GLFW_WIN32_WGL 1) # Set up library and include paths - list(APPEND GLFW_INCLUDE_DIR ${OPENGL_INCLUDE_DIR}) - list(APPEND GLFW_LIBRARIES ${OPENGL_gl_LIBRARY}) + list(APPEND glfw_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR}) + list(APPEND glfw_LIBRARIES ${OPENGL_gl_LIBRARY}) if (BUILD_SHARED_LIBS) - list(APPEND GLFW_LIBRARIES winmm) + list(APPEND glfw_LIBRARIES winmm) endif() endif() @@ -52,8 +52,8 @@ if (UNIX AND NOT APPLE) find_package(X11 REQUIRED) # Set up library and include paths - list(APPEND GLFW_INCLUDE_DIR ${X11_X11_INCLUDE_PATH} ${OPENGL_INCLUDE_DIR}) - list(APPEND GLFW_LIBRARIES ${X11_X11_LIB} ${OPENGL_gl_LIBRARY}) + list(APPEND glfw_INCLUDE_DIRS ${X11_X11_INCLUDE_PATH} ${OPENGL_INCLUDE_DIR}) + list(APPEND glfw_LIBRARIES ${X11_X11_LIB} ${OPENGL_gl_LIBRARY}) set(GLFW_PKGLIBS "gl x11") @@ -61,27 +61,27 @@ if (UNIX AND NOT APPLE) include(CheckSymbolExists) # This is needed by the GLX function checks below - set(CMAKE_REQUIRED_LIBRARIES ${GLFW_LIBRARIES}) + set(CMAKE_REQUIRED_LIBRARIES ${glfw_LIBRARIES}) # Check for XRandR (modern resolution switching extension) if (X11_Xrandr_FOUND) set(_GLFW_HAS_XRANDR 1) - list(APPEND GLFW_INCLUDE_DIR ${X11_Xrandr_INCLUDE_PATH}) - list(APPEND GLFW_LIBRARIES ${X11_Xrandr_LIB}) + list(APPEND glfw_INCLUDE_DIRS ${X11_Xrandr_INCLUDE_PATH}) + list(APPEND glfw_LIBRARIES ${X11_Xrandr_LIB}) set(GLFW_PKGLIBS "${GLFW_PKGLIBS} xrandr") endif() # Check for Xf86VidMode (fallback legacy resolution switching extension) if (X11_xf86vmode_FOUND) set(_GLFW_HAS_XF86VIDMODE 1) - list(APPEND GLFW_INCLUDE_DIR ${X11_xf86vmode_INCLUDE_PATH}) + list(APPEND glfw_INCLUDE_DIRS ${X11_xf86vmode_INCLUDE_PATH}) # NOTE: This is a workaround for CMake bug 0006976 (missing # X11_xf86vmode_LIB variable) if (X11_xf86vmode_LIB) - list(APPEND GLFW_LIBRARIES ${X11_xf86vmode_LIB}) + list(APPEND glfw_LIBRARIES ${X11_xf86vmode_LIB}) else() - list(APPEND GLFW_LIBRARIES Xxf86vm) + list(APPEND glfw_LIBRARIES Xxf86vm) endif() set(GLFW_PKGLIBS "${GLFW_PKGLIBS} xxf86vm") @@ -90,20 +90,20 @@ if (UNIX AND NOT APPLE) # Check for Xkb (X keyboard extension) if (X11_Xkb_FOUND) set(_GLFW_HAS_XKB 1) - list(APPEND GLFW_INCLUDE_DIR ${X11_Xkb_INCLUDE_PATH}) + list(APPEND glfw_INCLUDE_DIR ${X11_Xkb_INCLUDE_PATH}) endif() find_library(RT_LIBRARY rt) mark_as_advanced(RT_LIBRARY) if (RT_LIBRARY) - list(APPEND GLFW_LIBRARIES ${RT_LIBRARY}) + list(APPEND glfw_LIBRARIES ${RT_LIBRARY}) set(GLFW_PKGLIBS "${GLFW_PKGLIBS} rt") endif() find_library(MATH_LIBRARY m) mark_as_advanced(MATH_LIBRARY) if (MATH_LIBRARY) - list(APPEND GLFW_LIBRARIES ${MATH_LIBRARY}) + list(APPEND glfw_LIBRARIES ${MATH_LIBRARY}) set(GLFW_PKGLIBS "${GLFW_PKGLIBS} m") endif() @@ -153,7 +153,7 @@ if (UNIX AND APPLE) find_library(COCOA_FRAMEWORK Cocoa) find_library(IOKIT_FRAMEWORK IOKit) find_library(CORE_FOUNDATION_FRAMEWORK CoreFoundation) - list(APPEND GLFW_LIBRARIES ${COCOA_FRAMEWORK} + list(APPEND glfw_LIBRARIES ${COCOA_FRAMEWORK} ${OPENGL_gl_LIBRARY} ${IOKIT_FRAMEWORK} ${CORE_FOUNDATION_FRAMEWORK}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index aa7fbf30..3f692cf8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,33 +8,33 @@ endif() include_directories(${GLFW_SOURCE_DIR}/src ${GLFW_BINARY_DIR}/src - ${GLFW_INCLUDE_DIR}) + ${glfw_INCLUDE_DIRS}) set(common_SOURCES error.c fullscreen.c gamma.c init.c input.c joystick.c opengl.c time.c window.c) if (_GLFW_COCOA_NSGL) - set(libglfw_SOURCES ${common_SOURCES} cocoa_fullscreen.m cocoa_gamma.c - cocoa_init.m cocoa_input.m cocoa_joystick.m - cocoa_opengl.m cocoa_time.c cocoa_window.m) + set(glfw_SOURCES ${common_SOURCES} cocoa_fullscreen.m cocoa_gamma.c + cocoa_init.m cocoa_input.m cocoa_joystick.m + cocoa_opengl.m cocoa_time.c cocoa_window.m) # For some reason, CMake doesn't know about .m - set_source_files_properties(${libglfw_SOURCES} PROPERTIES LANGUAGE C) + set_source_files_properties(${glfw_SOURCES} PROPERTIES LANGUAGE C) elseif (_GLFW_WIN32_WGL) - set(libglfw_SOURCES ${common_SOURCES} 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) + set(glfw_SOURCES ${common_SOURCES} 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) elseif (_GLFW_X11_GLX) - set(libglfw_SOURCES ${common_SOURCES} x11_fullscreen.c x11_gamma.c - x11_init.c x11_input.c x11_joystick.c - x11_keysym2unicode.c x11_opengl.c x11_time.c - x11_window.c) + set(glfw_SOURCES ${common_SOURCES} x11_fullscreen.c x11_gamma.c + x11_init.c x11_input.c x11_joystick.c + x11_keysym2unicode.c x11_opengl.c x11_time.c + x11_window.c) else() message(FATAL_ERROR "No supported platform was selected") endif() -add_library(glfw ${libglfw_SOURCES}) +add_library(glfw ${glfw_SOURCES}) if (BUILD_SHARED_LIBS) @@ -49,14 +49,15 @@ if (BUILD_SHARED_LIBS) if (APPLE) # Append -fno-common to the compile flags to work around a bug in the Apple GCC - get_target_property(CFLAGS glfw COMPILE_FLAGS) - if (NOT CFLAGS) - set(CFLAGS "") + get_target_property(glfw_CFLAGS glfw COMPILE_FLAGS) + if (NOT glfw_CFLAGS) + set(glfw_CFLAGS "") endif() - set_target_properties(glfw PROPERTIES COMPILE_FLAGS "${CFLAGS} -fno-common") + set_target_properties(glfw PROPERTIES + COMPILE_FLAGS "${glfw_CFLAGS} -fno-common") endif() - target_link_libraries(glfw ${GLFW_LIBRARIES}) + target_link_libraries(glfw ${glfw_LIBRARIES}) target_link_libraries(glfw LINK_INTERFACE_LIBRARIES) endif() From bd8eb1399a051ce09b07ce34f76f2e12889849bc Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 25 Mar 2012 16:51:24 +0200 Subject: [PATCH 094/226] Put platform detection in a single place. --- CMakeLists.txt | 32 ++++++++++++++++++-------------- src/CMakeLists.txt | 11 +++-------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e7149dd6..ef6ded3d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,13 +23,25 @@ if (CMAKE_COMPILER_IS_GNUCC) endif() #-------------------------------------------------------------------- -# Set up GLFW for Win32 and WGL on Windows +# Detect and select target platform #-------------------------------------------------------------------- if (WIN32) - message(STATUS "Building GLFW for WGL on a Win32 system") - - # Define the platform identifier set(_GLFW_WIN32_WGL 1) + message(STATUS "Building GLFW for WGL on a Win32 system") +elseif (UNIX AND APPLE) + set(_GLFW_COCOA_NSGL 1) + message(STATUS "Building GLFW for X11 and GLX on a Unix-like system") +elseif (UNIX AND NOT APPLE) + set(_GLFW_X11_GLX 1) + message(STATUS "Building GLFW for Cocoa and NSOpenGL on Mac OS X") +else() + message(FATAL_ERROR "No supported platform was detected") +endif() + +#-------------------------------------------------------------------- +# Set up GLFW for Win32 and WGL on Windows +#-------------------------------------------------------------------- +if (_GLFW_WIN32_WGL) # Set up library and include paths list(APPEND glfw_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR}) @@ -43,11 +55,7 @@ endif() #-------------------------------------------------------------------- # Set up GLFW for Xlib and GLX on Unix-like systems with X Windows #-------------------------------------------------------------------- -if (UNIX AND NOT APPLE) - message(STATUS "Building GLFW for X11 and GLX on a Unix-like system") - - # Define the platform identifier - set(_GLFW_X11_GLX 1) +if (_GLFW_X11_GLX) find_package(X11 REQUIRED) @@ -131,12 +139,8 @@ endif() #-------------------------------------------------------------------- # Set up GLFW for Cocoa and NSOpenGL on Mac OS X #-------------------------------------------------------------------- -if (UNIX AND APPLE) - message(STATUS "Building GLFW for Cocoa and NSOpenGL on Mac OS X") +if (_GLFW_COCOA_NSGL) - # Define the platform identifier - set(_GLFW_COCOA_NSGL 1) - option(GLFW_BUILD_UNIVERSAL "Build GLFW as a Universal Binary" OFF) # Universal build diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3f692cf8..b8c0fd7d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,5 @@ -if (UNIX) +if (_GLFW_X11_GLX) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libglfw.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc @@ -30,24 +30,20 @@ elseif (_GLFW_X11_GLX) x11_init.c x11_input.c x11_joystick.c x11_keysym2unicode.c x11_opengl.c x11_time.c x11_window.c) -else() - message(FATAL_ERROR "No supported platform was selected") endif() add_library(glfw ${glfw_SOURCES}) if (BUILD_SHARED_LIBS) - if (WIN32) + if (_GLFW_WIN32_WGL) # The GLFW DLL needs a special compile-time macro and import library name set_target_properties(glfw PROPERTIES COMPILE_DEFINITIONS "GLFW_BUILD_DLL;_GLFW_NO_DLOAD_GDI32;_GLFW_NO_DLOAD_WINMM" PREFIX "" IMPORT_PREFIX "" IMPORT_SUFFIX "dll.lib") - endif() - - if (APPLE) + elseif (_GLFW_COCOA_NSGL) # Append -fno-common to the compile flags to work around a bug in the Apple GCC get_target_property(glfw_CFLAGS glfw COMPILE_FLAGS) if (NOT glfw_CFLAGS) @@ -59,7 +55,6 @@ if (BUILD_SHARED_LIBS) target_link_libraries(glfw ${glfw_LIBRARIES}) target_link_libraries(glfw LINK_INTERFACE_LIBRARIES) - endif() install(TARGETS glfw DESTINATION lib) From 1eb24ff261c815d2db102b78c74706defb892799 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 25 Mar 2012 17:05:00 +0200 Subject: [PATCH 095/226] Executable dependency list fixes. --- examples/CMakeLists.txt | 3 ++- tests/CMakeLists.txt | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 2bdd95e9..76135a92 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -3,8 +3,9 @@ link_libraries(glfw ${OPENGL_glu_LIBRARY}) if (BUILD_SHARED_LIBS) add_definitions(-DGLFW_DLL) + link_libraries(${OPENGL_gl_LIBRARY}) else() - link_libraries(${GLFW_LIBRARIES}) + link_libraries(${glfw_LIBRARIES}) endif() include_directories(${GLFW_SOURCE_DIR}/include diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f6749e54..d016fb0e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -3,8 +3,9 @@ link_libraries(glfw ${OPENGL_glu_LIBRARY}) if (BUILD_SHARED_LIBS) add_definitions(-DGLFW_DLL) + link_libraries(${OPENGL_gl_LIBRARY}) else() - link_libraries(${GLFW_LIBRARIES}) + link_libraries(${glfw_LIBRARIES}) endif() include_directories(${GLFW_SOURCE_DIR}/include From 862efe78e3535d8a1cad2084828ca91e410c60ac Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 25 Mar 2012 17:22:35 +0200 Subject: [PATCH 096/226] Added fallback check for dlopen, clearer use of required libraries. --- CMakeLists.txt | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ef6ded3d..d17f72ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,9 +68,6 @@ if (_GLFW_X11_GLX) include(CheckFunctionExists) include(CheckSymbolExists) - # This is needed by the GLX function checks below - set(CMAKE_REQUIRED_LIBRARIES ${glfw_LIBRARIES}) - # Check for XRandR (modern resolution switching extension) if (X11_Xrandr_FOUND) set(_GLFW_HAS_XRANDR 1) @@ -115,6 +112,8 @@ if (_GLFW_X11_GLX) set(GLFW_PKGLIBS "${GLFW_PKGLIBS} m") endif() + set(CMAKE_REQUIRED_LIBRARIES ${OPENGL_gl_LIBRARY}) + check_function_exists(glXGetProcAddress _GLFW_HAS_GLXGETPROCADDRESS) if (NOT _GLFW_HAS_GLXGETPROCADDRESS) @@ -129,6 +128,26 @@ if (_GLFW_X11_GLX) NOT _GLFW_HAS_GLXGETPROCADDRESSARB AND NOT _GLFW_HAS_GLXGETPROCADDRESSEXT) message(WARNING "No glXGetProcAddressXXX variant found") + + # Check for dlopen support as a fallback + + find_library(DL_LIBRARY dl) + if (DL_LIBRARY) + set(CMAKE_REQUIRED_LIBRARIES ${DL_LIBRARY}) + else() + set(CMAKE_REQUIRED_LIBRARIES "") + endif() + + check_function_exists(dlopen _GLFW_HAS_DLOPEN) + + if (NOT _GLFW_HAS_DLOPEN) + message(FATAL_ERROR "No entry point retrieval mechanism found") + endif() + + if (DL_LIBRARY) + list(APPEND glfw_LIBRARIES ${DL_LIBRARY}) + set(GLFW_PKGLIBS "${GLFW_PKGLIBS} dl") + endif() endif() if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") From cfa798451e71b61504208de22434d1c51961961e Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 25 Mar 2012 17:23:24 +0200 Subject: [PATCH 097/226] Fixed platform messages being mixed up. --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d17f72ed..8101242b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,10 +30,10 @@ if (WIN32) message(STATUS "Building GLFW for WGL on a Win32 system") elseif (UNIX AND APPLE) set(_GLFW_COCOA_NSGL 1) - message(STATUS "Building GLFW for X11 and GLX on a Unix-like system") + message(STATUS "Building GLFW for Cocoa and NSOpenGL on Mac OS X") elseif (UNIX AND NOT APPLE) set(_GLFW_X11_GLX 1) - message(STATUS "Building GLFW for Cocoa and NSOpenGL on Mac OS X") + message(STATUS "Building GLFW for X11 and GLX on a Unix-like system") else() message(FATAL_ERROR "No supported platform was detected") endif() From 730e2e55c9a10b90c7728f44a9744873fd1ab36f Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 25 Mar 2012 17:24:33 +0200 Subject: [PATCH 098/226] Removed unused module. --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8101242b..4ea202ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,7 +66,6 @@ if (_GLFW_X11_GLX) set(GLFW_PKGLIBS "gl x11") include(CheckFunctionExists) - include(CheckSymbolExists) # Check for XRandR (modern resolution switching extension) if (X11_Xrandr_FOUND) From 8dc139183543040e87e0ac73ace61702ff4789ba Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 25 Mar 2012 17:25:03 +0200 Subject: [PATCH 099/226] Marked library variable as advanced. --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ea202ea..c3e41168 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -131,6 +131,7 @@ if (_GLFW_X11_GLX) # Check for dlopen support as a fallback find_library(DL_LIBRARY dl) + mark_as_advanced(DL_LIBRARY) if (DL_LIBRARY) set(CMAKE_REQUIRED_LIBRARIES ${DL_LIBRARY}) else() From c097246312820cb64c44d3742f4647b14c94b404 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 25 Mar 2012 17:31:22 +0200 Subject: [PATCH 100/226] Fixed listing of non-pkg-config libraries. --- CMakeLists.txt | 13 +++++++------ src/libglfw.pc.cmake | 5 +++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c3e41168..07790a12 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,7 +63,8 @@ if (_GLFW_X11_GLX) list(APPEND glfw_INCLUDE_DIRS ${X11_X11_INCLUDE_PATH} ${OPENGL_INCLUDE_DIR}) list(APPEND glfw_LIBRARIES ${X11_X11_LIB} ${OPENGL_gl_LIBRARY}) - set(GLFW_PKGLIBS "gl x11") + set(GLFW_PKG_DEPS "gl x11") + set(GLFW_PKG_LIBS "") include(CheckFunctionExists) @@ -72,7 +73,7 @@ if (_GLFW_X11_GLX) set(_GLFW_HAS_XRANDR 1) list(APPEND glfw_INCLUDE_DIRS ${X11_Xrandr_INCLUDE_PATH}) list(APPEND glfw_LIBRARIES ${X11_Xrandr_LIB}) - set(GLFW_PKGLIBS "${GLFW_PKGLIBS} xrandr") + set(GLFW_PKG_DEPS "${GLFW_PKG_DEPS} xrandr") endif() # Check for Xf86VidMode (fallback legacy resolution switching extension) @@ -88,7 +89,7 @@ if (_GLFW_X11_GLX) list(APPEND glfw_LIBRARIES Xxf86vm) endif() - set(GLFW_PKGLIBS "${GLFW_PKGLIBS} xxf86vm") + set(GLFW_PKG_DEPS "${GLFW_PKG_DEPS} xxf86vm") endif() # Check for Xkb (X keyboard extension) @@ -101,14 +102,14 @@ if (_GLFW_X11_GLX) mark_as_advanced(RT_LIBRARY) if (RT_LIBRARY) list(APPEND glfw_LIBRARIES ${RT_LIBRARY}) - set(GLFW_PKGLIBS "${GLFW_PKGLIBS} rt") + set(GLFW_PKG_LIBS "${GLFW_PKG_LIBS} -lrt") endif() find_library(MATH_LIBRARY m) mark_as_advanced(MATH_LIBRARY) if (MATH_LIBRARY) list(APPEND glfw_LIBRARIES ${MATH_LIBRARY}) - set(GLFW_PKGLIBS "${GLFW_PKGLIBS} m") + set(GLFW_PKG_LIBS "${GLFW_PKG_LIBS} -lm") endif() set(CMAKE_REQUIRED_LIBRARIES ${OPENGL_gl_LIBRARY}) @@ -146,7 +147,7 @@ if (_GLFW_X11_GLX) if (DL_LIBRARY) list(APPEND glfw_LIBRARIES ${DL_LIBRARY}) - set(GLFW_PKGLIBS "${GLFW_PKGLIBS} dl") + set(GLFW_PKG_LIBS "${GLFW_PKG_LIBS} -ldl") endif() endif() diff --git a/src/libglfw.pc.cmake b/src/libglfw.pc.cmake index 164fdc26..f83ad126 100644 --- a/src/libglfw.pc.cmake +++ b/src/libglfw.pc.cmake @@ -7,6 +7,7 @@ Name: GLFW Description: A portable library for OpenGL, window and input Version: 3.0.0 URL: http://www.glfw.org/ -Requires.private: @GLFW_PKGLIBS@ -Libs: -L${libdir} -lglfw +Requires.private: @GLFW_PKG_DEPS@ +Libs: -L${libdir} -lglfw +Libs.private: @GLFW_PKG_LIBS@ Cflags: -I${includedir} From 2588c9be1739d62d7b27bf11e278d1a6063d40e3 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 25 Mar 2012 17:40:30 +0200 Subject: [PATCH 101/226] Renamed GLFW_BUILD_DLL to _GLFW_BUILD_DLL. --- include/GL/glfw3.h | 2 +- readme.html | 1 + src/CMakeLists.txt | 2 +- src/win32_dllmain.c | 4 ++-- src/win32_init.c | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 44e26b62..180fca80 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -119,7 +119,7 @@ extern "C" { /* ---------------- GLFW related system specific defines ----------------- */ -#if defined(_WIN32) && defined(GLFW_BUILD_DLL) +#if defined(_WIN32) && defined(_GLFW_BUILD_DLL) /* We are building a Win32 DLL */ #define GLFWAPI __declspec(dllexport) diff --git a/readme.html b/readme.html index 84cc2a66..f631acd7 100644 --- a/readme.html +++ b/readme.html @@ -288,6 +288,7 @@ version of GLFW.

    • Renamed glfw.h to glfw3.h to avoid conflicts with 2.x series
    • Renamed GLFW_WINDOW token to GLFW_WINDOWED
    • Renamed GLFW_WINDOW_NO_RESIZE to GLFW_WINDOW_RESIZABLE
    • +
    • Renamed GLFW_BUILD_DLL to _GLFW_BUILD_DLL
    • Renamed version test to glfwinfo
    • Replaced ad hoc build system with CMake
    • Replaced layout-dependent key codes with single, platform-independent set based on US layout
    • diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b8c0fd7d..b87ac3b1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -39,7 +39,7 @@ if (BUILD_SHARED_LIBS) if (_GLFW_WIN32_WGL) # The GLFW DLL needs a special compile-time macro and import library name set_target_properties(glfw PROPERTIES - COMPILE_DEFINITIONS "GLFW_BUILD_DLL;_GLFW_NO_DLOAD_GDI32;_GLFW_NO_DLOAD_WINMM" + COMPILE_DEFINITIONS "_GLFW_BUILD_DLL;_GLFW_NO_DLOAD_GDI32;_GLFW_NO_DLOAD_WINMM" PREFIX "" IMPORT_PREFIX "" IMPORT_SUFFIX "dll.lib") diff --git a/src/win32_dllmain.c b/src/win32_dllmain.c index a999af0e..95258ccc 100644 --- a/src/win32_dllmain.c +++ b/src/win32_dllmain.c @@ -31,7 +31,7 @@ #include "internal.h" -#if defined(GLFW_BUILD_DLL) +#if defined(_GLFW_BUILD_DLL) //======================================================================== // GLFW DLL entry point @@ -45,5 +45,5 @@ BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) return TRUE; } -#endif // GLFW_BUILD_DLL +#endif // _GLFW_BUILD_DLL diff --git a/src/win32_init.c b/src/win32_init.c index 4fab9b74..55232fd7 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -271,7 +271,7 @@ const char* _glfwPlatformGetVersionString(void) #else " (unknown compiler)" #endif -#if defined(GLFW_BUILD_DLL) +#if defined(_GLFW_BUILD_DLL) " DLL" #endif #if !defined(_GLFW_NO_DLOAD_GDI32) From cc5d7cda64643b900c93502927837d09b35c13b3 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 25 Mar 2012 17:43:02 +0200 Subject: [PATCH 102/226] Added configuration error check. --- include/GL/glfw3.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 180fca80..b29d0005 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -119,6 +119,10 @@ extern "C" { /* ---------------- GLFW related system specific defines ----------------- */ +#if defined(GLFW_DLL) && defined(_GLFW_BUILD_DLL) + #error "You must not have both GLFW_DLL and _GLFW_BUILD_DLL defined" +#endif + #if defined(_WIN32) && defined(_GLFW_BUILD_DLL) /* We are building a Win32 DLL */ From 415ebbb97cfb9487b8682cf704cd7a07481a2420 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 25 Mar 2012 20:15:27 +0200 Subject: [PATCH 103/226] Added cache variable for dependencies of GLFW. --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 07790a12..522aaf76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -183,6 +183,11 @@ if (_GLFW_COCOA_NSGL) ${CORE_FOUNDATION_FRAMEWORK}) endif() +#-------------------------------------------------------------------- +# Export GLFW library dependencies +#-------------------------------------------------------------------- +set(GLFW_LIBRARIES ${glfw_LIBRARIES} CACHE STRING "Dependencies of GLFW") + #-------------------------------------------------------------------- # Add subdirectories #-------------------------------------------------------------------- From 7fb702a22be00f26de75483185d39a01aa44abc6 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 25 Mar 2012 20:45:06 +0200 Subject: [PATCH 104/226] Removed unused code. --- src/win32_window.c | 46 +--------------------------------------------- 1 file changed, 1 insertion(+), 45 deletions(-) diff --git a/src/win32_window.c b/src/win32_window.c index 0f3c67d0..dd25c3ce 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -34,30 +34,6 @@ #include -//======================================================================== -// Convert BPP to RGB bits based on "best guess" -//======================================================================== - -static void bpp2rgb(int bpp, int* r, int* g, int* b) -{ - int delta; - - // We assume that by 32 they really meant 24 - if (bpp == 32) - bpp = 24; - - // Convert "bits per pixel" to red, green & blue sizes - - *r = *g = *b = bpp / 3; - delta = bpp - (*r * 3); - if (delta >= 1) - *g = *g + 1; - - if (delta == 2) - *r = *r + 1; -} - - //======================================================================== // Enable/disable minimize/restore animations //======================================================================== @@ -1600,29 +1576,10 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) { - //int bpp, refresh; - int newMode = 0; GLboolean sizeChanged = GL_FALSE; if (window->mode == GLFW_FULLSCREEN) { - // Get some info about the current mode - - DEVMODE dm; - - dm.dmSize = sizeof(DEVMODE); - //if (EnumDisplaySettings(NULL, window->Win32.modeID, &dm)) - //{ - // We need to keep BPP the same for the OpenGL context to keep working - //bpp = dm.dmBitsPerPel; - - // Get closest match for target video mode - //refresh = window->Win32.desiredRefreshRate; - //newMode = _glfwGetClosestVideoModeBPP(&width, &height, &bpp, &refresh); - //} - //else - //newMode = window->Win32.modeID; - if (width > window->width || height > window->height) { // The new video mode is larger than the current one, so we resize @@ -1634,8 +1591,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) sizeChanged = GL_TRUE; } - //if (newMode != window->Win32.modeID) - //_glfwSetVideoModeMODE(newMode); + // TODO: Change video mode } else { From e53bbfd2dd5b383cfe0e1a7e2b1e4a6630b81956 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 26 Mar 2012 03:06:45 +0200 Subject: [PATCH 105/226] Renamed pkg-config file template. --- src/CMakeLists.txt | 2 +- src/{libglfw.pc.cmake => libglfw.pc.in} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/{libglfw.pc.cmake => libglfw.pc.in} (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b87ac3b1..7358c8f5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,6 @@ if (_GLFW_X11_GLX) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libglfw.pc.cmake + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libglfw.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc DESTINATION lib/pkgconfig) diff --git a/src/libglfw.pc.cmake b/src/libglfw.pc.in similarity index 100% rename from src/libglfw.pc.cmake rename to src/libglfw.pc.in From 6fd6c5f7e45c0a9a29b9d539a2fb198603e596b6 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 26 Mar 2012 03:11:43 +0200 Subject: [PATCH 106/226] Moved pkg-config file generation. --- CMakeLists.txt | 6 ++++++ src/CMakeLists.txt | 7 ------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 522aaf76..665f8c64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -154,6 +154,12 @@ if (_GLFW_X11_GLX) if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") set(_GLFW_USE_LINUX_JOYSTICKS 1) endif() + + configure_file(${GLFW_SOURCE_DIR}/src/libglfw.pc.in + ${GLFW_BINARY_DIR}/src/libglfw.pc @ONLY) + + install(FILES ${GLFW_BINARY_DIR}/src/libglfw.pc + DESTINATION lib/pkgconfig) endif() #-------------------------------------------------------------------- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7358c8f5..26471f93 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,11 +1,4 @@ -if (_GLFW_X11_GLX) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libglfw.pc.in - ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc @ONLY) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libglfw.pc - DESTINATION lib/pkgconfig) -endif() - include_directories(${GLFW_SOURCE_DIR}/src ${GLFW_BINARY_DIR}/src ${glfw_INCLUDE_DIRS}) From fd6bc698c0d695b47c587549a77559f846ca91c6 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 26 Mar 2012 12:54:50 +0200 Subject: [PATCH 107/226] Moved file generation around. --- CMakeLists.txt | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 665f8c64..aab5c293 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -154,12 +154,6 @@ if (_GLFW_X11_GLX) if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") set(_GLFW_USE_LINUX_JOYSTICKS 1) endif() - - configure_file(${GLFW_SOURCE_DIR}/src/libglfw.pc.in - ${GLFW_BINARY_DIR}/src/libglfw.pc @ONLY) - - install(FILES ${GLFW_BINARY_DIR}/src/libglfw.pc - DESTINATION lib/pkgconfig) endif() #-------------------------------------------------------------------- @@ -208,29 +202,34 @@ if (GLFW_BUILD_TESTS) endif() #-------------------------------------------------------------------- -# Create shared configuration header +# Create generated files #-------------------------------------------------------------------- +configure_file("${GLFW_SOURCE_DIR}/docs/Doxyfile.in" + "${GLFW_BINARY_DIR}/docs/Doxyfile" @ONLY) + configure_file(${GLFW_SOURCE_DIR}/src/config.h.in ${GLFW_BINARY_DIR}/src/config.h @ONLY) #-------------------------------------------------------------------- -# Install standard files +# Install header and documentation +# The src directory's CMakeLists.txt file installs the library #-------------------------------------------------------------------- - install(DIRECTORY include/GL DESTINATION include FILES_MATCHING PATTERN glfw3.h) install(FILES COPYING.txt readme.html DESTINATION share/doc/glfw-${GLFW_VERSION_FULL}) -# The src directory's CMakeLists.txt file installs the library +#-------------------------------------------------------------------- +# Create and install pkg-config file on supported platforms +#-------------------------------------------------------------------- +if (_GLFW_X11_GLX) + configure_file(${GLFW_SOURCE_DIR}/src/libglfw.pc.in + ${GLFW_BINARY_DIR}/src/libglfw.pc @ONLY) -#-------------------------------------------------------------------- -# -- Documentation generation -#-------------------------------------------------------------------- -configure_file("${GLFW_SOURCE_DIR}/docs/Doxyfile.in" - "${GLFW_BINARY_DIR}/docs/Doxyfile" - @ONLY) + install(FILES ${GLFW_BINARY_DIR}/src/libglfw.pc + DESTINATION lib/pkgconfig) +endif() #-------------------------------------------------------------------- # Uninstall operation From 2a8324955cc3630807c3f51ff0e4daf1a00f8364 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 26 Mar 2012 13:14:06 +0200 Subject: [PATCH 108/226] Formatting. --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aab5c293..01b50a6b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -204,8 +204,8 @@ endif() #-------------------------------------------------------------------- # Create generated files #-------------------------------------------------------------------- -configure_file("${GLFW_SOURCE_DIR}/docs/Doxyfile.in" - "${GLFW_BINARY_DIR}/docs/Doxyfile" @ONLY) +configure_file(${GLFW_SOURCE_DIR}/docs/Doxyfile.in + ${GLFW_BINARY_DIR}/docs/Doxyfile @ONLY) configure_file(${GLFW_SOURCE_DIR}/src/config.h.in ${GLFW_BINARY_DIR}/src/config.h @ONLY) From 92758e4ac0cccc1cf9cf30fd23a5bdcf76498bee Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 26 Mar 2012 13:15:37 +0200 Subject: [PATCH 109/226] Made pkg-config file use version variable. --- src/libglfw.pc.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libglfw.pc.in b/src/libglfw.pc.in index f83ad126..be6275aa 100644 --- a/src/libglfw.pc.in +++ b/src/libglfw.pc.in @@ -5,7 +5,7 @@ libdir=${exec_prefix}/lib Name: GLFW Description: A portable library for OpenGL, window and input -Version: 3.0.0 +Version: @GLFW_VERSION_FULL@ URL: http://www.glfw.org/ Requires.private: @GLFW_PKG_DEPS@ Libs: -L${libdir} -lglfw From ee1d71adf3d372ea039fd7033f6683cf7b2864cb Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 26 Mar 2012 13:35:14 +0200 Subject: [PATCH 110/226] Added OS X support to pkg-config file. --- CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aab5c293..93970833 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -181,6 +181,9 @@ if (_GLFW_COCOA_NSGL) ${OPENGL_gl_LIBRARY} ${IOKIT_FRAMEWORK} ${CORE_FOUNDATION_FRAMEWORK}) + + set(GLFW_PKG_DEPS "") + set(GLFW_PKG_LIBS "-framework Cocoa -framework OpenGL -framework IOKit -framework CoreFoundation") endif() #-------------------------------------------------------------------- @@ -223,7 +226,7 @@ install(FILES COPYING.txt readme.html #-------------------------------------------------------------------- # Create and install pkg-config file on supported platforms #-------------------------------------------------------------------- -if (_GLFW_X11_GLX) +if (_GLFW_X11_GLX OR _GLFW_COCOA_NSGL) configure_file(${GLFW_SOURCE_DIR}/src/libglfw.pc.in ${GLFW_BINARY_DIR}/src/libglfw.pc @ONLY) From 8e4e70d7a476d285dc4c46ee03b8766aa75eab5b Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 26 Mar 2012 14:46:42 +0200 Subject: [PATCH 111/226] Implemented cursor enter/leave for OS X. --- src/cocoa_window.m | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 98c220ed..5cd7ee3e 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -292,6 +292,7 @@ static int convertMacKeyCode(unsigned int macKeyCode) @interface GLFWContentView : NSView { _GLFWwindow* window; + NSTrackingArea* trackingArea; } - (id)initWithGlfwWindow:(_GLFWwindow *)initWindow; @@ -304,11 +305,22 @@ static int convertMacKeyCode(unsigned int macKeyCode) { self = [super init]; if (self != nil) + { window = initWindow; + trackingArea = nil; + + [self updateTrackingAreas]; + } return self; } +-(void)dealloc +{ + [trackingArea release]; + [super dealloc]; +} + - (BOOL)isOpaque { return YES; @@ -384,6 +396,36 @@ static int convertMacKeyCode(unsigned int macKeyCode) _glfwInputMouseClick(window, [event buttonNumber], GLFW_RELEASE); } +- (void)mouseExited:(NSEvent *)event +{ + _glfwInputCursorEnter(window, GL_FALSE); +} + +- (void)mouseEntered:(NSEvent *)event +{ + _glfwInputCursorEnter(window, GL_TRUE); +} + +- (void)updateTrackingAreas +{ + if (trackingArea != nil) + { + [self removeTrackingArea:trackingArea]; + [trackingArea release]; + } + + NSTrackingAreaOptions options = NSTrackingMouseEnteredAndExited | + NSTrackingActiveAlways | + NSTrackingInVisibleRect; + + trackingArea = [[NSTrackingArea alloc] initWithRect:[self bounds] + options:options + owner:self + userInfo:nil]; + + [self addTrackingArea:trackingArea]; +} + - (void)keyDown:(NSEvent *)event { NSUInteger i, length; From c9820b2ba50cacc5fbeeb6a9c71f5e544bd45dee Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 26 Mar 2012 15:20:31 +0200 Subject: [PATCH 112/226] Fixed issues found with static analysis. --- src/cocoa_joystick.m | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/cocoa_joystick.m b/src/cocoa_joystick.m index 45b3be0f..c0268e44 100644 --- a/src/cocoa_joystick.m +++ b/src/cocoa_joystick.m @@ -336,7 +336,12 @@ void _glfwInitJoysticks(void) result = IOMasterPort(bootstrap_port, &masterPort); hidMatchDictionary = IOServiceMatching(kIOHIDDeviceKey); if (kIOReturnSuccess != result || !hidMatchDictionary) + { + if (hidMatchDictionary) + CFRelease(hidMatchDictionary); + return; + } result = IOServiceGetMatchingServices(masterPort, hidMatchDictionary, @@ -370,19 +375,27 @@ void _glfwInitJoysticks(void) /* Check device type */ refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDPrimaryUsagePageKey)); if (refCF) + { CFNumberGetValue(refCF, kCFNumberLongType, &usagePage); + if (usagePage != kHIDPage_GenericDesktop) + { + /* We are not interested in this device */ + continue; + } + } refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDPrimaryUsageKey)); if (refCF) - CFNumberGetValue(refCF, kCFNumberLongType, &usage); - - if ((usagePage != kHIDPage_GenericDesktop) || - (usage != kHIDUsage_GD_Joystick && - usage != kHIDUsage_GD_GamePad && - usage != kHIDUsage_GD_MultiAxisController)) { - /* We don't interested in this device */ - continue; + CFNumberGetValue(refCF, kCFNumberLongType, &usage); + + if ((usage != kHIDUsage_GD_Joystick && + usage != kHIDUsage_GD_GamePad && + usage != kHIDUsage_GD_MultiAxisController)) + { + /* We are not interested in this device */ + continue; + } } _glfwJoystick* joystick = &_glfwJoysticks[deviceCounter]; From a12b395442f8c1a7f0d0acfdcca9b1560e1bdb54 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 26 Mar 2012 15:21:13 +0200 Subject: [PATCH 113/226] Added headers to project. --- src/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 26471f93..ae72cda7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,10 +3,12 @@ include_directories(${GLFW_SOURCE_DIR}/src ${GLFW_BINARY_DIR}/src ${glfw_INCLUDE_DIRS}) +set(common_HEADERS ${GLFW_SOURCE_DIR}/include/GL/glfw3.h internal.h) set(common_SOURCES error.c fullscreen.c gamma.c init.c input.c joystick.c opengl.c time.c window.c) if (_GLFW_COCOA_NSGL) + set(glfw_HEADERS ${common_HEADERS} cocoa_platform.h) set(glfw_SOURCES ${common_SOURCES} cocoa_fullscreen.m cocoa_gamma.c cocoa_init.m cocoa_input.m cocoa_joystick.m cocoa_opengl.m cocoa_time.c cocoa_window.m) @@ -14,18 +16,20 @@ if (_GLFW_COCOA_NSGL) # For some reason, CMake doesn't know about .m set_source_files_properties(${glfw_SOURCES} PROPERTIES LANGUAGE C) elseif (_GLFW_WIN32_WGL) + set(glfw_HEADERS ${common_HEADERS} win32_platform.h) set(glfw_SOURCES ${common_SOURCES} 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) elseif (_GLFW_X11_GLX) + set(glfw_HEADERS ${common_HEADERS} x11_platform.h) set(glfw_SOURCES ${common_SOURCES} x11_fullscreen.c x11_gamma.c x11_init.c x11_input.c x11_joystick.c x11_keysym2unicode.c x11_opengl.c x11_time.c x11_window.c) endif() -add_library(glfw ${glfw_SOURCES}) +add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS}) if (BUILD_SHARED_LIBS) From d40a3d1617c9a04e436208dc3ea692e1947b0e5f Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 26 Mar 2012 15:21:41 +0200 Subject: [PATCH 114/226] Renamed Cocoa window object member. --- src/cocoa_platform.h | 2 +- src/cocoa_window.m | 52 ++++++++++++++++++++++---------------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index b70fb184..801b4c88 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -72,7 +72,7 @@ typedef struct _GLFWcontextNSGL //------------------------------------------------------------------------ typedef struct _GLFWwindowNS { - id window; + id object; id delegate; unsigned int modifierFlags; double fracScrollX; diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 5cd7ee3e..3f3dbc4a 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -69,7 +69,7 @@ [window->NSGL.context update]; NSRect contentRect = - [window->NS.window contentRectForFrameRect:[window->NS.window frame]]; + [window->NS.object contentRectForFrameRect:[window->NS.object frame]]; _glfwInputWindowSize(window, contentRect.size.width, contentRect.size.height); } @@ -79,7 +79,7 @@ [window->NSGL.context update]; NSRect contentRect = - [window->NS.window contentRectForFrameRect:[window->NS.window frame]]; + [window->NS.object contentRectForFrameRect:[window->NS.object frame]]; CGPoint mainScreenOrigin = CGDisplayBounds(CGMainDisplayID()).origin; double mainScreenHeight = CGDisplayBounds(CGMainDisplayID()).size.height; @@ -360,7 +360,7 @@ static int convertMacKeyCode(unsigned int macKeyCode) NSPoint p = [event locationInWindow]; // Cocoa coordinate system has origin at lower left - p.y = [[window->NS.window contentView] bounds].size.height - p.y; + p.y = [[window->NS.object contentView] bounds].size.height - p.y; _glfwInputCursorMotion(window, p.x, p.y); } @@ -674,25 +674,25 @@ static GLboolean createWindow(_GLFWwindow* window, else styleMask = NSBorderlessWindowMask; - window->NS.window = [[NSWindow alloc] + window->NS.object = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, window->width, window->height) styleMask:styleMask backing:NSBackingStoreBuffered defer:NO]; - if (window->NS.window == nil) + if (window->NS.object == nil) { _glfwSetError(GLFW_PLATFORM_ERROR, "Cocoa/NSOpenGL: Failed to create window"); return GL_FALSE; } - [window->NS.window setTitle:[NSString stringWithUTF8String:wndconfig->title]]; - [window->NS.window setContentView:[[GLFWContentView alloc] + [window->NS.object setTitle:[NSString stringWithUTF8String:wndconfig->title]]; + [window->NS.object setContentView:[[GLFWContentView alloc] initWithGlfwWindow:window]]; - [window->NS.window setDelegate:window->NS.delegate]; - [window->NS.window setAcceptsMouseMovedEvents:YES]; - [window->NS.window center]; + [window->NS.object setDelegate:window->NS.delegate]; + [window->NS.object setAcceptsMouseMovedEvents:YES]; + [window->NS.object center]; return GL_TRUE; } @@ -906,8 +906,8 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, if (!createContext(window, wndconfig, fbconfig)) return GL_FALSE; - [window->NS.window makeKeyAndOrderFront:nil]; - [window->NSGL.context setView:[window->NS.window contentView]]; + [window->NS.object makeKeyAndOrderFront:nil]; + [window->NSGL.context setView:[window->NS.object contentView]]; if (wndconfig->mode == GLFW_FULLSCREEN) { @@ -921,7 +921,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, return GL_FALSE; } - [[window->NS.window contentView] enterFullScreenMode:[NSScreen mainScreen] + [[window->NS.object contentView] enterFullScreenMode:[NSScreen mainScreen] withOptions:nil]; } @@ -943,11 +943,11 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, void _glfwPlatformCloseWindow(_GLFWwindow* window) { - [window->NS.window orderOut:nil]; + [window->NS.object orderOut:nil]; if (window->mode == GLFW_FULLSCREEN) { - [[window->NS.window contentView] exitFullScreenModeWithOptions:nil]; + [[window->NS.object contentView] exitFullScreenModeWithOptions:nil]; _glfwRestoreVideoMode(); } @@ -959,12 +959,12 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window) [window->NSGL.context release]; window->NSGL.context = nil; - [window->NS.window setDelegate:nil]; + [window->NS.object setDelegate:nil]; [window->NS.delegate release]; window->NS.delegate = nil; - [window->NS.window close]; - window->NS.window = nil; + [window->NS.object close]; + window->NS.object = nil; // TODO: Probably more cleanup } @@ -976,7 +976,7 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window) void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title) { - [window->NS.window setTitle:[NSString stringWithUTF8String:title]]; + [window->NS.object setTitle:[NSString stringWithUTF8String:title]]; } @@ -986,7 +986,7 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title) void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) { - [window->NS.window setContentSize:NSMakeSize(width, height)]; + [window->NS.object setContentSize:NSMakeSize(width, height)]; } @@ -997,16 +997,16 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y) { NSRect contentRect = - [window->NS.window contentRectForFrameRect:[window->NS.window frame]]; + [window->NS.object contentRectForFrameRect:[window->NS.object frame]]; // We assume here that the client code wants to position the window within the // screen the window currently occupies - NSRect screenRect = [[window->NS.window screen] visibleFrame]; + NSRect screenRect = [[window->NS.object screen] visibleFrame]; contentRect.origin = NSMakePoint(screenRect.origin.x + x, screenRect.origin.y + screenRect.size.height - y - contentRect.size.height); - [window->NS.window setFrame:[window->NS.window frameRectForContentRect:contentRect] + [window->NS.object setFrame:[window->NS.object frameRectForContentRect:contentRect] display:YES]; } @@ -1017,7 +1017,7 @@ void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y) void _glfwPlatformIconifyWindow(_GLFWwindow* window) { - [window->NS.window miniaturize:nil]; + [window->NS.object miniaturize:nil]; } @@ -1027,7 +1027,7 @@ void _glfwPlatformIconifyWindow(_GLFWwindow* window) void _glfwPlatformRestoreWindow(_GLFWwindow* window) { - [window->NS.window deminiaturize:nil]; + [window->NS.object deminiaturize:nil]; } @@ -1168,7 +1168,7 @@ void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y) // "global coordinates" are upside down from CG's... NSPoint localPoint = NSMakePoint(x, y); - NSPoint globalPoint = [window->NS.window convertBaseToScreen:localPoint]; + NSPoint globalPoint = [window->NS.object convertBaseToScreen:localPoint]; CGPoint mainScreenOrigin = CGDisplayBounds(CGMainDisplayID()).origin; double mainScreenHeight = CGDisplayBounds(CGMainDisplayID()).size.height; CGPoint targetPoint = CGPointMake(globalPoint.x - mainScreenOrigin.x, From 77c9baab3556f351806378ab294967bb0999a788 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 26 Mar 2012 15:29:01 +0200 Subject: [PATCH 115/226] Fixed issues found with static analysis. --- src/cocoa_platform.h | 1 + src/cocoa_window.m | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index 801b4c88..67154190 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -74,6 +74,7 @@ typedef struct _GLFWwindowNS { id object; id delegate; + id view; unsigned int modifierFlags; double fracScrollX; double fracScrollY; diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 3f3dbc4a..e3b79706 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -687,9 +687,10 @@ static GLboolean createWindow(_GLFWwindow* window, return GL_FALSE; } + window->NS.view = [[GLFWContentView alloc] initWithGlfwWindow:window]; + [window->NS.object setTitle:[NSString stringWithUTF8String:wndconfig->title]]; - [window->NS.object setContentView:[[GLFWContentView alloc] - initWithGlfwWindow:window]]; + [window->NS.object setContentView:window->NS.view]; [window->NS.object setDelegate:window->NS.delegate]; [window->NS.object setAcceptsMouseMovedEvents:YES]; [window->NS.object center]; @@ -963,6 +964,9 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window) [window->NS.delegate release]; window->NS.delegate = nil; + [window->NS.view release]; + window->NS.view = nil; + [window->NS.object close]; window->NS.object = nil; From a8bcae8efaf3695482d65bda35249a387267d1d0 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 26 Mar 2012 16:55:31 +0200 Subject: [PATCH 116/226] Merged credit entries. --- readme.html | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/readme.html b/readme.html index 6e098a05..d8f22094 100644 --- a/readme.html +++ b/readme.html @@ -858,9 +858,6 @@ their skills. Special thanks go out to:

    • Stefan Gustavson, for quick and thorough testing of GLFW on many and varied operating systems and hardware configurations
    • -
    • Hans 'Hanmac' Mackowiak, for the initial implementation of cursor enter - and leave callbacks on X11
    • -
    • Sylvain Hellegouarch, for support, bug reports and testing
    • Alex Holkner, for writing the code from which the Compiz/Intel fix was @@ -883,7 +880,8 @@ their skills. Special thanks go out to:

    • Tristam MacDonald, for his bug reports and feedback on the Cocoa port
    • -
    • Hans 'Hanmac' Mackowiak, for adding UTF-8 window title support on X11 and +
    • Hans 'Hanmac' Mackowiak, for the initial implementation of cursor + enter/leave callbacks on X11, adding UTF-8 window title support on X11 and a fix for the Xkb support
    • David Medlock, for doing the initial Lua port
    • From f84990bffd20d5663de1889c60ef4bf334e76fb7 Mon Sep 17 00:00:00 2001 From: Osman Keskin Date: Tue, 27 Mar 2012 00:24:01 +0200 Subject: [PATCH 117/226] Implemented joystick hat support for OS X and Win32. --- src/cocoa_joystick.m | 39 ++++++++++++++++++++++++++++++--------- src/win32_joystick.c | 28 ++++++++++++++++++++++++---- 2 files changed, 54 insertions(+), 13 deletions(-) diff --git a/src/cocoa_joystick.m b/src/cocoa_joystick.m index c0268e44..b3bd6e41 100644 --- a/src/cocoa_joystick.m +++ b/src/cocoa_joystick.m @@ -311,6 +311,13 @@ static void pollJoystickEvents(void) (_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->axes, j); axes->value = getElementValue(joystick, axes); } + + for (j = 0; j < joystick->numHats; j++) + { + _glfwJoystickElement* hat = + (_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick->hats, j); + hat->value = getElementValue(joystick, hat); + } } } } @@ -502,7 +509,7 @@ int _glfwPlatformGetJoystickParam(int joy, int param) return (int) CFArrayGetCount(_glfwJoysticks[joy].axes); case GLFW_BUTTONS: - return (int) CFArrayGetCount(_glfwJoysticks[joy].buttons); + return (int) CFArrayGetCount(_glfwJoysticks[joy].buttons) + ((int) CFArrayGetCount(_glfwJoysticks[joy].hats)) * 4; default: break; @@ -565,7 +572,7 @@ int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes) int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons) { - int i; + int button; if (joy < GLFW_JOYSTICK_1 || joy > GLFW_JOYSTICK_LAST) return 0; @@ -578,17 +585,31 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, return 0; } - numbuttons = numbuttons < joystick.numButtons ? numbuttons : joystick.numButtons; - // Update joystick state pollJoystickEvents(); - for (i = 0; i < numbuttons; i++) + for (button = 0; button < numbuttons && button < joystick.numButtons; button++) { - _glfwJoystickElement* button = (_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick.buttons, i); - buttons[i] = button->value ? GLFW_PRESS : GLFW_RELEASE; + _glfwJoystickElement* element = (_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick.buttons, button); + buttons[button] = element->value ? GLFW_PRESS : GLFW_RELEASE; } - return numbuttons; -} + // Virtual buttons - Inject data from hats + // Each hat is exposed as 4 buttons which exposes 8 directions with concurrent button presses + const int directions[9] = { 1, 3, 2, 6, 4, 12, 8, 9, 0 }; // Bit fields of button presses for each direction, including nil + + for (int i = 0; i < joystick.numHats; i++) + { + _glfwJoystickElement* hat = (_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick.hats, i); + int value = hat->value; + if (value < 0 || value > 8) value = 8; + + for (int j = 0; j < 4 && button < numbuttons; j++) + { + buttons[button++] = directions[value] & (1 << j) ? GLFW_PRESS : GLFW_RELEASE; + } + } + + return button; +} diff --git a/src/win32_joystick.c b/src/win32_joystick.c index 0ab84aaf..9fad3002 100644 --- a/src/win32_joystick.c +++ b/src/win32_joystick.c @@ -91,6 +91,8 @@ int _glfwPlatformGetJoystickParam(int joy, int param) // Get joystick capabilities _glfw_joyGetDevCaps(joy - GLFW_JOYSTICK_1, &jc, sizeof(JOYCAPS)); + const int hats = (jc.wCaps & JOYCAPS_HASPOV) && (jc.wCaps & JOYCAPS_POV4DIR) ? 1 : 0; + switch (param) { case GLFW_AXES: @@ -98,8 +100,8 @@ int _glfwPlatformGetJoystickParam(int joy, int param) return jc.wNumAxes; case GLFW_BUTTONS: - // Return number of joystick axes - return jc.wNumButtons; + // Return number of joystick buttons + return jc.wNumButtons + hats * 4; default: break; @@ -174,7 +176,7 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, // Get joystick state ji.dwSize = sizeof(JOYINFOEX); - ji.dwFlags = JOY_RETURNBUTTONS; + ji.dwFlags = JOY_RETURNBUTTONS | JOY_RETURNPOV; _glfw_joyGetPosEx(joy - GLFW_JOYSTICK_1, &ji); // Get states of all requested buttons @@ -184,6 +186,24 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, (ji.dwButtons & (1UL << button) ? GLFW_PRESS : GLFW_RELEASE); } + // Virtual buttons - Inject data from hats + // Each hat is exposed as 4 buttons which exposes 8 directions with concurrent button presses + // (Note: This API only exposes one hat) + + const int hats = (jc.wCaps & JOYCAPS_HASPOV) && (jc.wCaps & JOYCAPS_POV4DIR) ? 1 : 0; + const int directions[9] = { 1, 3, 2, 6, 4, 12, 8, 9, 0 }; // Bit fields of button presses for each direction, including nil + + if (hats > 0) + { + int j; + int value = ji.dwPOV / 100 / 45; + if (value < 0 || value > 8) value = 8; + + for (j = 0; j < 4 && button < numbuttons; j++) + { + buttons[button++] = directions[value] & (1 << j) ? GLFW_PRESS : GLFW_RELEASE; + } + } + return button; } - From 7f470065fc3b0a2c8c9fe72a146d7346d965ef98 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 28 Mar 2012 15:05:17 +0200 Subject: [PATCH 118/226] Applied coding conventions. --- src/clipboard.c | 1 + src/x11_clipboard.c | 54 +++++++++++++++++++++++++++------------------ 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/clipboard.c b/src/clipboard.c index b055c168..480bad8e 100644 --- a/src/clipboard.c +++ b/src/clipboard.c @@ -76,3 +76,4 @@ GLFWAPI size_t glfwGetClipboardData(void *data, size_t size, int format) return _glfwPlatformGetClipboardData(data, size, format); } + diff --git a/src/x11_clipboard.c b/src/x11_clipboard.c index 1be0ac23..71f2f7c9 100644 --- a/src/x11_clipboard.c +++ b/src/x11_clipboard.c @@ -36,18 +36,15 @@ #include #include -////////////////////////////////////////////////////////////////////////// -////// GLFW platform API ////// -////////////////////////////////////////////////////////////////////////// //======================================================================== // Get the corresponding X11 format for a given GLFW format. //======================================================================== -static Atom *getInternalFormat(int fmt) +static Atom* getInternalFormat(int format) { // Get the necessary atoms - switch (fmt) + switch (format) { case GLFW_CLIPBOARD_FORMAT_STRING: return _glfwLibrary.X11.selection.atoms.string; @@ -56,13 +53,18 @@ static Atom *getInternalFormat(int fmt) } } + +////////////////////////////////////////////////////////////////////////// +////// GLFW internal API ////// +////////////////////////////////////////////////////////////////////////// + //======================================================================== // X11 selection request event //======================================================================== -Atom _glfwSelectionRequest(XSelectionRequestEvent *request) +Atom _glfwSelectionRequest(XSelectionRequestEvent* request) { - Atom *atoms = _glfwLibrary.X11.selection.atoms.string; + Atom* atoms = _glfwLibrary.X11.selection.atoms.string; if (request->target == XA_STRING) { // TODO: ISO Latin-1 specific characters don't get converted @@ -73,7 +75,7 @@ Atom _glfwSelectionRequest(XSelectionRequestEvent *request) request->target, 8, PropModeReplace, - (unsigned char *)_glfwLibrary.X11.selection.clipboard.string, + (unsigned char*) _glfwLibrary.X11.selection.clipboard.string, 8); } else if (request->target == atoms[_GLFW_STRING_ATOM_COMPOUND] || @@ -85,7 +87,7 @@ Atom _glfwSelectionRequest(XSelectionRequestEvent *request) request->target, 8, PropModeReplace, - (unsigned char *)_glfwLibrary.X11.selection.clipboard.string, + (unsigned char*) _glfwLibrary.X11.selection.clipboard.string, _glfwLibrary.X11.selection.clipboard.stringlen); } else @@ -93,9 +95,15 @@ Atom _glfwSelectionRequest(XSelectionRequestEvent *request) // TODO: Should we set an error? Probably not. return None; } + return request->target; } + +////////////////////////////////////////////////////////////////////////// +////// GLFW platform API ////// +////////////////////////////////////////////////////////////////////////// + //======================================================================== // Set the clipboard contents //======================================================================== @@ -132,14 +140,15 @@ void _glfwPlatformSetClipboardData(void *data, size_t size, int format) // Set the selection owner to our active window XSetSelectionOwner(_glfwLibrary.X11.display, XA_PRIMARY, - _glfwLibrary.activeWindow->X11.handle, CurrentTime); + _glfwLibrary.activeWindow->X11.handle, CurrentTime); XSetSelectionOwner(_glfwLibrary.X11.display, - _glfwLibrary.X11.selection.atoms.clipboard - [_GLFW_CLIPBOARD_ATOM_CLIPBOARD], - _glfwLibrary.activeWindow->X11.handle, CurrentTime); + _glfwLibrary.X11.selection.atoms.clipboard + [_GLFW_CLIPBOARD_ATOM_CLIPBOARD], + _glfwLibrary.activeWindow->X11.handle, CurrentTime); XFlush(_glfwLibrary.X11.display); } + //======================================================================== // Return the current clipboard contents //======================================================================== @@ -155,16 +164,16 @@ size_t _glfwPlatformGetClipboardData(void *data, size_t size, int format) // format with preference for more appropriate formats first Atom *xcbrd = _glfwLibrary.X11.selection.atoms.clipboard; Atom *xcbrdend = _glfwLibrary.X11.selection.atoms.clipboard + - _GLFW_CLIPBOARD_ATOM_COUNT; + _GLFW_CLIPBOARD_ATOM_COUNT; Atom *xfmt = getInternalFormat(format); Atom *xfmtend = xfmt + _GLFW_STRING_ATOM_COUNT; // Get the currently active window Window window = _glfwLibrary.activeWindow->X11.handle; - for (; xcbrd != xcbrdend; xcbrd++) + for ( ; xcbrd != xcbrdend; xcbrd++) { - for (; xfmt != xfmtend; xfmt++) + for ( ; xfmt != xfmtend; xfmt++) { // Specify the format we would like. _glfwLibrary.X11.selection.request = *xfmt; @@ -218,21 +227,23 @@ size_t _glfwPlatformGetClipboardData(void *data, size_t size, int format) if (rembytes > 0) { int result = XGetWindowProperty(_glfwLibrary.X11.display, window, - *xfmt, 0, rembytes, 0, - AnyPropertyType, &type, &fmt, - &len, &dummy, &d); + *xfmt, 0, rembytes, 0, + AnyPropertyType, &type, &fmt, + &len, &dummy, &d); if (result == Success) { size_t s = size - 1 > rembytes ? rembytes : size - 1; + // Copy the data out. memcpy(data, d, s); + // Null-terminate strings. if (format == GLFW_CLIPBOARD_FORMAT_STRING) - { ((char *)data)[s] = '\0'; - } + // Free the data allocated using X11. XFree(d); + // Return the actual number of bytes. return rembytes; } @@ -243,6 +254,7 @@ size_t _glfwPlatformGetClipboardData(void *data, size_t size, int format) return 0; } } + return 0; } From a1d5fc039d39ee1a925874ce3abbed0a821133f1 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 28 Mar 2012 15:07:47 +0200 Subject: [PATCH 119/226] Added support for right control key. --- tests/clipboard.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/tests/clipboard.c b/tests/clipboard.c index cdbba6d2..16249f8a 100644 --- a/tests/clipboard.c +++ b/tests/clipboard.c @@ -39,15 +39,14 @@ static void usage(void) printf("Usage: clipboard [-h]\n"); } +static GLboolean control_is_down(void) +{ + return glfwGetKey(GLFW_KEY_LEFT_CONTROL) || + glfwGetKey(GLFW_KEY_RIGHT_CONTROL); +} + static void key_callback(GLFWwindow window, int key, int action) { - static int control = GL_FALSE; - if (key == GLFW_KEY_LEFT_CONTROL) - { - control = (action == GLFW_PRESS); - return; - } - if (action != GLFW_PRESS) return; @@ -57,7 +56,7 @@ static void key_callback(GLFWwindow window, int key, int action) glfwCloseWindow(window); break; case GLFW_KEY_V: - if (control) + if (control_is_down()) { char buffer[4096]; size_t size; @@ -71,7 +70,7 @@ static void key_callback(GLFWwindow window, int key, int action) } break; case GLFW_KEY_C: - if (control) + if (control_is_down()) { glfwSetClipboardData("Hello GLFW World!", sizeof("Hello GLFW World!"), GLFW_CLIPBOARD_FORMAT_STRING); From e4328af790de86d14811a10a1f266c30f08f9a33 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 28 Mar 2012 16:08:55 +0200 Subject: [PATCH 120/226] Formatting. --- src/x11_platform.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/x11_platform.h b/src/x11_platform.h index c6be6db3..2e6bbc21 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -236,15 +236,15 @@ typedef struct _GLFWlibraryX11 // Selection data struct { - struct { - Atom clipboard[_GLFW_CLIPBOARD_ATOM_COUNT]; - Atom string[_GLFW_STRING_ATOM_COUNT]; - } atoms; - struct { - size_t stringlen; - char *string; - } clipboard; - Atom request; + struct { + Atom clipboard[_GLFW_CLIPBOARD_ATOM_COUNT]; + Atom string[_GLFW_STRING_ATOM_COUNT]; + } atoms; + struct { + size_t stringlen; + char *string; + } clipboard; + Atom request; int converted; } selection; From 4ef9aec7e049d8c6b09c7d7a5441d9236c7d78f7 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 28 Mar 2012 21:54:09 +0200 Subject: [PATCH 121/226] Made scrolling deltas floating point. --- examples/wave.c | 4 ++-- include/GL/glfw3.h | 4 ++-- readme.html | 2 +- src/cocoa_platform.h | 2 -- src/cocoa_window.m | 9 +-------- src/input.c | 4 ++-- src/internal.h | 4 ++-- src/win32_window.c | 4 ++-- src/x11_window.c | 8 ++++---- tests/events.c | 4 ++-- 10 files changed, 18 insertions(+), 27 deletions(-) diff --git a/examples/wave.c b/examples/wave.c index 1eb8b855..8ecee51f 100644 --- a/examples/wave.c +++ b/examples/wave.c @@ -341,9 +341,9 @@ void mouse_position_callback(GLFWwindow window, int x, int y) // Callback function for scroll events //======================================================================== -void scroll_callback(GLFWwindow window, int x, int y) +void scroll_callback(GLFWwindow window, double x, double y) { - zoom += y / 4.f; + zoom += (float) y / 4.f; if (zoom < 0) zoom = 0; } diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 4a2c5145..7807edbc 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -482,7 +482,7 @@ typedef void (* GLFWwindowiconifyfun)(GLFWwindow,int); typedef void (* GLFWmousebuttonfun)(GLFWwindow,int,int); typedef void (* GLFWmouseposfun)(GLFWwindow,int,int); typedef void (* GLFWcursorenterfun)(GLFWwindow,int); -typedef void (* GLFWscrollfun)(GLFWwindow,int,int); +typedef void (* GLFWscrollfun)(GLFWwindow,double,double); typedef void (* GLFWkeyfun)(GLFWwindow,int,int); typedef void (* GLFWcharfun)(GLFWwindow,int); @@ -561,7 +561,7 @@ GLFWAPI int glfwGetKey(GLFWwindow window, int key); GLFWAPI int glfwGetMouseButton(GLFWwindow window, int button); GLFWAPI void glfwGetMousePos(GLFWwindow window, int* xpos, int* ypos); GLFWAPI void glfwSetMousePos(GLFWwindow window, int xpos, int ypos); -GLFWAPI void glfwGetScrollOffset(GLFWwindow window, int* xoffset, int* yoffset); +GLFWAPI void glfwGetScrollOffset(GLFWwindow window, double* xoffset, double* yoffset); GLFWAPI void glfwSetKeyCallback(GLFWkeyfun cbfun); GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun); GLFWAPI void glfwSetMouseButtonCallback(GLFWmousebuttonfun cbfun); diff --git a/readme.html b/readme.html index d8f22094..3e0966c0 100644 --- a/readme.html +++ b/readme.html @@ -292,7 +292,7 @@ version of GLFW.

    • 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
    • +
    • Replaced mouse wheel interface with two-dimensional, floating point scrolling interface
    • Replaced glfwEnable and glfwDisable with glfwGetInputMode and glfwSetInputMode
    • Made Unicode character input unaffected by GLFW_KEY_REPEAT
    • Removed event auto-polling and the GLFW_AUTO_POLL_EVENTS window enable
    • diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index b70fb184..26cc431e 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -75,8 +75,6 @@ typedef struct _GLFWwindowNS id window; id delegate; unsigned int modifierFlags; - double fracScrollX; - double fracScrollY; } _GLFWwindowNS; diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 5cd7ee3e..6ad5caab 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -479,14 +479,7 @@ static int convertMacKeyCode(unsigned int macKeyCode) - (void)scrollWheel:(NSEvent *)event { - double deltaX = window->NS.fracScrollX + [event deltaX]; - double deltaY = window->NS.fracScrollY + [event deltaY]; - - if ((int) deltaX || (int) deltaY) - _glfwInputScroll(window, (int) deltaX, (int) deltaY); - - window->NS.fracScrollX = (int) (deltaX - floor(deltaX)); - window->NS.fracScrollY = (int) (deltaY - floor(deltaY)); + _glfwInputScroll(window, [event deltaX], [event deltaY]); } @end diff --git a/src/input.c b/src/input.c index 1074ded5..ac37af0d 100644 --- a/src/input.c +++ b/src/input.c @@ -200,7 +200,7 @@ void _glfwInputChar(_GLFWwindow* window, int character) // Register scroll events //======================================================================== -void _glfwInputScroll(_GLFWwindow* window, int xoffset, int yoffset) +void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset) { window->scrollX += xoffset; window->scrollY += yoffset; @@ -476,7 +476,7 @@ GLFWAPI void glfwSetMousePos(GLFWwindow handle, int xpos, int ypos) // Returns the scroll offset for the specified window //======================================================================== -GLFWAPI void glfwGetScrollOffset(GLFWwindow handle, int* xoffset, int* yoffset) +GLFWAPI void glfwGetScrollOffset(GLFWwindow handle, double* xoffset, double* yoffset) { _GLFWwindow* window = (_GLFWwindow*) handle; diff --git a/src/internal.h b/src/internal.h index 44141e66..1e973a0e 100644 --- a/src/internal.h +++ b/src/internal.h @@ -186,7 +186,7 @@ struct _GLFWwindow GLboolean systemKeys; // system keys enabled flag int cursorPosX, cursorPosY; int cursorMode; - int scrollX, scrollY; + double scrollX, scrollY; char mouseButton[GLFW_MOUSE_BUTTON_LAST + 1]; char key[GLFW_KEY_LAST + 1]; @@ -343,7 +343,7 @@ void _glfwInputWindowDamage(_GLFWwindow* window); // Input event notification (input.c) void _glfwInputKey(_GLFWwindow* window, int key, int action); void _glfwInputChar(_GLFWwindow* window, int character); -void _glfwInputScroll(_GLFWwindow* window, int x, int y); +void _glfwInputScroll(_GLFWwindow* window, double x, double y); void _glfwInputMouseClick(_GLFWwindow* window, int button, int action); void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y); void _glfwInputCursorEnter(_GLFWwindow* window, int entered); diff --git a/src/win32_window.c b/src/win32_window.c index d73e73c3..6127bc46 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1022,7 +1022,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, case WM_MOUSEWHEEL: { - _glfwInputScroll(window, 0, (((int) wParam) >> 16) / WHEEL_DELTA); + _glfwInputScroll(window, 0.0, (SHORT) HIWORD(wParam) / (double) WHEEL_DELTA); return 0; } @@ -1030,7 +1030,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, { // This message is only sent on Windows Vista and later - _glfwInputScroll(window, (((int) wParam) >> 16) / WHEEL_DELTA, 0); + _glfwInputScroll(window, (SHORT) HIWORD(wParam) / (double) WHEEL_DELTA, 0.0); return 0; } diff --git a/src/x11_window.c b/src/x11_window.c index fe3b98a1..8faf2621 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -1144,14 +1144,14 @@ static void processSingleEvent(void) // XFree86 3.3.2 and later translates mouse wheel up/down into // mouse button 4 & 5 presses else if (event.xbutton.button == Button4) - _glfwInputScroll(window, 0, 1); + _glfwInputScroll(window, 0.0, 1.0); else if (event.xbutton.button == Button5) - _glfwInputScroll(window, 0, -1); + _glfwInputScroll(window, 0.0, -1.0); else if (event.xbutton.button == Button6) - _glfwInputScroll(window, -1, 0); + _glfwInputScroll(window, -1.0, 0.0); else if (event.xbutton.button == Button7) - _glfwInputScroll(window, 1, 0); + _glfwInputScroll(window, 1.0, 0.0); break; } diff --git a/tests/events.c b/tests/events.c index 3bf2ca6c..cc79da62 100644 --- a/tests/events.c +++ b/tests/events.c @@ -283,9 +283,9 @@ static void cursor_enter_callback(GLFWwindow window, int entered) entered ? "entered" : "left"); } -static void scroll_callback(GLFWwindow window, int x, int y) +static void scroll_callback(GLFWwindow window, double x, double y) { - printf("%08x at %0.3f: Scroll: %i %i\n", counter++, glfwGetTime(), x, y); + printf("%08x at %0.3f: Scroll: %0.3f %0.3f\n", counter++, glfwGetTime(), x, y); } static void key_callback(GLFWwindow window, int key, int action) From 171db6d6cb76ec7afddb2f8e4a876c6c65ab865d Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 28 Mar 2012 22:39:48 +0200 Subject: [PATCH 122/226] Discarded uninteresting scroll events. --- src/cocoa_window.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 5d8c00d4..9e64b2d3 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -479,7 +479,11 @@ static int convertMacKeyCode(unsigned int macKeyCode) - (void)scrollWheel:(NSEvent *)event { - _glfwInputScroll(window, [event deltaX], [event deltaY]); + double deltaX = [event deltaX]; + double deltaY = [event deltaY]; + + if (fabs(deltaX) > 0.0 || fabs(deltaY) > 0.0) + _glfwInputScroll(window, deltaX, deltaY); } @end From e49f1b88011838fafe705a8fd00d54f280f27f4a Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 29 Mar 2012 13:30:40 +0200 Subject: [PATCH 123/226] Fixed broken example. --- tests/clipboard.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/clipboard.c b/tests/clipboard.c index 16249f8a..5388ba4d 100644 --- a/tests/clipboard.c +++ b/tests/clipboard.c @@ -39,10 +39,10 @@ static void usage(void) printf("Usage: clipboard [-h]\n"); } -static GLboolean control_is_down(void) +static GLboolean control_is_down(GLFWwindow window) { - return glfwGetKey(GLFW_KEY_LEFT_CONTROL) || - glfwGetKey(GLFW_KEY_RIGHT_CONTROL); + return glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) || + glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL); } static void key_callback(GLFWwindow window, int key, int action) @@ -56,7 +56,7 @@ static void key_callback(GLFWwindow window, int key, int action) glfwCloseWindow(window); break; case GLFW_KEY_V: - if (control_is_down()) + if (control_is_down(window)) { char buffer[4096]; size_t size; @@ -66,11 +66,11 @@ static void key_callback(GLFWwindow window, int key, int action) { printf("Buffer wasn't big enough to hold clipboard data.\n"); } - printf("[%ld]: %s\n", size, buffer); + printf("[%lu]: %s\n", (unsigned long) size, buffer); } break; case GLFW_KEY_C: - if (control_is_down()) + if (control_is_down(window)) { glfwSetClipboardData("Hello GLFW World!", sizeof("Hello GLFW World!"), GLFW_CLIPBOARD_FORMAT_STRING); From cca6b521208bcdc693dffc28922713064d647d6b Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 29 Mar 2012 13:31:19 +0200 Subject: [PATCH 124/226] Formatting. --- tests/clipboard.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/clipboard.c b/tests/clipboard.c index 5388ba4d..0065e0a6 100644 --- a/tests/clipboard.c +++ b/tests/clipboard.c @@ -60,12 +60,13 @@ static void key_callback(GLFWwindow window, int key, int action) { char buffer[4096]; size_t size; + printf("Paste test.\n"); + size = glfwGetClipboardData(buffer, sizeof(buffer), GLFW_CLIPBOARD_FORMAT_STRING); if (size >= sizeof(buffer)) - { printf("Buffer wasn't big enough to hold clipboard data.\n"); - } + printf("[%lu]: %s\n", (unsigned long) size, buffer); } break; From 2ad5764f0627b6a949ac7e69f21f177a5d58db0b Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 29 Mar 2012 13:44:55 +0200 Subject: [PATCH 125/226] Formatting. --- tests/clipboard.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/clipboard.c b/tests/clipboard.c index 0065e0a6..1960d6ec 100644 --- a/tests/clipboard.c +++ b/tests/clipboard.c @@ -55,6 +55,7 @@ static void key_callback(GLFWwindow window, int key, int action) case GLFW_KEY_ESCAPE: glfwCloseWindow(window); break; + case GLFW_KEY_V: if (control_is_down(window)) { @@ -70,6 +71,7 @@ static void key_callback(GLFWwindow window, int key, int action) printf("[%lu]: %s\n", (unsigned long) size, buffer); } break; + case GLFW_KEY_C: if (control_is_down(window)) { From dd8b098387f45289c2faae7b1cddf51a3d7eea96 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 29 Mar 2012 14:06:26 +0200 Subject: [PATCH 126/226] Moved _GLFW_BUILD_DLL into configuration header. --- CMakeLists.txt | 7 +++++++ src/CMakeLists.txt | 2 +- src/cocoa_init.m | 6 +++++- src/config.h.in | 3 +++ src/x11_init.c | 3 +++ 5 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 57f4d16b..db1e363a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,13 @@ if (CMAKE_COMPILER_IS_GNUCC) add_definitions(-Wall) endif() +#-------------------------------------------------------------------- +# Export shared library / dynamic library / DLL build option +#-------------------------------------------------------------------- +if (BUILD_SHARED_LIBS) + set(_GLFW_BUILD_DLL 1) +endif() + #-------------------------------------------------------------------- # Detect and select target platform #-------------------------------------------------------------------- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ae72cda7..1b8a26e3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,7 +36,7 @@ if (BUILD_SHARED_LIBS) if (_GLFW_WIN32_WGL) # The GLFW DLL needs a special compile-time macro and import library name set_target_properties(glfw PROPERTIES - COMPILE_DEFINITIONS "_GLFW_BUILD_DLL;_GLFW_NO_DLOAD_GDI32;_GLFW_NO_DLOAD_WINMM" + COMPILE_DEFINITIONS "_GLFW_NO_DLOAD_GDI32;_GLFW_NO_DLOAD_WINMM" PREFIX "" IMPORT_PREFIX "" IMPORT_SUFFIX "dll.lib") diff --git a/src/cocoa_init.m b/src/cocoa_init.m index 16bd98eb..594266d1 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -152,7 +152,11 @@ int _glfwPlatformTerminate(void) const char* _glfwPlatformGetVersionString(void) { - const char* version = _GLFW_VERSION_FULL " Cocoa"; + const char* version = _GLFW_VERSION_FULL +#if defined(_GLFW_BUILD_DLL) + " dynamic" +#endif + ; return version; } diff --git a/src/config.h.in b/src/config.h.in index 46a6e2aa..c21212e7 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -42,6 +42,9 @@ // Define this to 1 if building GLFW for Cocoa/NSOpenGL #cmakedefine _GLFW_COCOA_NSGL +// Define this to 1 if building as a shared library / dynamic library / DLL +#cmakedefine _GLFW_BUILD_DLL 1 + // Define this to 1 if XRandR is available #cmakedefine _GLFW_HAS_XRANDR 1 // Define this to 1 if Xf86VidMode is available diff --git a/src/x11_init.c b/src/x11_init.c index d57af27e..9cec8e22 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -660,6 +660,9 @@ const char* _glfwPlatformGetVersionString(void) " Linux-joystick-API" #else " no-joystick-support" +#endif +#if defined(_GLFW_BUILD_DLL) + " shared" #endif ; From fcf54b4b27495b235c32852a319ca0efa2d5a95c Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 29 Mar 2012 14:21:04 +0200 Subject: [PATCH 127/226] Moved dynamic loading macros to configuration header. --- CMakeLists.txt | 3 +++ src/CMakeLists.txt | 1 - src/config.h.in | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index db1e363a..089132f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,9 @@ if (_GLFW_WIN32_WGL) list(APPEND glfw_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR}) list(APPEND glfw_LIBRARIES ${OPENGL_gl_LIBRARY}) + set(_GLFW_NO_DLOAD_GDI32 ${BUILD_SHARED_LIBS}) + set(_GLFW_NO_DLOAD_WINMM ${BUILD_SHARED_LIBS}) + if (BUILD_SHARED_LIBS) list(APPEND glfw_LIBRARIES winmm) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1b8a26e3..01ff500c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,7 +36,6 @@ if (BUILD_SHARED_LIBS) if (_GLFW_WIN32_WGL) # The GLFW DLL needs a special compile-time macro and import library name set_target_properties(glfw PROPERTIES - COMPILE_DEFINITIONS "_GLFW_NO_DLOAD_GDI32;_GLFW_NO_DLOAD_WINMM" PREFIX "" IMPORT_PREFIX "" IMPORT_SUFFIX "dll.lib") diff --git a/src/config.h.in b/src/config.h.in index c21212e7..b099dd9b 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -45,6 +45,11 @@ // Define this to 1 if building as a shared library / dynamic library / DLL #cmakedefine _GLFW_BUILD_DLL 1 +// Define this to 1 to disable dynamic loading of gdi32 +#cmakedefine _GLFW_NO_DLOAD_GDI32 1 +// Define this to 1 to disable dynamic loading of winmm +#cmakedefine _GLFW_NO_DLOAD_WINMM 1 + // Define this to 1 if XRandR is available #cmakedefine _GLFW_HAS_XRANDR 1 // Define this to 1 if Xf86VidMode is available From 3bcde7e1cd291a491e5482881fbd05ea932bf663 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Thu, 29 Mar 2012 17:41:05 -0400 Subject: [PATCH 128/226] Only define Win32 crud macros if not defined already --- src/win32_platform.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/win32_platform.h b/src/win32_platform.h index 63a372d7..7bfd5995 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -33,8 +33,13 @@ // We don't need all the fancy stuff -#define NOMINMAX -#define VC_EXTRALEAN +#ifndef NOMINMAX + #define NOMINMAX +#endif + +#ifndef VC_EXTRALEAN + #define VC_EXTRALEAN +#endif #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN From cd44a7182b15e7950a821f6d8c2a4a60b68548fe Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 30 Mar 2012 01:54:50 +0200 Subject: [PATCH 129/226] Removed re-definitions of Win32 things now ancient. --- src/win32_platform.h | 82 -------------------------------------------- 1 file changed, 82 deletions(-) diff --git a/src/win32_platform.h b/src/win32_platform.h index 7bfd5995..abd6a9e0 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -73,92 +73,10 @@ // Hack: Define things that some windows.h variants don't //======================================================================== -// Some old versions of w32api (used by MinGW and Cygwin) define -// WH_KEYBOARD_LL without typedef:ing KBDLLHOOKSTRUCT (!) -#if defined(__MINGW32__) || defined(__CYGWIN__) - #include - #if defined(WH_KEYBOARD_LL) && (__W32API_MAJOR_VERSION == 1) && (__W32API_MINOR_VERSION <= 2) - #undef WH_KEYBOARD_LL - #endif -#endif - -//------------------------------------------------------------------------ -// ** NOTE ** If this gives you compiler errors and you are using MinGW -// (or Dev-C++), update to w32api version 1.3 or later: -// http://sourceforge.net/project/showfiles.php?group_id=2435 -//------------------------------------------------------------------------ -#ifndef WH_KEYBOARD_LL -#define WH_KEYBOARD_LL 13 -typedef struct tagKBDLLHOOKSTRUCT { - DWORD vkCode; - DWORD scanCode; - DWORD flags; - DWORD time; - DWORD dwExtraInfo; -} KBDLLHOOKSTRUCT, FAR *LPKBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT; -#endif // WH_KEYBOARD_LL - -#ifndef LLKHF_ALTDOWN - #define LLKHF_ALTDOWN 0x00000020 -#endif - -#ifndef SPI_SETSCREENSAVERRUNNING - #define SPI_SETSCREENSAVERRUNNING 97 -#endif -#ifndef SPI_GETANIMATION - #define SPI_GETANIMATION 72 -#endif -#ifndef SPI_SETANIMATION - #define SPI_SETANIMATION 73 -#endif -#ifndef SPI_GETFOREGROUNDLOCKTIMEOUT - #define SPI_GETFOREGROUNDLOCKTIMEOUT 0x2000 -#endif -#ifndef SPI_SETFOREGROUNDLOCKTIMEOUT - #define SPI_SETFOREGROUNDLOCKTIMEOUT 0x2001 -#endif - -#ifndef CDS_FULLSCREEN - #define CDS_FULLSCREEN 4 -#endif - -#ifndef PFD_GENERIC_ACCELERATED - #define PFD_GENERIC_ACCELERATED 0x00001000 -#endif -#ifndef PFD_DEPTH_DONTCARE - #define PFD_DEPTH_DONTCARE 0x20000000 -#endif - -#ifndef ENUM_CURRENT_SETTINGS - #define ENUM_CURRENT_SETTINGS -1 -#endif -#ifndef ENUM_REGISTRY_SETTINGS - #define ENUM_REGISTRY_SETTINGS -2 -#endif - -#ifndef WM_MOUSEWHEEL - #define WM_MOUSEWHEEL 0x020A -#endif -#ifndef WHEEL_DELTA - #define WHEEL_DELTA 120 -#endif #ifndef WM_MOUSEHWHEEL #define WM_MOUSEHWHEEL 0x020E #endif -#ifndef WM_XBUTTONDOWN - #define WM_XBUTTONDOWN 0x020B -#endif -#ifndef WM_XBUTTONUP - #define WM_XBUTTONUP 0x020C -#endif -#ifndef XBUTTON1 - #define XBUTTON1 1 -#endif -#ifndef XBUTTON2 - #define XBUTTON2 2 -#endif - //======================================================================== // DLLs that are loaded at glfwInit() From 532e0dd2f6f3f340d15682a27ddc22e62f3b177e Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 30 Mar 2012 01:55:28 +0200 Subject: [PATCH 130/226] Formatting. --- src/win32_platform.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/win32_platform.h b/src/win32_platform.h index abd6a9e0..fe9f9399 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -57,7 +57,7 @@ // GLFW requires Windows XP #ifndef WINVER -#define WINVER 0x0501 + #define WINVER 0x0501 #endif #include From 2753577dbdc6c6e79a7116d31550f5b0b16379a2 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 30 Mar 2012 02:28:15 +0200 Subject: [PATCH 131/226] Removed dynamic loading of gdi32. --- CMakeLists.txt | 1 - src/config.h.in | 2 -- src/win32_gamma.c | 4 ++-- src/win32_init.c | 45 -------------------------------------------- src/win32_opengl.c | 2 +- src/win32_platform.h | 44 ------------------------------------------- src/win32_window.c | 26 ++++++++++++------------- 7 files changed, 16 insertions(+), 108 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 089132f6..44dcb4d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,7 +54,6 @@ if (_GLFW_WIN32_WGL) list(APPEND glfw_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR}) list(APPEND glfw_LIBRARIES ${OPENGL_gl_LIBRARY}) - set(_GLFW_NO_DLOAD_GDI32 ${BUILD_SHARED_LIBS}) set(_GLFW_NO_DLOAD_WINMM ${BUILD_SHARED_LIBS}) if (BUILD_SHARED_LIBS) diff --git a/src/config.h.in b/src/config.h.in index b099dd9b..a5b3172d 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -45,8 +45,6 @@ // Define this to 1 if building as a shared library / dynamic library / DLL #cmakedefine _GLFW_BUILD_DLL 1 -// Define this to 1 to disable dynamic loading of gdi32 -#cmakedefine _GLFW_NO_DLOAD_GDI32 1 // Define this to 1 to disable dynamic loading of winmm #cmakedefine _GLFW_NO_DLOAD_WINMM 1 diff --git a/src/win32_gamma.c b/src/win32_gamma.c index f131c3bd..36fbd3a4 100644 --- a/src/win32_gamma.c +++ b/src/win32_gamma.c @@ -42,7 +42,7 @@ void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp) { - _glfw_GetDeviceGammaRamp(GetDC(GetDesktopWindow()), (WORD*) ramp); + GetDeviceGammaRamp(GetDC(GetDesktopWindow()), (WORD*) ramp); } @@ -52,6 +52,6 @@ void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp) void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp) { - _glfw_SetDeviceGammaRamp(GetDC(GetDesktopWindow()), (WORD*) ramp); + SetDeviceGammaRamp(GetDC(GetDesktopWindow()), (WORD*) ramp); } diff --git a/src/win32_init.c b/src/win32_init.c index 55232fd7..2422dd4b 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -44,40 +44,6 @@ static GLboolean initLibraries(void) { -#ifndef _GLFW_NO_DLOAD_GDI32 - // gdi32.dll (OpenGL pixel format functions & SwapBuffers) - - _glfwLibrary.Win32.gdi.instance = LoadLibrary(L"gdi32.dll"); - if (!_glfwLibrary.Win32.gdi.instance) - return GL_FALSE; - - _glfwLibrary.Win32.gdi.ChoosePixelFormat = (CHOOSEPIXELFORMAT_T) - GetProcAddress(_glfwLibrary.Win32.gdi.instance, "ChoosePixelFormat"); - _glfwLibrary.Win32.gdi.DescribePixelFormat = (DESCRIBEPIXELFORMAT_T) - GetProcAddress(_glfwLibrary.Win32.gdi.instance, "DescribePixelFormat"); - _glfwLibrary.Win32.gdi.GetPixelFormat = (GETPIXELFORMAT_T) - GetProcAddress(_glfwLibrary.Win32.gdi.instance, "GetPixelFormat"); - _glfwLibrary.Win32.gdi.SetPixelFormat = (SETPIXELFORMAT_T) - GetProcAddress(_glfwLibrary.Win32.gdi.instance, "SetPixelFormat"); - _glfwLibrary.Win32.gdi.SwapBuffers = (SWAPBUFFERS_T) - GetProcAddress(_glfwLibrary.Win32.gdi.instance, "SwapBuffers"); - _glfwLibrary.Win32.gdi.GetDeviceGammaRamp = (GETDEVICEGAMMARAMP_T) - GetProcAddress(_glfwLibrary.Win32.gdi.instance, "GetDeviceGammaRamp"); - _glfwLibrary.Win32.gdi.SetDeviceGammaRamp = (SETDEVICEGAMMARAMP_T) - GetProcAddress(_glfwLibrary.Win32.gdi.instance, "SetDeviceGammaRamp"); - - if (!_glfwLibrary.Win32.gdi.ChoosePixelFormat || - !_glfwLibrary.Win32.gdi.DescribePixelFormat || - !_glfwLibrary.Win32.gdi.GetPixelFormat || - !_glfwLibrary.Win32.gdi.SetPixelFormat || - !_glfwLibrary.Win32.gdi.SwapBuffers || - !_glfwLibrary.Win32.gdi.GetDeviceGammaRamp || - !_glfwLibrary.Win32.gdi.SetDeviceGammaRamp) - { - return GL_FALSE; - } -#endif // _GLFW_NO_DLOAD_GDI32 - #ifndef _GLFW_NO_DLOAD_WINMM // winmm.dll (for joystick and timer support) @@ -113,14 +79,6 @@ static GLboolean initLibraries(void) static void freeLibraries(void) { -#ifndef _GLFW_NO_DLOAD_GDI32 - if (_glfwLibrary.Win32.gdi.instance != NULL) - { - FreeLibrary(_glfwLibrary.Win32.gdi.instance); - _glfwLibrary.Win32.gdi.instance = NULL; - } -#endif // _GLFW_NO_DLOAD_GDI32 - #ifndef _GLFW_NO_DLOAD_WINMM if (_glfwLibrary.Win32.winmm.instance != NULL) { @@ -274,9 +232,6 @@ const char* _glfwPlatformGetVersionString(void) #if defined(_GLFW_BUILD_DLL) " DLL" #endif -#if !defined(_GLFW_NO_DLOAD_GDI32) - " load(gdi32)" -#endif #if !defined(_GLFW_NO_DLOAD_WINMM) " load(winmm)" #endif diff --git a/src/win32_opengl.c b/src/win32_opengl.c index 0ffd594c..2262c222 100644 --- a/src/win32_opengl.c +++ b/src/win32_opengl.c @@ -56,7 +56,7 @@ void _glfwPlatformSwapBuffers(void) { _GLFWwindow* window = _glfwLibrary.currentWindow; - _glfw_SwapBuffers(window->WGL.DC); + SwapBuffers(window->WGL.DC); } diff --git a/src/win32_platform.h b/src/win32_platform.h index fe9f9399..b2ba9182 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -82,17 +82,6 @@ // DLLs that are loaded at glfwInit() //======================================================================== -// gdi32.dll function pointer typedefs -#ifndef _GLFW_NO_DLOAD_GDI32 -typedef int (WINAPI * CHOOSEPIXELFORMAT_T) (HDC,CONST PIXELFORMATDESCRIPTOR*); -typedef int (WINAPI * DESCRIBEPIXELFORMAT_T) (HDC,int,UINT,LPPIXELFORMATDESCRIPTOR); -typedef int (WINAPI * GETPIXELFORMAT_T) (HDC); -typedef BOOL (WINAPI * SETPIXELFORMAT_T) (HDC,int,const PIXELFORMATDESCRIPTOR*); -typedef BOOL (WINAPI * SWAPBUFFERS_T) (HDC); -typedef BOOL (WINAPI * GETDEVICEGAMMARAMP_T) (HDC,PVOID); -typedef BOOL (WINAPI * SETDEVICEGAMMARAMP_T) (HDC,PVOID); -#endif // _GLFW_NO_DLOAD_GDI32 - // winmm.dll function pointer typedefs #ifndef _GLFW_NO_DLOAD_WINMM typedef MMRESULT (WINAPI * JOYGETDEVCAPS_T) (UINT,LPJOYCAPS,UINT); @@ -102,25 +91,6 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void); #endif // _GLFW_NO_DLOAD_WINMM -// gdi32.dll shortcuts -#ifndef _GLFW_NO_DLOAD_GDI32 - #define _glfw_ChoosePixelFormat _glfwLibrary.Win32.gdi.ChoosePixelFormat - #define _glfw_DescribePixelFormat _glfwLibrary.Win32.gdi.DescribePixelFormat - #define _glfw_GetPixelFormat _glfwLibrary.Win32.gdi.GetPixelFormat - #define _glfw_SetPixelFormat _glfwLibrary.Win32.gdi.SetPixelFormat - #define _glfw_SwapBuffers _glfwLibrary.Win32.gdi.SwapBuffers - #define _glfw_GetDeviceGammaRamp _glfwLibrary.Win32.gdi.GetDeviceGammaRamp - #define _glfw_SetDeviceGammaRamp _glfwLibrary.Win32.gdi.SetDeviceGammaRamp -#else - #define _glfw_ChoosePixelFormat ChoosePixelFormat - #define _glfw_DescribePixelFormat DescribePixelFormat - #define _glfw_GetPixelFormat GetPixelFormat - #define _glfw_SetPixelFormat SetPixelFormat - #define _glfw_SwapBuffers SwapBuffers - #define _glfw_GetDeviceGammaRamp GetDeviceGammaRamp - #define _glfw_SetDeviceGammaRamp SetDeviceGammaRamp -#endif // _GLFW_NO_DLOAD_GDI32 - // winmm.dll shortcuts #ifndef _GLFW_NO_DLOAD_WINMM #define _glfw_joyGetDevCaps _glfwLibrary.Win32.winmm.joyGetDevCaps @@ -225,20 +195,6 @@ typedef struct _GLFWlibraryWin32 __int64 t0_64; } timer; -#ifndef _GLFW_NO_DLOAD_GDI32 - // gdi32.dll - struct { - HINSTANCE instance; - CHOOSEPIXELFORMAT_T ChoosePixelFormat; - DESCRIBEPIXELFORMAT_T DescribePixelFormat; - GETPIXELFORMAT_T GetPixelFormat; - SETPIXELFORMAT_T SetPixelFormat; - SWAPBUFFERS_T SwapBuffers; - GETDEVICEGAMMARAMP_T GetDeviceGammaRamp; - SETDEVICEGAMMARAMP_T SetDeviceGammaRamp; - } gdi; -#endif // _GLFW_NO_DLOAD_GDI32 - #ifndef _GLFW_NO_DLOAD_WINMM // winmm.dll struct { diff --git a/src/win32_window.c b/src/win32_window.c index 6127bc46..42b73099 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -159,10 +159,10 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) count = getPixelFormatAttrib(window, 1, WGL_NUMBER_PIXEL_FORMATS_ARB); else { - count = _glfw_DescribePixelFormat(window->WGL.DC, - 1, - sizeof(PIXELFORMATDESCRIPTOR), - NULL); + count = DescribePixelFormat(window->WGL.DC, + 1, + sizeof(PIXELFORMATDESCRIPTOR), + NULL); } if (!count) @@ -243,10 +243,10 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) { // Get pixel format attributes through old-fashioned PFDs - if (!_glfw_DescribePixelFormat(window->WGL.DC, - i, - sizeof(PIXELFORMATDESCRIPTOR), - &pfd)) + if (!DescribePixelFormat(window->WGL.DC, + i, + sizeof(PIXELFORMATDESCRIPTOR), + &pfd)) { continue; } @@ -311,14 +311,14 @@ static GLboolean createContext(_GLFWwindow* window, if (wndconfig->share) share = wndconfig->share->WGL.context; - if (!_glfw_DescribePixelFormat(window->WGL.DC, pixelFormat, sizeof(pfd), &pfd)) + if (!DescribePixelFormat(window->WGL.DC, pixelFormat, sizeof(pfd), &pfd)) { _glfwSetError(GLFW_OPENGL_UNAVAILABLE, "Win32/WGL: Failed to retrieve PFD for selected pixel format"); return GL_FALSE; } - if (!_glfw_SetPixelFormat(window->WGL.DC, pixelFormat, &pfd)) + if (!SetPixelFormat(window->WGL.DC, pixelFormat, &pfd)) { _glfwSetError(GLFW_OPENGL_UNAVAILABLE, "Win32/WGL: Failed to set selected pixel format"); @@ -1673,7 +1673,7 @@ void _glfwPlatformRefreshWindowParams(void) _GLFWwindow* window = _glfwLibrary.currentWindow; // Obtain a detailed description of current pixel format - pixelFormat = _glfw_GetPixelFormat(window->WGL.DC); + pixelFormat = GetPixelFormat(window->WGL.DC); if (window->WGL.ARB_pixel_format) { @@ -1727,8 +1727,8 @@ void _glfwPlatformRefreshWindowParams(void) } else { - _glfw_DescribePixelFormat(window->WGL.DC, pixelFormat, - sizeof(PIXELFORMATDESCRIPTOR), &pfd); + DescribePixelFormat(window->WGL.DC, pixelFormat, + sizeof(PIXELFORMATDESCRIPTOR), &pfd); // Is current OpenGL context accelerated? window->accelerated = (pfd.dwFlags & PFD_GENERIC_ACCELERATED) || From 61264339a7b5e74940ca95149c4843ecac538d91 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 5 Apr 2012 16:14:01 +0200 Subject: [PATCH 132/226] Simplified X11 screen handling. --- src/x11_fullscreen.c | 69 ++++++++++++++++++++++++++++---------------- src/x11_platform.h | 8 ++--- src/x11_window.c | 10 +++---- 3 files changed, 52 insertions(+), 35 deletions(-) diff --git a/src/x11_fullscreen.c b/src/x11_fullscreen.c index 37a3ae98..7ad11ec5 100644 --- a/src/x11_fullscreen.c +++ b/src/x11_fullscreen.c @@ -42,7 +42,7 @@ // Finds the video mode closest in size to the specified desired size //======================================================================== -int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate) +int _glfwGetClosestVideoMode(int* width, int* height, int* rate) { int i, match, bestmatch; @@ -55,8 +55,7 @@ int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate) XRRScreenConfiguration* sc; XRRScreenSize* sizelist; - sc = XRRGetScreenInfo(_glfwLibrary.X11.display, - RootWindow(_glfwLibrary.X11.display, screen)); + sc = XRRGetScreenInfo(_glfwLibrary.X11.display, _glfwLibrary.X11.root); sizelist = XRRConfigSizes(sc, &sizecount); @@ -116,7 +115,8 @@ int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate) int bestmode, modecount; // Get a list of all available display modes - XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen, + XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, + _glfwLibrary.X11.screen, &modecount, &modelist); // Find the best matching mode @@ -150,8 +150,8 @@ int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate) } // Default: Simply use the screen resolution - *width = DisplayWidth(_glfwLibrary.X11.display, screen); - *height = DisplayHeight(_glfwLibrary.X11.display, screen); + *width = DisplayWidth(_glfwLibrary.X11.display, _glfwLibrary.X11.screen); + *height = DisplayHeight(_glfwLibrary.X11.display, _glfwLibrary.X11.screen); return 0; } @@ -161,7 +161,7 @@ int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate) // Change the current video mode //======================================================================== -void _glfwSetVideoModeMODE(int screen, int mode, int rate) +void _glfwSetVideoModeMODE(int mode, int rate) { if (_glfwLibrary.X11.RandR.available) { @@ -169,15 +169,17 @@ void _glfwSetVideoModeMODE(int screen, int mode, int rate) XRRScreenConfiguration* sc; Window root; - root = RootWindow(_glfwLibrary.X11.display, screen); + root = _glfwLibrary.X11.root; sc = XRRGetScreenInfo(_glfwLibrary.X11.display, root); // Remember old size and flag that we have changed the mode if (!_glfwLibrary.X11.FS.modeChanged) { _glfwLibrary.X11.FS.oldSizeID = XRRConfigCurrentConfiguration(sc, &_glfwLibrary.X11.FS.oldRotation); - _glfwLibrary.X11.FS.oldWidth = DisplayWidth(_glfwLibrary.X11.display, screen); - _glfwLibrary.X11.FS.oldHeight = DisplayHeight(_glfwLibrary.X11.display, screen); + _glfwLibrary.X11.FS.oldWidth = DisplayWidth(_glfwLibrary.X11.display, + _glfwLibrary.X11.screen); + _glfwLibrary.X11.FS.oldHeight = DisplayHeight(_glfwLibrary.X11.display, + _glfwLibrary.X11.screen); _glfwLibrary.X11.FS.modeChanged = GL_TRUE; } @@ -214,21 +216,32 @@ void _glfwSetVideoModeMODE(int screen, int mode, int rate) int modecount; // Get a list of all available display modes - XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen, + XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, + _glfwLibrary.X11.screen, &modecount, &modelist); // Unlock mode switch if necessary if (_glfwLibrary.X11.FS.modeChanged) - XF86VidModeLockModeSwitch(_glfwLibrary.X11.display, screen, 0); + { + XF86VidModeLockModeSwitch(_glfwLibrary.X11.display, + _glfwLibrary.X11.screen, + 0); + } // Change the video mode to the desired mode - XF86VidModeSwitchToMode(_glfwLibrary.X11.display, screen, modelist[mode]); + XF86VidModeSwitchToMode(_glfwLibrary.X11.display, + _glfwLibrary.X11.screen, + modelist[mode]); // Set viewport to upper left corner (where our window will be) - XF86VidModeSetViewPort(_glfwLibrary.X11.display, screen, 0, 0); + XF86VidModeSetViewPort(_glfwLibrary.X11.display, + _glfwLibrary.X11.screen, + 0, 0); // Lock mode switch - XF86VidModeLockModeSwitch(_glfwLibrary.X11.display, screen, 1); + XF86VidModeLockModeSwitch(_glfwLibrary.X11.display, + _glfwLibrary.X11.screen, + 1); // Remember old mode and flag that we have changed the mode if (!_glfwLibrary.X11.FS.modeChanged) @@ -247,15 +260,15 @@ void _glfwSetVideoModeMODE(int screen, int mode, int rate) // Change the current video mode //======================================================================== -void _glfwSetVideoMode(int screen, int* width, int* height, int* rate) +void _glfwSetVideoMode(int* width, int* height, int* rate) { int bestmode; // Find a best match mode - bestmode = _glfwGetClosestVideoMode(screen, width, height, rate); + bestmode = _glfwGetClosestVideoMode(width, height, rate); // Change mode - _glfwSetVideoModeMODE(screen, bestmode, *rate); + _glfwSetVideoModeMODE(bestmode, *rate); } @@ -263,7 +276,7 @@ void _glfwSetVideoMode(int screen, int* width, int* height, int* rate) // Restore the previously saved (original) video mode //======================================================================== -void _glfwRestoreVideoMode(int screen) +void _glfwRestoreVideoMode(void) { if (_glfwLibrary.X11.FS.modeChanged) { @@ -292,11 +305,13 @@ void _glfwRestoreVideoMode(int screen) { #if defined(_GLFW_HAS_XF86VIDMODE) // Unlock mode switch - XF86VidModeLockModeSwitch(_glfwLibrary.X11.display, screen, 0); + XF86VidModeLockModeSwitch(_glfwLibrary.X11.display, + _glfwLibrary.X11.screen, + 0); // Change the video mode back to the old mode XF86VidModeSwitchToMode(_glfwLibrary.X11.display, - screen, + _glfwLibrary.X11.screen, &_glfwLibrary.X11.FS.oldMode); #endif /*_GLFW_HAS_XF86VIDMODE*/ } @@ -323,7 +338,7 @@ struct _glfwResolution int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) { int count, k, l, r, g, b, rgba, gl; - int depth, screen = DefaultScreen(_glfwLibrary.X11.display); + int depth; XVisualInfo* vislist; XVisualInfo dummy; int viscount, rgbcount, rescount; @@ -407,7 +422,9 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) XF86VidModeModeInfo** modelist; int modecount, width, height; - XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, screen, &modecount, &modelist); + XF86VidModeGetAllModeLines(_glfwLibrary.X11.display, + _glfwLibrary.X11.screen, + &modecount, &modelist); resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * modecount); @@ -440,8 +457,10 @@ int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount) rescount = 1; resarray = (struct _glfwResolution*) malloc(sizeof(struct _glfwResolution) * rescount); - resarray[0].width = DisplayWidth(_glfwLibrary.X11.display, screen); - resarray[0].height = DisplayHeight(_glfwLibrary.X11.display, screen); + resarray[0].width = DisplayWidth(_glfwLibrary.X11.display, + _glfwLibrary.X11.screen); + resarray[0].height = DisplayHeight(_glfwLibrary.X11.display, + _glfwLibrary.X11.screen); } // Build permutations of colors and resolutions diff --git a/src/x11_platform.h b/src/x11_platform.h index 3b824d64..e101f9f8 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -250,10 +250,10 @@ GLFWGLOBAL struct { void _glfwInitTimer(void); // Fullscreen support -int _glfwGetClosestVideoMode(int screen, int* width, int* height, int* rate); -void _glfwSetVideoModeMODE(int screen, int mode, int rate); -void _glfwSetVideoMode(int screen, int* width, int* height, int* rate); -void _glfwRestoreVideoMode(int screen); +int _glfwGetClosestVideoMode(int* width, int* height, int* rate); +void _glfwSetVideoModeMODE(int mode, int rate); +void _glfwSetVideoMode(int* width, int* height, int* rate); +void _glfwRestoreVideoMode(void); // Joystick input void _glfwInitJoysticks(void); diff --git a/src/x11_window.c b/src/x11_window.c index 8faf2621..418f427f 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -908,8 +908,7 @@ static void enterFullscreenMode(_GLFWwindow* window) _glfwLibrary.X11.saver.changed = GL_TRUE; } - _glfwSetVideoMode(_glfwLibrary.X11.screen, - &window->width, &window->height, + _glfwSetVideoMode(&window->width, &window->height, &window->refreshRate); if (window->X11.hasEWMH && @@ -989,7 +988,7 @@ static void enterFullscreenMode(_GLFWwindow* window) static void leaveFullscreenMode(_GLFWwindow* window) { - _glfwRestoreVideoMode(_glfwLibrary.X11.screen); + _glfwRestoreVideoMode(); // Did we change the screen saver setting? if (_glfwLibrary.X11.saver.changed) @@ -1600,8 +1599,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) if (window->mode == GLFW_FULLSCREEN) { // Get the closest matching video mode for the specified window size - mode = _glfwGetClosestVideoMode(_glfwLibrary.X11.screen, - &width, &height, &rate); + mode = _glfwGetClosestVideoMode(&width, &height, &rate); } if (!window->resizable) @@ -1628,7 +1626,7 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) if (window->mode == GLFW_FULLSCREEN) { // Change video mode, keeping current refresh rate - _glfwSetVideoModeMODE(_glfwLibrary.X11.screen, mode, window->refreshRate); + _glfwSetVideoModeMODE(mode, window->refreshRate); } // Set window size (if not already changed) From 76615bf2370e410a60bb53f91fc3fe11b5cbf5c3 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 5 Apr 2012 17:29:08 +0200 Subject: [PATCH 133/226] Moved EWMH logic to library init. --- src/x11_init.c | 149 ++++++++++++++++++++++++++++++++ src/x11_platform.h | 19 +++-- src/x11_window.c | 206 ++++++--------------------------------------- 3 files changed, 187 insertions(+), 187 deletions(-) diff --git a/src/x11_init.c b/src/x11_init.c index 9cec8e22..b6c23563 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -33,6 +33,7 @@ #include #include #include +#include //======================================================================== @@ -369,6 +370,152 @@ static void updateKeyCodeLUT(void) } +//======================================================================== +// Retrieve a single window property of the specified type +// Inspired by fghGetWindowProperty from freeglut +//======================================================================== + +static unsigned long getWindowProperty(Window window, + Atom property, + Atom type, + unsigned char** value) +{ + Atom actualType; + int actualFormat; + unsigned long itemCount, bytesAfter; + + XGetWindowProperty(_glfwLibrary.X11.display, + window, + property, + 0, + LONG_MAX, + False, + type, + &actualType, + &actualFormat, + &itemCount, + &bytesAfter, + value); + + if (actualType != type) + return 0; + + return itemCount; +} + + +//======================================================================== +// Check whether the specified atom is supported +//======================================================================== + +static Atom getSupportedAtom(Atom* supportedAtoms, + unsigned long atomCount, + const char* atomName) +{ + Atom atom = XInternAtom(_glfwLibrary.X11.display, atomName, True); + if (atom != None) + { + unsigned long i; + + for (i = 0; i < atomCount; i++) + { + if (supportedAtoms[i] == atom) + return atom; + } + } + + return None; +} + + +//======================================================================== +// Check whether the running window manager is EWMH-compliant +//======================================================================== + +static void initEWMH(void) +{ + Window* windowFromRoot = NULL; + Window* windowFromChild = NULL; + + // First we need a couple of atoms, which should already be there + Atom supportingWmCheck = + XInternAtom(_glfwLibrary.X11.display, "_NET_SUPPORTING_WM_CHECK", True); + Atom wmSupported = + XInternAtom(_glfwLibrary.X11.display, "_NET_SUPPORTED", True); + if (supportingWmCheck == None || wmSupported == None) + return; + + // Then we look for the _NET_SUPPORTING_WM_CHECK property of the root window + if (getWindowProperty(_glfwLibrary.X11.root, + supportingWmCheck, + XA_WINDOW, + (unsigned char**) &windowFromRoot) != 1) + { + XFree(windowFromRoot); + return; + } + + // It should be the ID of a child window (of the root) + // Then we look for the same property on the child window + if (getWindowProperty(*windowFromRoot, + supportingWmCheck, + XA_WINDOW, + (unsigned char**) &windowFromChild) != 1) + { + XFree(windowFromRoot); + XFree(windowFromChild); + return; + } + + // It should be the ID of that same child window + if (*windowFromRoot != *windowFromChild) + { + XFree(windowFromRoot); + XFree(windowFromChild); + return; + } + + XFree(windowFromRoot); + XFree(windowFromChild); + + // We are now fairly sure that an EWMH-compliant window manager is running + + Atom* supportedAtoms; + unsigned long atomCount; + + // Now we need to check the _NET_SUPPORTED property of the root window + // It should be a list of supported WM protocol and state atoms + atomCount = getWindowProperty(_glfwLibrary.X11.root, + wmSupported, + XA_ATOM, + (unsigned char**) &supportedAtoms); + + // See which of the atoms we support that are supported by the WM + + _glfwLibrary.X11.wmState = + getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE"); + + _glfwLibrary.X11.wmStateFullscreen = + getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE_FULLSCREEN"); + + _glfwLibrary.X11.wmName = + getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_NAME"); + + _glfwLibrary.X11.wmIconName = + getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_ICON_NAME"); + + _glfwLibrary.X11.wmPing = + getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_PING"); + + _glfwLibrary.X11.wmActiveWindow = + getSupportedAtom(supportedAtoms, atomCount, "_NET_ACTIVE_WINDOW"); + + XFree(supportedAtoms); + + _glfwLibrary.X11.hasEWMH = GL_TRUE; +} + + //======================================================================== // Initialize X11 display and look for supported X11 extensions //======================================================================== @@ -580,6 +727,8 @@ int _glfwPlatformInit(void) initGammaRamp(); + initEWMH(); + _glfwLibrary.X11.cursor = createNULLCursor(); // Try to load libGL.so if necessary diff --git a/src/x11_platform.h b/src/x11_platform.h index e101f9f8..b3869bc4 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -133,16 +133,8 @@ typedef struct _GLFWwindowX11 // Platform specific window resources Colormap colormap; // Window colormap Window handle; // Window handle - Atom wmDeleteWindow; // WM_DELETE_WINDOW atom - Atom wmName; // _NET_WM_NAME atom - Atom wmIconName; // _NET_WM_ICON_NAME atom - Atom wmPing; // _NET_WM_PING atom - Atom wmState; // _NET_WM_STATE atom - Atom wmStateFullscreen; // _NET_WM_STATE_FULLSCREEN atom - Atom wmActiveWindow; // _NET_ACTIVE_WINDOW atom // Various platform specific internal variables - GLboolean hasEWMH; // True if window manager supports EWMH GLboolean overrideRedirect; // True if window is OverrideRedirect GLboolean keyboardGrabbed; // True if keyboard is currently grabbed GLboolean cursorGrabbed; // True if cursor is currently grabbed @@ -163,6 +155,17 @@ typedef struct _GLFWlibraryX11 Window root; Cursor cursor; // Invisible cursor for hidden cursor + Atom wmDeleteWindow; // WM_DELETE_WINDOW atom + Atom wmName; // _NET_WM_NAME atom + Atom wmIconName; // _NET_WM_ICON_NAME atom + Atom wmPing; // _NET_WM_PING atom + Atom wmState; // _NET_WM_STATE atom + Atom wmStateFullscreen; // _NET_WM_STATE_FULLSCREEN atom + Atom wmActiveWindow; // _NET_ACTIVE_WINDOW atom + + // True if window manager supports EWMH + GLboolean hasEWMH; + // Server-side GLX version int glxMajor, glxMinor; diff --git a/src/x11_window.c b/src/x11_window.c index 418f427f..a5058f00 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -30,7 +30,6 @@ #include "internal.h" -#include #include #include #include @@ -65,154 +64,6 @@ static Bool isMapNotify(Display* d, XEvent* e, char* arg) } -//======================================================================== -// Retrieve a single window property of the specified type -// Inspired by fghGetWindowProperty from freeglut -//======================================================================== - -static unsigned long getWindowProperty(Window window, - Atom property, - Atom type, - unsigned char** value) -{ - Atom actualType; - int actualFormat; - unsigned long itemCount, bytesAfter; - - XGetWindowProperty(_glfwLibrary.X11.display, - window, - property, - 0, - LONG_MAX, - False, - type, - &actualType, - &actualFormat, - &itemCount, - &bytesAfter, - value); - - if (actualType != type) - return 0; - - return itemCount; -} - - -//======================================================================== -// Check whether the specified atom is supported -//======================================================================== - -static Atom getSupportedAtom(Atom* supportedAtoms, - unsigned long atomCount, - const char* atomName) -{ - Atom atom = XInternAtom(_glfwLibrary.X11.display, atomName, True); - if (atom != None) - { - unsigned long i; - - for (i = 0; i < atomCount; i++) - { - if (supportedAtoms[i] == atom) - return atom; - } - } - - return None; -} - - -//======================================================================== -// Check whether the running window manager is EWMH-compliant -//======================================================================== - -static GLboolean hasEWMH(_GLFWwindow* window) -{ - Window* windowFromRoot = NULL; - Window* windowFromChild = NULL; - - // Hey kids; let's see if the window manager supports EWMH! - - // First we need a couple of atoms, which should already be there - Atom supportingWmCheck = - XInternAtom(_glfwLibrary.X11.display, "_NET_SUPPORTING_WM_CHECK", True); - Atom wmSupported = - XInternAtom(_glfwLibrary.X11.display, "_NET_SUPPORTED", True); - if (supportingWmCheck == None || wmSupported == None) - return GL_FALSE; - - // Then we look for the _NET_SUPPORTING_WM_CHECK property of the root window - if (getWindowProperty(_glfwLibrary.X11.root, - supportingWmCheck, - XA_WINDOW, - (unsigned char**) &windowFromRoot) != 1) - { - XFree(windowFromRoot); - return GL_FALSE; - } - - // It should be the ID of a child window (of the root) - // Then we look for the same property on the child window - if (getWindowProperty(*windowFromRoot, - supportingWmCheck, - XA_WINDOW, - (unsigned char**) &windowFromChild) != 1) - { - XFree(windowFromRoot); - XFree(windowFromChild); - return GL_FALSE; - } - - // It should be the ID of that same child window - if (*windowFromRoot != *windowFromChild) - { - XFree(windowFromRoot); - XFree(windowFromChild); - return GL_FALSE; - } - - XFree(windowFromRoot); - XFree(windowFromChild); - - // We are now fairly sure that an EWMH-compliant window manager is running - - Atom* supportedAtoms; - unsigned long atomCount; - - // Now we need to check the _NET_SUPPORTED property of the root window - // It should be a list of supported WM protocol and state atoms - atomCount = getWindowProperty(_glfwLibrary.X11.root, - wmSupported, - XA_ATOM, - (unsigned char**) &supportedAtoms); - - // See which of the atoms we support that are supported by the WM - - window->X11.wmState = - getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE"); - - window->X11.wmStateFullscreen = - getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_STATE_FULLSCREEN"); - - window->X11.wmName = - getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_NAME"); - - window->X11.wmIconName = - getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_ICON_NAME"); - - window->X11.wmPing = - getSupportedAtom(supportedAtoms, atomCount, "_NET_WM_PING"); - - window->X11.wmActiveWindow = - getSupportedAtom(supportedAtoms, atomCount, "_NET_ACTIVE_WINDOW"); - - XFree(supportedAtoms); - - return GL_TRUE; -} - - //======================================================================== // Translates an X Window key to internal coding //======================================================================== @@ -721,10 +572,7 @@ static GLboolean createWindow(_GLFWwindow* window, } } - // Check whether an EWMH-compliant window manager is running - window->X11.hasEWMH = hasEWMH(window); - - if (window->mode == GLFW_FULLSCREEN && !window->X11.hasEWMH) + if (window->mode == GLFW_FULLSCREEN && !_glfwLibrary.X11.hasEWMH) { // This is the butcher's way of removing window decorations // Setting the override-redirect attribute on a window makes the window @@ -745,9 +593,9 @@ static GLboolean createWindow(_GLFWwindow* window, } // Find or create the protocol atom for window close notifications - window->X11.wmDeleteWindow = XInternAtom(_glfwLibrary.X11.display, - "WM_DELETE_WINDOW", - False); + _glfwLibrary.X11.wmDeleteWindow = XInternAtom(_glfwLibrary.X11.display, + "WM_DELETE_WINDOW", + False); // Declare the WM protocols we support { @@ -756,14 +604,14 @@ static GLboolean createWindow(_GLFWwindow* window, // The WM_DELETE_WINDOW ICCCM protocol // Basic window close notification protocol - if (window->X11.wmDeleteWindow != None) - protocols[count++] = window->X11.wmDeleteWindow; + if (_glfwLibrary.X11.wmDeleteWindow != None) + protocols[count++] = _glfwLibrary.X11.wmDeleteWindow; // The _NET_WM_PING EWMH protocol // Tells the WM to ping our window and flag us as unresponsive if we // don't reply within a few seconds - if (window->X11.wmPing != None) - protocols[count++] = window->X11.wmPing; + if (_glfwLibrary.X11.wmPing != None) + protocols[count++] = _glfwLibrary.X11.wmPing; if (count > 0) { @@ -911,11 +759,11 @@ static void enterFullscreenMode(_GLFWwindow* window) _glfwSetVideoMode(&window->width, &window->height, &window->refreshRate); - if (window->X11.hasEWMH && - window->X11.wmState != None && - window->X11.wmStateFullscreen != None) + if (_glfwLibrary.X11.hasEWMH && + _glfwLibrary.X11.wmState != None && + _glfwLibrary.X11.wmStateFullscreen != None) { - if (window->X11.wmActiveWindow != None) + if (_glfwLibrary.X11.wmActiveWindow != None) { // Ask the window manager to raise and focus the GLFW window // Only focused windows with the _NET_WM_STATE_FULLSCREEN state end @@ -927,7 +775,7 @@ static void enterFullscreenMode(_GLFWwindow* window) event.type = ClientMessage; event.xclient.window = window->X11.handle; event.xclient.format = 32; // Data is 32-bit longs - event.xclient.message_type = window->X11.wmActiveWindow; + event.xclient.message_type = _glfwLibrary.X11.wmActiveWindow; event.xclient.data.l[0] = 1; // Sender is a normal application event.xclient.data.l[1] = 0; // We don't really know the timestamp @@ -948,9 +796,9 @@ static void enterFullscreenMode(_GLFWwindow* window) event.type = ClientMessage; event.xclient.window = window->X11.handle; event.xclient.format = 32; // Data is 32-bit longs - event.xclient.message_type = window->X11.wmState; + event.xclient.message_type = _glfwLibrary.X11.wmState; event.xclient.data.l[0] = _NET_WM_STATE_ADD; - event.xclient.data.l[1] = window->X11.wmStateFullscreen; + event.xclient.data.l[1] = _glfwLibrary.X11.wmStateFullscreen; event.xclient.data.l[2] = 0; // No secondary property event.xclient.data.l[3] = 1; // Sender is a normal application @@ -1003,9 +851,9 @@ static void leaveFullscreenMode(_GLFWwindow* window) _glfwLibrary.X11.saver.changed = GL_FALSE; } - if (window->X11.hasEWMH && - window->X11.wmState != None && - window->X11.wmStateFullscreen != None) + if (_glfwLibrary.X11.hasEWMH && + _glfwLibrary.X11.wmState != None && + _glfwLibrary.X11.wmStateFullscreen != None) { // Ask the window manager to make the GLFW window a normal window // Normal windows usually have frames and other decorations @@ -1016,9 +864,9 @@ static void leaveFullscreenMode(_GLFWwindow* window) event.type = ClientMessage; event.xclient.window = window->X11.handle; event.xclient.format = 32; // Data is 32-bit longs - event.xclient.message_type = window->X11.wmState; + event.xclient.message_type = _glfwLibrary.X11.wmState; event.xclient.data.l[0] = _NET_WM_STATE_REMOVE; - event.xclient.data.l[1] = window->X11.wmStateFullscreen; + event.xclient.data.l[1] = _glfwLibrary.X11.wmStateFullscreen; event.xclient.data.l[2] = 0; // No secondary property event.xclient.data.l[3] = 1; // Sender is a normal application @@ -1291,15 +1139,15 @@ static void processSingleEvent(void) return; } - if ((Atom) event.xclient.data.l[0] == window->X11.wmDeleteWindow) + if ((Atom) event.xclient.data.l[0] == _glfwLibrary.X11.wmDeleteWindow) { // The window manager was asked to close the window, for example by // the user pressing a 'close' window decoration button window->closeRequested = GL_TRUE; } - else if (window->X11.wmPing != None && - (Atom) event.xclient.data.l[0] == window->X11.wmPing) + else if (_glfwLibrary.X11.wmPing != None && + (Atom) event.xclient.data.l[0] == _glfwLibrary.X11.wmPing) { // The window manager is pinging us to make sure we are still // responding to events @@ -1567,18 +1415,18 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) NULL, NULL, NULL); #endif - if (window->X11.wmName != None) + if (_glfwLibrary.X11.wmName != None) { XChangeProperty(_glfwLibrary.X11.display, window->X11.handle, - window->X11.wmName, type, 8, + _glfwLibrary.X11.wmName, type, 8, PropModeReplace, (unsigned char*) title, strlen(title)); } - if (window->X11.wmIconName != None) + if (_glfwLibrary.X11.wmIconName != None) { XChangeProperty(_glfwLibrary.X11.display, window->X11.handle, - window->X11.wmIconName, type, 8, + _glfwLibrary.X11.wmIconName, type, 8, PropModeReplace, (unsigned char*) title, strlen(title)); } From 906754d3d069d2c759668ee483d8ab7722c6095b Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 5 Apr 2012 17:32:38 +0200 Subject: [PATCH 134/226] Removed superfluous assignment. --- src/x11_init.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/x11_init.c b/src/x11_init.c index b6c23563..12b61eef 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -53,7 +53,6 @@ static void initLibraries(void) NULL }; - _glfwLibrary.X11.libGL = NULL; for (i = 0; libGL_names[i] != NULL; i++) { _glfwLibrary.X11.libGL = dlopen(libGL_names[i], RTLD_LAZY | RTLD_GLOBAL); From b076d858cc0faf8e0d23f8331feaafafbbdaff70 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 5 Apr 2012 17:34:13 +0200 Subject: [PATCH 135/226] Formatting. --- src/x11_init.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/x11_init.c b/src/x11_init.c index 12b61eef..48e48a2c 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -261,10 +261,8 @@ static void updateKeyCodeLUT(void) int keyCode; // Clear the LUT - for (keyCode = 0; keyCode < 256; ++keyCode) - { + for (keyCode = 0; keyCode < 256; keyCode++) _glfwLibrary.X11.keyCodeLUT[keyCode] = -1; - } #if defined(_GLFW_HAS_XKB) // If the Xkb extension is available, use it to determine physical key @@ -272,7 +270,7 @@ static void updateKeyCodeLUT(void) if (_glfwLibrary.X11.Xkb.available) { int i, keyCodeGLFW; - char name[XkbKeyNameLength+1]; + char name[XkbKeyNameLength + 1]; XkbDescPtr descr; // Get keyboard description @@ -284,10 +282,9 @@ static void updateKeyCodeLUT(void) for (keyCode = descr->min_key_code; keyCode <= descr->max_key_code; ++keyCode) { // Get the key name - for (i = 0; i < XkbKeyNameLength; ++i) - { + for (i = 0; i < XkbKeyNameLength; i++) name[i] = descr->names->keys[keyCode].name[i]; - } + name[XkbKeyNameLength] = 0; // Map the key name to a GLFW key code. Note: We only map printable @@ -346,9 +343,7 @@ static void updateKeyCodeLUT(void) // Update the key code LUT if ((keyCode >= 0) && (keyCode < 256)) - { _glfwLibrary.X11.keyCodeLUT[keyCode] = keyCodeGLFW; - } } // Free the keyboard description @@ -358,7 +353,7 @@ static void updateKeyCodeLUT(void) // Translate the un-translated key codes using traditional X11 KeySym // lookups - for (keyCode = 0; keyCode < 256; ++keyCode) + for (keyCode = 0; keyCode < 256; keyCode++) { if (_glfwLibrary.X11.keyCodeLUT[keyCode] < 0) { From c1dd245d8ad76af8f3b4137f9e74dc7c9df7e817 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 6 Apr 2012 14:37:31 +0200 Subject: [PATCH 136/226] Moved input functions to input section. --- src/internal.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/internal.h b/src/internal.h index 1e973a0e..9bfc3f5d 100644 --- a/src/internal.h +++ b/src/internal.h @@ -277,6 +277,8 @@ const char* _glfwPlatformGetVersionString(void); // Input void _glfwPlatformEnableSystemKeys(_GLFWwindow* window); void _glfwPlatformDisableSystemKeys(_GLFWwindow* window); +void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y); +void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode); // Fullscreen int _glfwPlatformGetVideoModes(GLFWvidmode* list, int maxcount); @@ -303,8 +305,6 @@ 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 _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y); -void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode); // Event management void _glfwPlatformPollEvents(void); From 77633d8d9a4470be45f23697e23bad773e270931 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 6 Apr 2012 14:37:40 +0200 Subject: [PATCH 137/226] Added some missing error reporting. --- src/x11_window.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/x11_window.c b/src/x11_window.c index a5058f00..980fa305 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -1292,11 +1292,18 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, fbconfigs = getFBConfigs(window, &fbcount); if (!fbconfigs) + { + _glfwSetError(GLFW_PLATFORM_ERROR, + "X11/GLX: No usable GLXFBConfigs found"); return GL_FALSE; + } result = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount); if (!result) { + _glfwSetError(GLFW_PLATFORM_ERROR, + "X11/GLX: No GLXFBConfig matched the criteria"); + free(fbconfigs); return GL_FALSE; } From d55616661d7a2b27807fe94c37dfcb546fa42f0d Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 9 Apr 2012 15:00:52 +0200 Subject: [PATCH 138/226] Removed support for primary and secondary selections. --- src/x11_clipboard.c | 41 ++++++++++++++++------------------------- src/x11_init.c | 8 ++------ src/x11_platform.h | 8 +------- 3 files changed, 19 insertions(+), 38 deletions(-) diff --git a/src/x11_clipboard.c b/src/x11_clipboard.c index 71f2f7c9..a0640873 100644 --- a/src/x11_clipboard.c +++ b/src/x11_clipboard.c @@ -142,8 +142,7 @@ void _glfwPlatformSetClipboardData(void *data, size_t size, int format) XSetSelectionOwner(_glfwLibrary.X11.display, XA_PRIMARY, _glfwLibrary.activeWindow->X11.handle, CurrentTime); XSetSelectionOwner(_glfwLibrary.X11.display, - _glfwLibrary.X11.selection.atoms.clipboard - [_GLFW_CLIPBOARD_ATOM_CLIPBOARD], + _glfwLibrary.X11.selection.atom, _glfwLibrary.activeWindow->X11.handle, CurrentTime); XFlush(_glfwLibrary.X11.display); } @@ -162,44 +161,36 @@ size_t _glfwPlatformGetClipboardData(void *data, size_t size, int format) // Try different clipboards and formats that relate to the GLFW // format with preference for more appropriate formats first - Atom *xcbrd = _glfwLibrary.X11.selection.atoms.clipboard; - Atom *xcbrdend = _glfwLibrary.X11.selection.atoms.clipboard + - _GLFW_CLIPBOARD_ATOM_COUNT; Atom *xfmt = getInternalFormat(format); Atom *xfmtend = xfmt + _GLFW_STRING_ATOM_COUNT; // Get the currently active window Window window = _glfwLibrary.activeWindow->X11.handle; - for ( ; xcbrd != xcbrdend; xcbrd++) + for ( ; xfmt != xfmtend; xfmt++) { - for ( ; xfmt != xfmtend; xfmt++) - { - // Specify the format we would like. - _glfwLibrary.X11.selection.request = *xfmt; + // Specify the format we would like. + _glfwLibrary.X11.selection.request = *xfmt; - // Convert the selection into a format we would like. - XConvertSelection(_glfwLibrary.X11.display, *xcbrd, - *xfmt, None, window, CurrentTime); - XFlush(_glfwLibrary.X11.display); + // Convert the selection into a format we would like. + XConvertSelection(_glfwLibrary.X11.display, + _glfwLibrary.X11.selection.atom, + *xfmt, None, window, CurrentTime); + XFlush(_glfwLibrary.X11.display); - // Process pending events until we get a SelectionNotify. - while (!_glfwLibrary.X11.selection.converted) - _glfwPlatformWaitEvents(); - - // Successful? - if (_glfwLibrary.X11.selection.converted == 1) - break; - } + // Process pending events until we get a SelectionNotify. + while (!_glfwLibrary.X11.selection.converted) + _glfwPlatformWaitEvents(); // Successful? if (_glfwLibrary.X11.selection.converted == 1) - { - _glfwLibrary.X11.selection.converted = 0; break; - } } + // Successful? + if (_glfwLibrary.X11.selection.converted == 1) + _glfwLibrary.X11.selection.converted = 0; + // Unsuccessful conversion, bail with no clipboard data if (_glfwLibrary.X11.selection.converted) { diff --git a/src/x11_init.c b/src/x11_init.c index 8b832d52..f9adc7f5 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -456,13 +456,9 @@ static GLboolean initDisplay(void) // the keyboard mapping. updateKeyCodeLUT(); - // Find or create clipboard atoms - _glfwLibrary.X11.selection.atoms.clipboard[_GLFW_CLIPBOARD_ATOM_PRIMARY] = - XA_PRIMARY; - _glfwLibrary.X11.selection.atoms.clipboard[_GLFW_CLIPBOARD_ATOM_CLIPBOARD] = + // Find or create clipboard atom + _glfwLibrary.X11.selection.atom = XInternAtom(_glfwLibrary.X11.display, "CLIPBOARD", False); - _glfwLibrary.X11.selection.atoms.clipboard[_GLFW_CLIPBOARD_ATOM_SECONDARY] = - XA_SECONDARY; // Find or create selection atoms _glfwLibrary.X11.selection.atoms.string[_GLFW_STRING_ATOM_UTF8] = diff --git a/src/x11_platform.h b/src/x11_platform.h index 2e6bbc21..163fcd19 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -85,12 +85,6 @@ #define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryX11 X11 #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX GLX -// Clipboard atoms -#define _GLFW_CLIPBOARD_ATOM_PRIMARY 0 -#define _GLFW_CLIPBOARD_ATOM_CLIPBOARD 1 -#define _GLFW_CLIPBOARD_ATOM_SECONDARY 2 -#define _GLFW_CLIPBOARD_ATOM_COUNT 3 - // String atoms #define _GLFW_STRING_ATOM_UTF8 0 #define _GLFW_STRING_ATOM_COMPOUND 1 @@ -236,8 +230,8 @@ typedef struct _GLFWlibraryX11 // Selection data struct { + Atom atom; struct { - Atom clipboard[_GLFW_CLIPBOARD_ATOM_COUNT]; Atom string[_GLFW_STRING_ATOM_COUNT]; } atoms; struct { From 508207ae04b06bee853adfba89033e8e95349662 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 9 Apr 2012 15:04:14 +0200 Subject: [PATCH 139/226] Removed superfluous function. --- src/x11_clipboard.c | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/src/x11_clipboard.c b/src/x11_clipboard.c index a0640873..ab2a5c1d 100644 --- a/src/x11_clipboard.c +++ b/src/x11_clipboard.c @@ -37,23 +37,6 @@ #include -//======================================================================== -// Get the corresponding X11 format for a given GLFW format. -//======================================================================== - -static Atom* getInternalFormat(int format) -{ - // Get the necessary atoms - switch (format) - { - case GLFW_CLIPBOARD_FORMAT_STRING: - return _glfwLibrary.X11.selection.atoms.string; - default: - return 0; - } -} - - ////////////////////////////////////////////////////////////////////////// ////// GLFW internal API ////// ////////////////////////////////////////////////////////////////////////// @@ -161,7 +144,7 @@ size_t _glfwPlatformGetClipboardData(void *data, size_t size, int format) // Try different clipboards and formats that relate to the GLFW // format with preference for more appropriate formats first - Atom *xfmt = getInternalFormat(format); + Atom *xfmt = _glfwLibrary.X11.selection.atoms.string; Atom *xfmtend = xfmt + _GLFW_STRING_ATOM_COUNT; // Get the currently active window From 168aba78d4f8f6cd7058627c9095b33ef056c393 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 9 Apr 2012 15:12:59 +0200 Subject: [PATCH 140/226] Formatting. --- src/x11_clipboard.c | 69 +++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/src/x11_clipboard.c b/src/x11_clipboard.c index ab2a5c1d..c46b0dd1 100644 --- a/src/x11_clipboard.c +++ b/src/x11_clipboard.c @@ -47,31 +47,33 @@ Atom _glfwSelectionRequest(XSelectionRequestEvent* request) { - Atom* atoms = _glfwLibrary.X11.selection.atoms.string; + Atom* formats = _glfwLibrary.X11.selection.atoms.string; + char* target = _glfwLibrary.X11.selection.clipboard.string; + if (request->target == XA_STRING) { // TODO: ISO Latin-1 specific characters don't get converted // (yet). For cleanliness, would we need something like iconv? XChangeProperty(_glfwLibrary.X11.display, - request->requestor, - request->target, - request->target, - 8, - PropModeReplace, - (unsigned char*) _glfwLibrary.X11.selection.clipboard.string, - 8); + request->requestor, + request->target, + request->target, + 8, + PropModeReplace, + (unsigned char*) target, + 8); } - else if (request->target == atoms[_GLFW_STRING_ATOM_COMPOUND] || - request->target == atoms[_GLFW_STRING_ATOM_UTF8]) + else if (request->target == formats[_GLFW_STRING_ATOM_COMPOUND] || + request->target == formats[_GLFW_STRING_ATOM_UTF8]) { XChangeProperty(_glfwLibrary.X11.display, - request->requestor, - request->target, - request->target, - 8, - PropModeReplace, - (unsigned char*) _glfwLibrary.X11.selection.clipboard.string, - _glfwLibrary.X11.selection.clipboard.stringlen); + request->requestor, + request->target, + request->target, + 8, + PropModeReplace, + (unsigned char*) target, + _glfwLibrary.X11.selection.clipboard.stringlen); } else { @@ -91,14 +93,14 @@ Atom _glfwSelectionRequest(XSelectionRequestEvent* request) // Set the clipboard contents //======================================================================== -void _glfwPlatformSetClipboardData(void *data, size_t size, int format) +void _glfwPlatformSetClipboardData(void* data, size_t size, int format) { switch (format) { case GLFW_CLIPBOARD_FORMAT_STRING: { // Allocate memory to keep track of the clipboard - char *cb = malloc(size+1); + char* cb = malloc(size + 1); // Copy the clipboard data memcpy(cb, data, size); @@ -135,10 +137,10 @@ void _glfwPlatformSetClipboardData(void *data, size_t size, int format) // Return the current clipboard contents //======================================================================== -size_t _glfwPlatformGetClipboardData(void *data, size_t size, int format) +size_t _glfwPlatformGetClipboardData(void* data, size_t size, int format) { size_t len, rembytes, dummy; - unsigned char *d; + unsigned char* d; int fmt; Atom type; @@ -158,7 +160,7 @@ size_t _glfwPlatformGetClipboardData(void *data, size_t size, int format) // Convert the selection into a format we would like. XConvertSelection(_glfwLibrary.X11.display, _glfwLibrary.X11.selection.atom, - *xfmt, None, window, CurrentTime); + *xfmt, None, window, CurrentTime); XFlush(_glfwLibrary.X11.display); // Process pending events until we get a SelectionNotify. @@ -200,20 +202,31 @@ size_t _glfwPlatformGetClipboardData(void *data, size_t size, int format) // The number of bytes remaining (which is all of them) if (rembytes > 0) { - int result = XGetWindowProperty(_glfwLibrary.X11.display, window, - *xfmt, 0, rembytes, 0, - AnyPropertyType, &type, &fmt, - &len, &dummy, &d); + int result = XGetWindowProperty(_glfwLibrary.X11.display, + window, + *xfmt, + 0, rembytes, + 0, + AnyPropertyType, + &type, + &fmt, + &len, &dummy, + &d); if (result == Success) { - size_t s = size - 1 > rembytes ? rembytes : size - 1; + size_t s; + + if (rembytes < size - 1) + s = rembytes; + else + s = size - 1; // Copy the data out. memcpy(data, d, s); // Null-terminate strings. if (format == GLFW_CLIPBOARD_FORMAT_STRING) - ((char *)data)[s] = '\0'; + ((char*) data)[s] = '\0'; // Free the data allocated using X11. XFree(d); From 3252829fe007ac27aab89d6a3aad571a9f1af079 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 9 Apr 2012 15:16:56 +0200 Subject: [PATCH 141/226] Replaced iterators with index. --- src/x11_clipboard.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/x11_clipboard.c b/src/x11_clipboard.c index c46b0dd1..c5d00deb 100644 --- a/src/x11_clipboard.c +++ b/src/x11_clipboard.c @@ -141,26 +141,23 @@ size_t _glfwPlatformGetClipboardData(void* data, size_t size, int format) { size_t len, rembytes, dummy; unsigned char* d; - int fmt; + int i, fmt; Atom type; - // Try different clipboards and formats that relate to the GLFW - // format with preference for more appropriate formats first - Atom *xfmt = _glfwLibrary.X11.selection.atoms.string; - Atom *xfmtend = xfmt + _GLFW_STRING_ATOM_COUNT; - // Get the currently active window Window window = _glfwLibrary.activeWindow->X11.handle; - for ( ; xfmt != xfmtend; xfmt++) + for (i = 0; i < _GLFW_STRING_ATOM_COUNT; i++) { // Specify the format we would like. - _glfwLibrary.X11.selection.request = *xfmt; + _glfwLibrary.X11.selection.request = + _glfwLibrary.X11.selection.atoms.strings[i]; // Convert the selection into a format we would like. XConvertSelection(_glfwLibrary.X11.display, _glfwLibrary.X11.selection.atom, - *xfmt, None, window, CurrentTime); + _glfwLibrary.X11.selection.request, + None, window, CurrentTime); XFlush(_glfwLibrary.X11.display); // Process pending events until we get a SelectionNotify. @@ -190,7 +187,7 @@ size_t _glfwPlatformGetClipboardData(void* data, size_t size, int format) // Check the length of data to receive (rembytes) XGetWindowProperty(_glfwLibrary.X11.display, window, - *xfmt, + _glfwLibrary.X11.selection.request, 0, 0, 0, AnyPropertyType, @@ -204,7 +201,7 @@ size_t _glfwPlatformGetClipboardData(void* data, size_t size, int format) { int result = XGetWindowProperty(_glfwLibrary.X11.display, window, - *xfmt, + _glfwLibrary.X11.selection.request, 0, rembytes, 0, AnyPropertyType, From b8676f01db7fd42b3127b21593bec6c7198fe378 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 9 Apr 2012 15:21:54 +0200 Subject: [PATCH 142/226] Clarified clipboard format atom use. --- src/x11_clipboard.c | 10 +++++----- src/x11_init.c | 7 ++++--- src/x11_platform.h | 14 ++++++-------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/x11_clipboard.c b/src/x11_clipboard.c index c5d00deb..56d71904 100644 --- a/src/x11_clipboard.c +++ b/src/x11_clipboard.c @@ -47,7 +47,7 @@ Atom _glfwSelectionRequest(XSelectionRequestEvent* request) { - Atom* formats = _glfwLibrary.X11.selection.atoms.string; + Atom* formats = _glfwLibrary.X11.selection.formats; char* target = _glfwLibrary.X11.selection.clipboard.string; if (request->target == XA_STRING) @@ -63,8 +63,8 @@ Atom _glfwSelectionRequest(XSelectionRequestEvent* request) (unsigned char*) target, 8); } - else if (request->target == formats[_GLFW_STRING_ATOM_COMPOUND] || - request->target == formats[_GLFW_STRING_ATOM_UTF8]) + else if (request->target == formats[_GLFW_CLIPBOARD_FORMAT_COMPOUND] || + request->target == formats[_GLFW_CLIPBOARD_FORMAT_UTF8]) { XChangeProperty(_glfwLibrary.X11.display, request->requestor, @@ -147,11 +147,11 @@ size_t _glfwPlatformGetClipboardData(void* data, size_t size, int format) // Get the currently active window Window window = _glfwLibrary.activeWindow->X11.handle; - for (i = 0; i < _GLFW_STRING_ATOM_COUNT; i++) + for (i = 0; i < _GLFW_CLIPBOARD_FORMAT_COUNT; i++) { // Specify the format we would like. _glfwLibrary.X11.selection.request = - _glfwLibrary.X11.selection.atoms.strings[i]; + _glfwLibrary.X11.selection.formats[i]; // Convert the selection into a format we would like. XConvertSelection(_glfwLibrary.X11.display, diff --git a/src/x11_init.c b/src/x11_init.c index f9adc7f5..dbadc916 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -461,11 +461,12 @@ static GLboolean initDisplay(void) XInternAtom(_glfwLibrary.X11.display, "CLIPBOARD", False); // Find or create selection atoms - _glfwLibrary.X11.selection.atoms.string[_GLFW_STRING_ATOM_UTF8] = + _glfwLibrary.X11.selection.formats[_GLFW_CLIPBOARD_FORMAT_UTF8] = XInternAtom(_glfwLibrary.X11.display, "UTF8_STRING", False); - _glfwLibrary.X11.selection.atoms.string[_GLFW_STRING_ATOM_COMPOUND] = + _glfwLibrary.X11.selection.formats[_GLFW_CLIPBOARD_FORMAT_COMPOUND] = XInternAtom(_glfwLibrary.X11.display, "COMPOUND_STRING", False); - _glfwLibrary.X11.selection.atoms.string[_GLFW_STRING_ATOM_STRING] = XA_STRING; + _glfwLibrary.X11.selection.formats[_GLFW_CLIPBOARD_FORMAT_STRING] = + XA_STRING; return GL_TRUE; } diff --git a/src/x11_platform.h b/src/x11_platform.h index 163fcd19..0bb4c6c4 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -85,11 +85,11 @@ #define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryX11 X11 #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX GLX -// String atoms -#define _GLFW_STRING_ATOM_UTF8 0 -#define _GLFW_STRING_ATOM_COMPOUND 1 -#define _GLFW_STRING_ATOM_STRING 2 -#define _GLFW_STRING_ATOM_COUNT 3 +// Clipboard format atom indices +#define _GLFW_CLIPBOARD_FORMAT_UTF8 0 +#define _GLFW_CLIPBOARD_FORMAT_COMPOUND 1 +#define _GLFW_CLIPBOARD_FORMAT_STRING 2 +#define _GLFW_CLIPBOARD_FORMAT_COUNT 3 //======================================================================== // GLFW platform specific types @@ -231,9 +231,7 @@ typedef struct _GLFWlibraryX11 // Selection data struct { Atom atom; - struct { - Atom string[_GLFW_STRING_ATOM_COUNT]; - } atoms; + Atom formats[_GLFW_CLIPBOARD_FORMAT_COUNT]; struct { size_t stringlen; char *string; From fcd67c69ec956987e6f8e6f88368872a3e037fcc Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 9 Apr 2012 15:27:32 +0200 Subject: [PATCH 143/226] Simplified clipboard cache layout. --- src/x11_clipboard.c | 12 ++++++------ src/x11_init.c | 4 ++-- src/x11_platform.h | 6 ++---- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/x11_clipboard.c b/src/x11_clipboard.c index 56d71904..e260e7cb 100644 --- a/src/x11_clipboard.c +++ b/src/x11_clipboard.c @@ -48,7 +48,7 @@ Atom _glfwSelectionRequest(XSelectionRequestEvent* request) { Atom* formats = _glfwLibrary.X11.selection.formats; - char* target = _glfwLibrary.X11.selection.clipboard.string; + char* target = _glfwLibrary.X11.selection.string; if (request->target == XA_STRING) { @@ -73,7 +73,7 @@ Atom _glfwSelectionRequest(XSelectionRequestEvent* request) 8, PropModeReplace, (unsigned char*) target, - _glfwLibrary.X11.selection.clipboard.stringlen); + _glfwLibrary.X11.selection.stringLength); } else { @@ -106,14 +106,14 @@ void _glfwPlatformSetClipboardData(void* data, size_t size, int format) memcpy(cb, data, size); // Set the string length - _glfwLibrary.X11.selection.clipboard.stringlen = size; + _glfwLibrary.X11.selection.stringLength = size; // Check if existing clipboard memory needs to be freed - if (_glfwLibrary.X11.selection.clipboard.string) - free(_glfwLibrary.X11.selection.clipboard.string); + if (_glfwLibrary.X11.selection.string) + free(_glfwLibrary.X11.selection.string); // Now set the clipboard (awaiting the event SelectionRequest) - _glfwLibrary.X11.selection.clipboard.string = cb; + _glfwLibrary.X11.selection.string = cb; break; } diff --git a/src/x11_init.c b/src/x11_init.c index dbadc916..a702ad19 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -632,8 +632,8 @@ int _glfwPlatformTerminate(void) #endif // Free clipboard memory - if (_glfwLibrary.X11.selection.clipboard.string) - free(_glfwLibrary.X11.selection.clipboard.string); + if (_glfwLibrary.X11.selection.string) + free(_glfwLibrary.X11.selection.string); return GL_TRUE; } diff --git a/src/x11_platform.h b/src/x11_platform.h index 0bb4c6c4..19447d47 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -232,10 +232,8 @@ typedef struct _GLFWlibraryX11 struct { Atom atom; Atom formats[_GLFW_CLIPBOARD_FORMAT_COUNT]; - struct { - size_t stringlen; - char *string; - } clipboard; + size_t stringLength; + char* string; Atom request; int converted; } selection; From 2bc8d442f4807bd985b7d6038487a8991b350391 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 9 Apr 2012 15:36:39 +0200 Subject: [PATCH 144/226] Formatting. --- include/GL/glfw3.h | 4 ++-- src/clipboard.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index f87be382..a7449099 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -581,8 +581,8 @@ GLFWAPI int glfwGetJoystickPos(int joy, float* pos, int numaxes); GLFWAPI int glfwGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons); /* Clipboard */ -GLFWAPI void glfwSetClipboardData(void *data, size_t size, int format); -GLFWAPI size_t glfwGetClipboardData(void *data, size_t size, int format); +GLFWAPI void glfwSetClipboardData(void* data, size_t size, int format); +GLFWAPI size_t glfwGetClipboardData(void* data, size_t size, int format); /* Time */ GLFWAPI double glfwGetTime(void); diff --git a/src/clipboard.c b/src/clipboard.c index 480bad8e..0f1889c3 100644 --- a/src/clipboard.c +++ b/src/clipboard.c @@ -41,7 +41,7 @@ // Set the clipboard contents //======================================================================== -GLFWAPI void glfwSetClipboardData(void *data, size_t size, int format) +GLFWAPI void glfwSetClipboardData(void* data, size_t size, int format) { if (!_glfwInitialized) { @@ -60,7 +60,7 @@ GLFWAPI void glfwSetClipboardData(void *data, size_t size, int format) // Return the current clipboard contents //======================================================================== -GLFWAPI size_t glfwGetClipboardData(void *data, size_t size, int format) +GLFWAPI size_t glfwGetClipboardData(void* data, size_t size, int format) { if (!_glfwInitialized) { From 490c472328ad625e3476f3bb127defdf8cadeb7d Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 9 Apr 2012 15:38:26 +0200 Subject: [PATCH 145/226] Removed unused error. --- include/GL/glfw3.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index a7449099..e2f25901 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -462,7 +462,6 @@ extern "C" { #define GLFW_PLATFORM_ERROR 0x00070008 #define GLFW_WINDOW_NOT_ACTIVE 0x00070009 #define GLFW_CLIPBOARD_FORMAT_UNAVAILABLE 0x00070010 -#define GLFW_CLIPBOARD_CANNOT_OWN 0x00070011 /* Gamma ramps */ #define GLFW_GAMMA_RAMP_SIZE 256 From 7044ed6f06a042eba8e694ba9f14812a35040fce Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 9 Apr 2012 15:54:36 +0200 Subject: [PATCH 146/226] Simplified and made clipboard API more type safe. --- include/GL/glfw3.h | 10 +++------- src/clipboard.c | 16 +++++----------- src/internal.h | 4 ++-- src/x11_clipboard.c | 45 +++++++++++++++++---------------------------- tests/clipboard.c | 8 ++++---- 5 files changed, 31 insertions(+), 52 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index e2f25901..d7be4fd2 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -461,15 +461,11 @@ extern "C" { #define GLFW_VERSION_UNAVAILABLE 0x00070007 #define GLFW_PLATFORM_ERROR 0x00070008 #define GLFW_WINDOW_NOT_ACTIVE 0x00070009 -#define GLFW_CLIPBOARD_FORMAT_UNAVAILABLE 0x00070010 +#define GLFW_FORMAT_UNAVAILABLE 0x0007000A /* Gamma ramps */ #define GLFW_GAMMA_RAMP_SIZE 256 -/* Clipboard formats */ -#define GLFW_CLIPBOARD_FORMAT_NONE 0 -#define GLFW_CLIPBOARD_FORMAT_STRING 1 - /************************************************************************* * Typedefs *************************************************************************/ @@ -580,8 +576,8 @@ GLFWAPI int glfwGetJoystickPos(int joy, float* pos, int numaxes); GLFWAPI int glfwGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons); /* Clipboard */ -GLFWAPI void glfwSetClipboardData(void* data, size_t size, int format); -GLFWAPI size_t glfwGetClipboardData(void* data, size_t size, int format); +GLFWAPI void glfwSetClipboardString(const char* data); +GLFWAPI size_t glfwGetClipboardString(char* data, size_t size); /* Time */ GLFWAPI double glfwGetTime(void); diff --git a/src/clipboard.c b/src/clipboard.c index 0f1889c3..a816ebb0 100644 --- a/src/clipboard.c +++ b/src/clipboard.c @@ -41,7 +41,7 @@ // Set the clipboard contents //======================================================================== -GLFWAPI void glfwSetClipboardData(void* data, size_t size, int format) +GLFWAPI void glfwSetClipboardString(const char* string) { if (!_glfwInitialized) { @@ -49,10 +49,7 @@ GLFWAPI void glfwSetClipboardData(void* data, size_t size, int format) return; } - if (format == GLFW_CLIPBOARD_FORMAT_NONE) - return; - - _glfwPlatformSetClipboardData(data, size, format); + _glfwPlatformSetClipboardString(string); } @@ -60,7 +57,7 @@ GLFWAPI void glfwSetClipboardData(void* data, size_t size, int format) // Return the current clipboard contents //======================================================================== -GLFWAPI size_t glfwGetClipboardData(void* data, size_t size, int format) +GLFWAPI size_t glfwGetClipboardString(char* string, size_t size) { if (!_glfwInitialized) { @@ -68,12 +65,9 @@ GLFWAPI size_t glfwGetClipboardData(void* data, size_t size, int format) return 0; } - if (format == GLFW_CLIPBOARD_FORMAT_NONE) + if (!string || !size) return 0; - if (!data || !size) - return 0; - - return _glfwPlatformGetClipboardData(data, size, format); + return _glfwPlatformGetClipboardString(string, size); } diff --git a/src/internal.h b/src/internal.h index c16fc03f..2e0b9c38 100644 --- a/src/internal.h +++ b/src/internal.h @@ -289,8 +289,8 @@ void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp); void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp); // Clipboard -void _glfwPlatformSetClipboardData(void *data, size_t size, int format); -size_t _glfwPlatformGetClipboardData(void *data, size_t size, int format); +void _glfwPlatformSetClipboardString(const char* string); +size_t _glfwPlatformGetClipboardString(char *data, size_t size); // Joystick int _glfwPlatformGetJoystickParam(int joy, int param); diff --git a/src/x11_clipboard.c b/src/x11_clipboard.c index e260e7cb..b733b486 100644 --- a/src/x11_clipboard.c +++ b/src/x11_clipboard.c @@ -93,35 +93,25 @@ Atom _glfwSelectionRequest(XSelectionRequestEvent* request) // Set the clipboard contents //======================================================================== -void _glfwPlatformSetClipboardData(void* data, size_t size, int format) +void _glfwPlatformSetClipboardString(const char* string) { - switch (format) - { - case GLFW_CLIPBOARD_FORMAT_STRING: - { - // Allocate memory to keep track of the clipboard - char* cb = malloc(size + 1); + size_t size = strlen(string) + 1; - // Copy the clipboard data - memcpy(cb, data, size); + // Allocate memory to keep track of the clipboard + char* cb = malloc(size); - // Set the string length - _glfwLibrary.X11.selection.stringLength = size; + // Copy the clipboard data + memcpy(cb, string, size); - // Check if existing clipboard memory needs to be freed - if (_glfwLibrary.X11.selection.string) - free(_glfwLibrary.X11.selection.string); + // Set the string length + _glfwLibrary.X11.selection.stringLength = size; - // Now set the clipboard (awaiting the event SelectionRequest) - _glfwLibrary.X11.selection.string = cb; - break; - } + // Check if existing clipboard memory needs to be freed + if (_glfwLibrary.X11.selection.string) + free(_glfwLibrary.X11.selection.string); - default: - _glfwSetError(GLFW_CLIPBOARD_FORMAT_UNAVAILABLE, - "X11/GLX: Unavailable clipboard format"); - return; - } + // Now set the clipboard (awaiting the event SelectionRequest) + _glfwLibrary.X11.selection.string = cb; // Set the selection owner to our active window XSetSelectionOwner(_glfwLibrary.X11.display, XA_PRIMARY, @@ -137,7 +127,7 @@ void _glfwPlatformSetClipboardData(void* data, size_t size, int format) // Return the current clipboard contents //======================================================================== -size_t _glfwPlatformGetClipboardData(void* data, size_t size, int format) +size_t _glfwPlatformGetClipboardString(char* data, size_t size) { size_t len, rembytes, dummy; unsigned char* d; @@ -176,8 +166,8 @@ size_t _glfwPlatformGetClipboardData(void* data, size_t size, int format) // Unsuccessful conversion, bail with no clipboard data if (_glfwLibrary.X11.selection.converted) { - _glfwSetError(GLFW_CLIPBOARD_FORMAT_UNAVAILABLE, - "X11/GLX: Unavailable clipboard format"); + _glfwSetError(GLFW_FORMAT_UNAVAILABLE, + "X11/GLX: Failed to convert selection to string"); return 0; } @@ -222,8 +212,7 @@ size_t _glfwPlatformGetClipboardData(void* data, size_t size, int format) memcpy(data, d, s); // Null-terminate strings. - if (format == GLFW_CLIPBOARD_FORMAT_STRING) - ((char*) data)[s] = '\0'; + ((char*) data)[s] = '\0'; // Free the data allocated using X11. XFree(d); diff --git a/tests/clipboard.c b/tests/clipboard.c index 1960d6ec..ac83448b 100644 --- a/tests/clipboard.c +++ b/tests/clipboard.c @@ -64,7 +64,7 @@ static void key_callback(GLFWwindow window, int key, int action) printf("Paste test.\n"); - size = glfwGetClipboardData(buffer, sizeof(buffer), GLFW_CLIPBOARD_FORMAT_STRING); + size = glfwGetClipboardString(buffer, sizeof(buffer)); if (size >= sizeof(buffer)) printf("Buffer wasn't big enough to hold clipboard data.\n"); @@ -75,9 +75,9 @@ static void key_callback(GLFWwindow window, int key, int action) case GLFW_KEY_C: if (control_is_down(window)) { - glfwSetClipboardData("Hello GLFW World!", sizeof("Hello GLFW World!"), - GLFW_CLIPBOARD_FORMAT_STRING); - printf("Setting clipboard to: %s\n", "Hello GLFW World!"); + const char* string = "Hello GLFW World!"; + glfwSetClipboardString(string); + printf("Setting clipboard to: %s\n", string); } break; } From bf1ada029b9032249dcc4d5af605fbefbfeb68d3 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 9 Apr 2012 16:00:54 +0200 Subject: [PATCH 147/226] Added window parameter to clipboard API. --- include/GL/glfw3.h | 4 ++-- src/clipboard.c | 12 ++++++++---- src/internal.h | 4 ++-- src/x11_clipboard.c | 17 +++++++---------- tests/clipboard.c | 4 ++-- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index d7be4fd2..6b1cc470 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -576,8 +576,8 @@ GLFWAPI int glfwGetJoystickPos(int joy, float* pos, int numaxes); GLFWAPI int glfwGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons); /* Clipboard */ -GLFWAPI void glfwSetClipboardString(const char* data); -GLFWAPI size_t glfwGetClipboardString(char* data, size_t size); +GLFWAPI void glfwSetClipboardString(GLFWwindow window, const char* data); +GLFWAPI size_t glfwGetClipboardString(GLFWwindow window, char* data, size_t size); /* Time */ GLFWAPI double glfwGetTime(void); diff --git a/src/clipboard.c b/src/clipboard.c index a816ebb0..b66d5656 100644 --- a/src/clipboard.c +++ b/src/clipboard.c @@ -41,15 +41,17 @@ // Set the clipboard contents //======================================================================== -GLFWAPI void glfwSetClipboardString(const char* string) +GLFWAPI void glfwSetClipboardString(GLFWwindow handle, const char* string) { + _GLFWwindow* window = (_GLFWwindow*) handle; + if (!_glfwInitialized) { _glfwSetError(GLFW_NOT_INITIALIZED, NULL); return; } - _glfwPlatformSetClipboardString(string); + _glfwPlatformSetClipboardString(window, string); } @@ -57,8 +59,10 @@ GLFWAPI void glfwSetClipboardString(const char* string) // Return the current clipboard contents //======================================================================== -GLFWAPI size_t glfwGetClipboardString(char* string, size_t size) +GLFWAPI size_t glfwGetClipboardString(GLFWwindow handle, char* string, size_t size) { + _GLFWwindow* window = (_GLFWwindow*) handle; + if (!_glfwInitialized) { _glfwSetError(GLFW_NOT_INITIALIZED, NULL); @@ -68,6 +72,6 @@ GLFWAPI size_t glfwGetClipboardString(char* string, size_t size) if (!string || !size) return 0; - return _glfwPlatformGetClipboardString(string, size); + return _glfwPlatformGetClipboardString(window, string, size); } diff --git a/src/internal.h b/src/internal.h index 2e0b9c38..407270ea 100644 --- a/src/internal.h +++ b/src/internal.h @@ -289,8 +289,8 @@ void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp); void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp); // Clipboard -void _glfwPlatformSetClipboardString(const char* string); -size_t _glfwPlatformGetClipboardString(char *data, size_t size); +void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string); +size_t _glfwPlatformGetClipboardString(_GLFWwindow* window, char *data, size_t size); // Joystick int _glfwPlatformGetJoystickParam(int joy, int param); diff --git a/src/x11_clipboard.c b/src/x11_clipboard.c index b733b486..4bbfb83c 100644 --- a/src/x11_clipboard.c +++ b/src/x11_clipboard.c @@ -93,7 +93,7 @@ Atom _glfwSelectionRequest(XSelectionRequestEvent* request) // Set the clipboard contents //======================================================================== -void _glfwPlatformSetClipboardString(const char* string) +void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) { size_t size = strlen(string) + 1; @@ -115,10 +115,10 @@ void _glfwPlatformSetClipboardString(const char* string) // Set the selection owner to our active window XSetSelectionOwner(_glfwLibrary.X11.display, XA_PRIMARY, - _glfwLibrary.activeWindow->X11.handle, CurrentTime); + window->X11.handle, CurrentTime); XSetSelectionOwner(_glfwLibrary.X11.display, _glfwLibrary.X11.selection.atom, - _glfwLibrary.activeWindow->X11.handle, CurrentTime); + window->X11.handle, CurrentTime); XFlush(_glfwLibrary.X11.display); } @@ -127,16 +127,13 @@ void _glfwPlatformSetClipboardString(const char* string) // Return the current clipboard contents //======================================================================== -size_t _glfwPlatformGetClipboardString(char* data, size_t size) +size_t _glfwPlatformGetClipboardString(_GLFWwindow* window, char* data, size_t size) { size_t len, rembytes, dummy; unsigned char* d; int i, fmt; Atom type; - // Get the currently active window - Window window = _glfwLibrary.activeWindow->X11.handle; - for (i = 0; i < _GLFW_CLIPBOARD_FORMAT_COUNT; i++) { // Specify the format we would like. @@ -147,7 +144,7 @@ size_t _glfwPlatformGetClipboardString(char* data, size_t size) XConvertSelection(_glfwLibrary.X11.display, _glfwLibrary.X11.selection.atom, _glfwLibrary.X11.selection.request, - None, window, CurrentTime); + None, window->X11.handle, CurrentTime); XFlush(_glfwLibrary.X11.display); // Process pending events until we get a SelectionNotify. @@ -176,7 +173,7 @@ size_t _glfwPlatformGetClipboardString(char* data, size_t size) // Check the length of data to receive (rembytes) XGetWindowProperty(_glfwLibrary.X11.display, - window, + window->X11.handle, _glfwLibrary.X11.selection.request, 0, 0, 0, @@ -190,7 +187,7 @@ size_t _glfwPlatformGetClipboardString(char* data, size_t size) if (rembytes > 0) { int result = XGetWindowProperty(_glfwLibrary.X11.display, - window, + window->X11.handle, _glfwLibrary.X11.selection.request, 0, rembytes, 0, diff --git a/tests/clipboard.c b/tests/clipboard.c index ac83448b..376ebbcd 100644 --- a/tests/clipboard.c +++ b/tests/clipboard.c @@ -64,7 +64,7 @@ static void key_callback(GLFWwindow window, int key, int action) printf("Paste test.\n"); - size = glfwGetClipboardString(buffer, sizeof(buffer)); + size = glfwGetClipboardString(window, buffer, sizeof(buffer)); if (size >= sizeof(buffer)) printf("Buffer wasn't big enough to hold clipboard data.\n"); @@ -76,7 +76,7 @@ static void key_callback(GLFWwindow window, int key, int action) if (control_is_down(window)) { const char* string = "Hello GLFW World!"; - glfwSetClipboardString(string); + glfwSetClipboardString(window, string); printf("Setting clipboard to: %s\n", string); } break; From 1214fa1157e59b870d9f03845624f489dc00139d Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 9 Apr 2012 16:03:14 +0200 Subject: [PATCH 148/226] Formatting. --- include/GL/glfw3.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 6b1cc470..955086af 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -576,8 +576,8 @@ GLFWAPI int glfwGetJoystickPos(int joy, float* pos, int numaxes); GLFWAPI int glfwGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons); /* Clipboard */ -GLFWAPI void glfwSetClipboardString(GLFWwindow window, const char* data); -GLFWAPI size_t glfwGetClipboardString(GLFWwindow window, char* data, size_t size); +GLFWAPI void glfwSetClipboardString(GLFWwindow window, const char* string); +GLFWAPI size_t glfwGetClipboardString(GLFWwindow window, char* string, size_t size); /* Time */ GLFWAPI double glfwGetTime(void); From 877c6337c3d2034b510ccbd7de64368976d99bff Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 9 Apr 2012 16:10:14 +0200 Subject: [PATCH 149/226] Updated remaining ports. --- src/cocoa_clipboard.m | 4 ++-- src/win32_clipboard.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cocoa_clipboard.m b/src/cocoa_clipboard.m index 0f78cf21..4ed01758 100644 --- a/src/cocoa_clipboard.m +++ b/src/cocoa_clipboard.m @@ -41,7 +41,7 @@ // Set the clipboard contents //======================================================================== -void _glfwPlatformSetClipboardData(void *data, size_t size, int format) +void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) { } @@ -49,7 +49,7 @@ void _glfwPlatformSetClipboardData(void *data, size_t size, int format) // Return the current clipboard contents //======================================================================== -size_t _glfwPlatformGetClipboardData(void *data, size_t size, int format) +size_t _glfwPlatformGetClipboardString(_GLFWwindow* window, char* string, size_t size) { return 0; } diff --git a/src/win32_clipboard.c b/src/win32_clipboard.c index b16c51c4..9a05b08e 100644 --- a/src/win32_clipboard.c +++ b/src/win32_clipboard.c @@ -41,7 +41,7 @@ // Set the clipboard contents //======================================================================== -void _glfwPlatformSetClipboardData(void *data, size_t size, int format) +void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) { } @@ -49,7 +49,7 @@ void _glfwPlatformSetClipboardData(void *data, size_t size, int format) // Return the current clipboard contents //======================================================================== -size_t _glfwPlatformGetClipboardData(void *data, size_t size, int format) +size_t _glfwPlatformGetClipboardString(_GLFWwindow* window, char* string, size_t size) { return 0; } From 67a3f5dc8f62b65648aa4dab16baab548727daa5 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 9 Apr 2012 17:41:17 +0200 Subject: [PATCH 150/226] Added error callback. --- tests/clipboard.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/clipboard.c b/tests/clipboard.c index 376ebbcd..da776e61 100644 --- a/tests/clipboard.c +++ b/tests/clipboard.c @@ -88,6 +88,11 @@ static void size_callback(GLFWwindow window, int width, int height) glViewport(0, 0, width, height); } +static void error_callback(int error, const char* description) +{ + fprintf(stderr, "Error: %s in %s\n", glfwErrorString(error), description); +} + int main(int argc, char** argv) { int ch; @@ -107,6 +112,8 @@ int main(int argc, char** argv) } } + glfwSetErrorCallback(error_callback); + if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); From ad18589c6c6ffe1898c6aab5471906912c067909 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 9 Apr 2012 17:45:26 +0200 Subject: [PATCH 151/226] Added initial implementation for Win32. --- src/win32_clipboard.c | 94 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/src/win32_clipboard.c b/src/win32_clipboard.c index 9a05b08e..c2888236 100644 --- a/src/win32_clipboard.c +++ b/src/win32_clipboard.c @@ -31,6 +31,7 @@ #include #include +#include ////////////////////////////////////////////////////////////////////////// @@ -43,6 +44,49 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) { + WCHAR* wideString; + HANDLE stringHandle; + size_t wideSize; + + wideString = _glfwCreateWideStringFromUTF8(string); + if (!wideString) + { + _glfwSetError(GLFW_PLATFORM_ERROR, + "Win32/WGL: Failed to convert clipboard string to " + "wide string"); + return; + } + + wideSize = (wcslen(wideString) + 1) * sizeof(WCHAR); + + stringHandle = GlobalAlloc(GMEM_MOVEABLE, wideSize); + if (!stringHandle) + { + free(wideString); + + _glfwSetError(GLFW_PLATFORM_ERROR, + "Win32/WGL: Failed to allocate global handle for clipboard"); + return; + } + + memcpy(GlobalLock(stringHandle), wideString, wideSize); + GlobalUnlock(stringHandle); + + if (!OpenClipboard(window->Win32.handle)) + { + GlobalFree(stringHandle); + free(wideString); + + _glfwSetError(GLFW_PLATFORM_ERROR, + "Win32/WGL: Failed to open clipboard"); + return; + } + + EmptyClipboard(); + SetClipboardData(CF_UNICODETEXT, stringHandle); + CloseClipboard(); + + free(wideString); } //======================================================================== @@ -51,6 +95,54 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) size_t _glfwPlatformGetClipboardString(_GLFWwindow* window, char* string, size_t size) { - return 0; + HANDLE stringHandle; + char* utf8String; + size_t utf8Size; + + if (!IsClipboardFormatAvailable(CF_UNICODETEXT)) + { + _glfwSetError(GLFW_FORMAT_UNAVAILABLE, NULL); + return 0; + } + + if (!OpenClipboard(window->Win32.handle)) + { + _glfwSetError(GLFW_PLATFORM_ERROR, + "Win32/WGL: Failed to open clipboard"); + return 0; + } + + stringHandle = GetClipboardData(CF_UNICODETEXT); + if (!stringHandle) + { + CloseClipboard(); + + _glfwSetError(GLFW_PLATFORM_ERROR, + "Win32/WGL: Failed to retrieve clipboard data"); + return 0; + } + + utf8String = _glfwCreateUTF8FromWideString(GlobalLock(stringHandle)); + GlobalUnlock(stringHandle); + CloseClipboard(); + + if (!utf8String) + { + _glfwSetError(GLFW_PLATFORM_ERROR, + "Win32/WGL: Failed to convert wide string to UTF-8"); + return 0; + } + + utf8Size = strlen(utf8String) + 1; + if (utf8Size > size) + { + memcpy(string, utf8String, size); + string[size - 1] = '\0'; + } + else + memcpy(string, utf8String, utf8Size); + + free(utf8String); + return utf8Size; } From ab40dab23590093f7be8a24966e9580d988f203c Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 9 Apr 2012 18:00:07 +0200 Subject: [PATCH 152/226] Formatting. --- src/cocoa_clipboard.m | 1 + src/win32_clipboard.c | 1 + 2 files changed, 2 insertions(+) diff --git a/src/cocoa_clipboard.m b/src/cocoa_clipboard.m index 4ed01758..8ac64bcc 100644 --- a/src/cocoa_clipboard.m +++ b/src/cocoa_clipboard.m @@ -45,6 +45,7 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) { } + //======================================================================== // Return the current clipboard contents //======================================================================== diff --git a/src/win32_clipboard.c b/src/win32_clipboard.c index c2888236..9b14f158 100644 --- a/src/win32_clipboard.c +++ b/src/win32_clipboard.c @@ -89,6 +89,7 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) free(wideString); } + //======================================================================== // Return the current clipboard contents //======================================================================== From 8fe46ac1fecaddc1554a33e3d1bff95aa23b2ef3 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 9 Apr 2012 23:27:06 +0200 Subject: [PATCH 153/226] Formatting. --- src/cocoa_clipboard.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cocoa_clipboard.m b/src/cocoa_clipboard.m index 8ac64bcc..e43e9906 100644 --- a/src/cocoa_clipboard.m +++ b/src/cocoa_clipboard.m @@ -52,6 +52,6 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) size_t _glfwPlatformGetClipboardString(_GLFWwindow* window, char* string, size_t size) { - return 0; + return 0; } From 3bd54e0b60dcfeb10826f155d0cea1b19912d14c Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 9 Apr 2012 23:55:44 +0200 Subject: [PATCH 154/226] Added inclusion of declaration of size_t. --- include/GL/glfw3.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 955086af..32c3899a 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -173,6 +173,10 @@ extern "C" { #endif #endif +/* This is needed for the declaration of size_t. + */ +#include + /************************************************************************* * GLFW version From 83901218698a708ef6284d967a757bf9c5f6c068 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 9 Apr 2012 23:56:14 +0200 Subject: [PATCH 155/226] Fixed legacy C warnings. --- src/cocoa_joystick.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cocoa_joystick.m b/src/cocoa_joystick.m index b3bd6e41..97510fdf 100644 --- a/src/cocoa_joystick.m +++ b/src/cocoa_joystick.m @@ -572,7 +572,7 @@ int _glfwPlatformGetJoystickPos(int joy, float* pos, int numaxes) int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons) { - int button; + int i, j, button; if (joy < GLFW_JOYSTICK_1 || joy > GLFW_JOYSTICK_LAST) return 0; @@ -599,13 +599,13 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, const int directions[9] = { 1, 3, 2, 6, 4, 12, 8, 9, 0 }; // Bit fields of button presses for each direction, including nil - for (int i = 0; i < joystick.numHats; i++) + for (i = 0; i < joystick.numHats; i++) { _glfwJoystickElement* hat = (_glfwJoystickElement*) CFArrayGetValueAtIndex(joystick.hats, i); int value = hat->value; if (value < 0 || value > 8) value = 8; - for (int j = 0; j < 4 && button < numbuttons; j++) + for (j = 0; j < 4 && button < numbuttons; j++) { buttons[button++] = directions[value] & (1 << j) ? GLFW_PRESS : GLFW_RELEASE; } From 15e8af1f79337ed3802aefd72ef57f8b0e92244e Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 10 Apr 2012 00:34:08 +0200 Subject: [PATCH 156/226] Added initial implementation for Cocoa. --- src/cocoa_clipboard.m | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/cocoa_clipboard.m b/src/cocoa_clipboard.m index e43e9906..e52b839e 100644 --- a/src/cocoa_clipboard.m +++ b/src/cocoa_clipboard.m @@ -43,6 +43,12 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) { + NSArray* types = [NSArray arrayWithObjects:NSStringPboardType, nil]; + + NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; + [pasteboard declareTypes:types owner:nil]; + [pasteboard setString:[NSString stringWithUTF8String:string] + forType:NSStringPboardType]; } @@ -52,6 +58,30 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) size_t _glfwPlatformGetClipboardString(_GLFWwindow* window, char* string, size_t size) { + const char* source; + size_t targetSize; + NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; + + if (![[pasteboard types] containsObject:NSStringPboardType]) + { + _glfwSetError(GLFW_FORMAT_UNAVAILABLE, NULL); + return 0; + } + + NSString* object = [pasteboard stringForType:NSStringPboardType]; + if (!object) + { + _glfwSetError(GLFW_PLATFORM_ERROR, + "Cocoa/NSGL: Failed to retrieve object from pasteboard"); + return 0; + } + + source = [object UTF8String]; + targetSize = strlen(source) + 1; + if (targetSize > size) + targetSize = size; + + strlcpy(string, source, targetSize); return 0; } From 0ee55ab8e5c947f92284ed26e012baa0b33cf583 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 10 Apr 2012 00:37:53 +0200 Subject: [PATCH 157/226] Updated change log, added credit. --- readme.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/readme.html b/readme.html index 3e0966c0..e890f955 100644 --- a/readme.html +++ b/readme.html @@ -271,6 +271,7 @@ version of GLFW.

    • Added glfwGetWindowPos function for querying the position of the specified window
    • Added glfwSetWindowFocusCallback function and GLFWwindowfocusfun type for receiving window focus events
    • Added glfwSetWindowIconifyCallback function and GLFWwindowiconifyfun type for receiving window iconification events
    • +
    • Added glfwGetClipboardString and glfwSetClipboardString functions for interacting with the system clipboard
    • Added glfwGetCurrentContext function for retrieving the window whose OpenGL context is current
    • Added glfwCopyContext function for copying OpenGL state categories between contexts
    • Added GLFW_OPENGL_ES2_PROFILE profile for creating OpenGL ES 2.0 contexts using the GLX_EXT_create_context_es2_profile and WGL_EXT_create_context_es2_profile extensions
    • @@ -844,7 +845,7 @@ their skills. Special thanks go out to:

      adding logic for the GLFW_ICON resource
    • Ralph Eastwood, for the initial design and implementation of the gamma - correction API
    • + correction and clipboard APIs
    • GeO4d, for the implementation of cursor enter/leave notifications on Win32.
    • From 0e9e37bfc451e35ba39b6de231aed84a44dd6823 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 10 Apr 2012 00:52:21 +0200 Subject: [PATCH 158/226] Simplified string storage. --- src/x11_clipboard.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/x11_clipboard.c b/src/x11_clipboard.c index 4bbfb83c..37d002b5 100644 --- a/src/x11_clipboard.c +++ b/src/x11_clipboard.c @@ -97,21 +97,11 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) { size_t size = strlen(string) + 1; - // Allocate memory to keep track of the clipboard - char* cb = malloc(size); - - // Copy the clipboard data - memcpy(cb, string, size); - - // Set the string length + // Store the new string in preparation for a request event + free(_glfwLibrary.X11.selection.string); + _glfwLibrary.X11.selection.string = malloc(size); _glfwLibrary.X11.selection.stringLength = size; - - // Check if existing clipboard memory needs to be freed - if (_glfwLibrary.X11.selection.string) - free(_glfwLibrary.X11.selection.string); - - // Now set the clipboard (awaiting the event SelectionRequest) - _glfwLibrary.X11.selection.string = cb; + memcpy(_glfwLibrary.X11.selection.string, string, size); // Set the selection owner to our active window XSetSelectionOwner(_glfwLibrary.X11.display, XA_PRIMARY, From e0c4d81e46e9a604b7d3064dd8c7dfb2c1c34ddd Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 10 Apr 2012 01:15:50 +0200 Subject: [PATCH 159/226] Added function for processing only pending events. --- src/x11_clipboard.c | 7 +++---- src/x11_platform.h | 3 +++ src/x11_window.c | 19 ++++++++++++++++++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/x11_clipboard.c b/src/x11_clipboard.c index 37d002b5..cd0b5976 100644 --- a/src/x11_clipboard.c +++ b/src/x11_clipboard.c @@ -135,11 +135,10 @@ size_t _glfwPlatformGetClipboardString(_GLFWwindow* window, char* data, size_t s _glfwLibrary.X11.selection.atom, _glfwLibrary.X11.selection.request, None, window->X11.handle, CurrentTime); - XFlush(_glfwLibrary.X11.display); - // Process pending events until we get a SelectionNotify. - while (!_glfwLibrary.X11.selection.converted) - _glfwPlatformWaitEvents(); + // Process the resulting SelectionNotify event + XSync(_glfwLibrary.X11.display, False); + _glfwProcessPendingEvents(); // Successful? if (_glfwLibrary.X11.selection.converted == 1) diff --git a/src/x11_platform.h b/src/x11_platform.h index f3c4dd35..8de54ead 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -283,4 +283,7 @@ long _glfwKeySym2Unicode(KeySym keysym); // Clipboard handling Atom _glfwSelectionRequest(XSelectionRequestEvent *request); +// Event processing +void _glfwProcessPendingEvents(void); + #endif // _platform_h_ diff --git a/src/x11_window.c b/src/x11_window.c index 57871d65..854480c5 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -1299,6 +1299,23 @@ static void processSingleEvent(void) } +////////////////////////////////////////////////////////////////////////// +////// GLFW internal API ////// +////////////////////////////////////////////////////////////////////////// + +//======================================================================== +// Processes all pending events +//======================================================================== + +void _glfwProcessPendingEvents(void) +{ + int i, count = XPending(_glfwLibrary.X11.display); + + for (i = 0; i < count; i++) + processSingleEvent(); +} + + ////////////////////////////////////////////////////////////////////////// ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// @@ -1369,7 +1386,7 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, } // Process the window map event and any other that may have arrived - _glfwPlatformPollEvents(); + _glfwProcessPendingEvents(); // Retrieve and set initial cursor position { From ad48c0e5ef7d61fc76754d62bad32d3ba0970368 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 10 Apr 2012 18:22:15 +0200 Subject: [PATCH 160/226] Added string for new error. --- src/error.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/error.c b/src/error.c index 2b46a72c..062fb76a 100644 --- a/src/error.c +++ b/src/error.c @@ -109,6 +109,8 @@ GLFWAPI const char* glfwErrorString(int error) return "A platform-specific error occurred"; case GLFW_WINDOW_NOT_ACTIVE: return "The specified window is not active"; + case GLFW_FORMAT_UNAVAILABLE: + return "The requested format is unavailable"; } return "ERROR: UNKNOWN ERROR TOKEN PASSED TO glfwErrorString"; From 21faa7b84fb4effa893ca0a8d67fb515df42c243 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 11 Apr 2012 11:33:42 +0200 Subject: [PATCH 161/226] Formatting. --- readme.html | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/readme.html b/readme.html index 3e0966c0..5ac580d7 100644 --- a/readme.html +++ b/readme.html @@ -20,7 +20,8 @@
    • Acknowledgements
    • - + +

      1. Introduction

      Welcome to version 3.0 of the GLFW library. GLFW is a free, open source, @@ -34,19 +35,22 @@ settle.

      Note that the threading and image loading APIs from the 2.x series have been removed.

      - + +

      2. Compiling GLFW and the example programs

      To compile GLFW and the accompanying example programs, you will need the CMake build system.

      - + +

      3. Installing GLFW

      A rudimentary installation target is provided for all supported platforms via the CMake build system.

      - + +

      4. Using GLFW

      There are two aspects to using GLFW:

      @@ -66,6 +70,7 @@ GLFW API.

      A few rules for successfully designing GLFW-based programs are presented in the following sections.

      +

      4.1 Include the GLFW header file

      In the files of your program where you use OpenGL or GLFW, you should @@ -106,9 +111,9 @@ disable any gl.h that the GLFW header includes and GLEW will work as expected.

      -

      4.2 Link with the right libraries

      +

      4.2.1 Windows static library

      If you link with the static version of GLFW, it is also necessary to @@ -219,7 +224,6 @@ by compile.sh at compile time.

      -lGLU to your link flags.

      -

      4.2.5 Mac OS X static library

      When compiling and linking a program under Mac OS X that uses GLFW, you @@ -256,9 +260,11 @@ that even though your machine may have Unix-style OpenGL libraries, they are for use with the X Window System, and will not work with the Mac OS X native version of GLFW.

      - + +

      5. Version history

      +

      v3.0

      • Added GLFWwindow window handle type and updated window-related functions and callbacks to take a window handle
      • @@ -768,7 +774,7 @@ version of GLFW.

      - +

      6. Directory structure of the GLFW distribution

      Here is an overview of the directory structure of the GLFW distribution: @@ -791,7 +797,7 @@ version of GLFW.

      - +

      7. Contacting the project

      The official website for GLFW is glfw.org. @@ -815,7 +821,7 @@ GLFW or porting it to your favorite platform, we have a or you could join us on #glfw. - +

      8. Acknowledgements

      GLFW exists because people around the world donated their time and lent From 4369a9a6f237446bdadfc775c652df92de76a405 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 11 Apr 2012 11:35:34 +0200 Subject: [PATCH 162/226] Updated header name. --- readme.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/readme.html b/readme.html index 5ac580d7..a4ee2c5d 100644 --- a/readme.html +++ b/readme.html @@ -74,9 +74,9 @@ in the following sections.

      4.1 Include the GLFW header file

      In the files of your program where you use OpenGL or GLFW, you should -include the GL/glfw.h header file, i.e.:

      +include the GL/glfw3.h header file, i.e.:

      -
      #include <GL/glfw.h>
      +
      #include <GL/glfw3.h>

      This defines all the constants, types and function prototypes of the GLFW API. It also includes the gl.h and GL/glu.h header @@ -100,7 +100,7 @@ it. This way, the namespace won't be cluttered by the entire Windows API.

    • Do not include windows.h unless you actually need direct access to the Windows API
    • If you do need to include windows.h, do it - before including GL/glfw.h and the GLFW header will + before including GL/glfw3.h and the GLFW header will detect this.

    From f231ed37f007e482e8f5f5d77e1ff161fe338ad6 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 11 Apr 2012 23:32:50 +0200 Subject: [PATCH 163/226] Re-worked and fixed X11 clipboard support. --- src/x11_clipboard.c | 214 ++++++++++++++++++++------------------------ src/x11_init.c | 10 ++- src/x11_platform.h | 16 +++- src/x11_window.c | 39 +++++--- 4 files changed, 144 insertions(+), 135 deletions(-) diff --git a/src/x11_clipboard.c b/src/x11_clipboard.c index cd0b5976..1b9e1fa3 100644 --- a/src/x11_clipboard.c +++ b/src/x11_clipboard.c @@ -27,8 +27,6 @@ // //======================================================================== -// TODO: Incremental support? Overkill perhaps. - #include "internal.h" #include @@ -42,46 +40,90 @@ ////////////////////////////////////////////////////////////////////////// //======================================================================== -// X11 selection request event +// Save the contents of the specified property //======================================================================== -Atom _glfwSelectionRequest(XSelectionRequestEvent* request) +GLboolean _glfwReadSelection(XSelectionEvent* request) { - Atom* formats = _glfwLibrary.X11.selection.formats; - char* target = _glfwLibrary.X11.selection.string; + Atom actualType; + int actualFormat; + unsigned long itemCount, bytesAfter; + char* data; - if (request->target == XA_STRING) + if (request->property == None) + return GL_FALSE; + + XGetWindowProperty(_glfwLibrary.X11.display, + request->requestor, + request->property, + 0, LONG_MAX, + False, + request->target, + &actualType, + &actualFormat, + &itemCount, + &bytesAfter, + (unsigned char**) &data); + + if (actualType == None) + return GL_FALSE; + + free(_glfwLibrary.X11.selection.string); + _glfwLibrary.X11.selection.string = strdup(data); + + XFree(data); + return GL_TRUE; +} + + +//======================================================================== +// Set the specified property to the contents of the requested selection +//======================================================================== + +Atom _glfwWriteSelection(XSelectionRequestEvent* request) +{ + int i; + Atom property = request->property; + + if (property == None) + property = _glfwLibrary.X11.selection.property; + + if (request->target == _glfwLibrary.X11.selection.targets) { - // TODO: ISO Latin-1 specific characters don't get converted - // (yet). For cleanliness, would we need something like iconv? + // The list of supported targets was requested + XChangeProperty(_glfwLibrary.X11.display, request->requestor, - request->target, - request->target, - 8, + property, + XA_ATOM, + 32, PropModeReplace, - (unsigned char*) target, - 8); - } - else if (request->target == formats[_GLFW_CLIPBOARD_FORMAT_COMPOUND] || - request->target == formats[_GLFW_CLIPBOARD_FORMAT_UTF8]) - { - XChangeProperty(_glfwLibrary.X11.display, - request->requestor, - request->target, - request->target, - 8, - PropModeReplace, - (unsigned char*) target, - _glfwLibrary.X11.selection.stringLength); - } - else - { - // TODO: Should we set an error? Probably not. - return None; + (unsigned char*) _glfwLibrary.X11.selection.formats, + _GLFW_CLIPBOARD_FORMAT_COUNT); + + return property; } - return request->target; + for (i = 0; i < _GLFW_CLIPBOARD_FORMAT_COUNT; i++) + { + if (request->target == _glfwLibrary.X11.selection.formats[i]) + { + // The requested format is one we support + + XChangeProperty(_glfwLibrary.X11.display, + request->requestor, + property, + request->target, + 8, + PropModeReplace, + (unsigned char*) _glfwLibrary.X11.selection.string, + strlen(_glfwLibrary.X11.selection.string)); + + return property; + } + } + + return None; } @@ -95,21 +137,14 @@ Atom _glfwSelectionRequest(XSelectionRequestEvent* request) void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) { - size_t size = strlen(string) + 1; - - // Store the new string in preparation for a request event + // Store the new string in preparation for a selection request event free(_glfwLibrary.X11.selection.string); - _glfwLibrary.X11.selection.string = malloc(size); - _glfwLibrary.X11.selection.stringLength = size; - memcpy(_glfwLibrary.X11.selection.string, string, size); + _glfwLibrary.X11.selection.string = strdup(string); - // Set the selection owner to our active window - XSetSelectionOwner(_glfwLibrary.X11.display, XA_PRIMARY, - window->X11.handle, CurrentTime); + // Set the specified window as owner of the selection XSetSelectionOwner(_glfwLibrary.X11.display, _glfwLibrary.X11.selection.atom, window->X11.handle, CurrentTime); - XFlush(_glfwLibrary.X11.display); } @@ -117,103 +152,50 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) // Return the current clipboard contents //======================================================================== -size_t _glfwPlatformGetClipboardString(_GLFWwindow* window, char* data, size_t size) +size_t _glfwPlatformGetClipboardString(_GLFWwindow* window, char* string, size_t size) { - size_t len, rembytes, dummy; - unsigned char* d; - int i, fmt; - Atom type; + int i; + size_t sourceSize, targetSize; + + _glfwLibrary.X11.selection.status = _GLFW_CONVERSION_INACTIVE; for (i = 0; i < _GLFW_CLIPBOARD_FORMAT_COUNT; i++) { - // Specify the format we would like. - _glfwLibrary.X11.selection.request = + // Request conversion to the selected format + _glfwLibrary.X11.selection.target = _glfwLibrary.X11.selection.formats[i]; - // Convert the selection into a format we would like. XConvertSelection(_glfwLibrary.X11.display, _glfwLibrary.X11.selection.atom, - _glfwLibrary.X11.selection.request, - None, window->X11.handle, CurrentTime); + _glfwLibrary.X11.selection.target, + _glfwLibrary.X11.selection.property, + window->X11.handle, CurrentTime); // Process the resulting SelectionNotify event XSync(_glfwLibrary.X11.display, False); - _glfwProcessPendingEvents(); + while (_glfwLibrary.X11.selection.status == _GLFW_CONVERSION_INACTIVE) + _glfwPlatformWaitEvents(); - // Successful? - if (_glfwLibrary.X11.selection.converted == 1) + if (_glfwLibrary.X11.selection.status == _GLFW_CONVERSION_SUCCEEDED) break; } - // Successful? - if (_glfwLibrary.X11.selection.converted == 1) - _glfwLibrary.X11.selection.converted = 0; - - // Unsuccessful conversion, bail with no clipboard data - if (_glfwLibrary.X11.selection.converted) + if (_glfwLibrary.X11.selection.status == _GLFW_CONVERSION_FAILED) { _glfwSetError(GLFW_FORMAT_UNAVAILABLE, "X11/GLX: Failed to convert selection to string"); return 0; } - // Reset for the next selection - _glfwLibrary.X11.selection.converted = 0; + sourceSize = strlen(_glfwLibrary.X11.selection.string) + 1; - // Check the length of data to receive (rembytes) - XGetWindowProperty(_glfwLibrary.X11.display, - window->X11.handle, - _glfwLibrary.X11.selection.request, - 0, 0, - 0, - AnyPropertyType, - &type, - &fmt, - &len, &rembytes, - &d); + targetSize = sourceSize; + if (targetSize > size) + targetSize = size; - // The number of bytes remaining (which is all of them) - if (rembytes > 0) - { - int result = XGetWindowProperty(_glfwLibrary.X11.display, - window->X11.handle, - _glfwLibrary.X11.selection.request, - 0, rembytes, - 0, - AnyPropertyType, - &type, - &fmt, - &len, &dummy, - &d); - if (result == Success) - { - size_t s; + memcpy(string, _glfwLibrary.X11.selection.string, targetSize); + string[targetSize - 1] = '\0'; - if (rembytes < size - 1) - s = rembytes; - else - s = size - 1; - - // Copy the data out. - memcpy(data, d, s); - - // Null-terminate strings. - ((char*) data)[s] = '\0'; - - // Free the data allocated using X11. - XFree(d); - - // Return the actual number of bytes. - return rembytes; - } - else - { - // Free the data allocated using X11. - XFree(d); - return 0; - } - } - - return 0; + return sourceSize; } diff --git a/src/x11_init.c b/src/x11_init.c index 535ede30..3af08cf4 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -597,11 +597,15 @@ static GLboolean initDisplay(void) // the keyboard mapping. updateKeyCodeLUT(); + // Find or create selection property atom + _glfwLibrary.X11.selection.property = + XInternAtom(_glfwLibrary.X11.display, "GLFW_SELECTION", False); + // Find or create clipboard atom _glfwLibrary.X11.selection.atom = XInternAtom(_glfwLibrary.X11.display, "CLIPBOARD", False); - // Find or create selection atoms + // Find or create selection target atoms _glfwLibrary.X11.selection.formats[_GLFW_CLIPBOARD_FORMAT_UTF8] = XInternAtom(_glfwLibrary.X11.display, "UTF8_STRING", False); _glfwLibrary.X11.selection.formats[_GLFW_CLIPBOARD_FORMAT_COMPOUND] = @@ -609,6 +613,10 @@ static GLboolean initDisplay(void) _glfwLibrary.X11.selection.formats[_GLFW_CLIPBOARD_FORMAT_STRING] = XA_STRING; + _glfwLibrary.X11.selection.targets = XInternAtom(_glfwLibrary.X11.display, + "TARGETS", + False); + return GL_TRUE; } diff --git a/src/x11_platform.h b/src/x11_platform.h index 8de54ead..2de3367e 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -91,6 +91,12 @@ #define _GLFW_CLIPBOARD_FORMAT_STRING 2 #define _GLFW_CLIPBOARD_FORMAT_COUNT 3 +// Clipboard conversion status tokens +#define _GLFW_CONVERSION_INACTIVE 0 +#define _GLFW_CONVERSION_SUCCEEDED 1 +#define _GLFW_CONVERSION_FAILED 2 + + //======================================================================== // GLFW platform specific types //======================================================================== @@ -235,10 +241,11 @@ typedef struct _GLFWlibraryX11 struct { Atom atom; Atom formats[_GLFW_CLIPBOARD_FORMAT_COUNT]; - size_t stringLength; char* string; - Atom request; - int converted; + Atom target; + Atom targets; + Atom property; + int status; } selection; #if defined(_GLFW_DLOPEN_LIBGL) @@ -281,7 +288,8 @@ void _glfwTerminateJoysticks(void); long _glfwKeySym2Unicode(KeySym keysym); // Clipboard handling -Atom _glfwSelectionRequest(XSelectionRequestEvent *request); +GLboolean _glfwReadSelection(XSelectionEvent* request); +Atom _glfwWriteSelection(XSelectionRequestEvent* request); // Event processing void _glfwProcessPendingEvents(void); diff --git a/src/x11_window.c b/src/x11_window.c index 854480c5..a84e209a 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -1241,28 +1241,39 @@ static void processSingleEvent(void) break; } + case SelectionClear: + { + // The ownership of the selection was lost + + free(_glfwLibrary.X11.selection.string); + _glfwLibrary.X11.selection.string = NULL; + break; + } + case SelectionNotify: { - // Selection notification triggered by the XConvertSelection + // The selection conversion status is available - // Check if the notification property matches the request - if (event.xselection.property != _glfwLibrary.X11.selection.request) - _glfwLibrary.X11.selection.converted = 2; - else // It was successful - _glfwLibrary.X11.selection.converted = 1; + XSelectionEvent* request = &event.xselection; + + if (_glfwReadSelection(request)) + _glfwLibrary.X11.selection.status = _GLFW_CONVERSION_SUCCEEDED; + else + _glfwLibrary.X11.selection.status = _GLFW_CONVERSION_FAILED; break; } case SelectionRequest: { - // Selection request triggered by someone wanting data from the - // X11 clipboard - XSelectionRequestEvent *request = &event.xselectionrequest; + // The contents of the selection was requested + + XSelectionRequestEvent* request = &event.xselectionrequest; - // Construct the response XEvent response; - response.xselection.property = _glfwSelectionRequest(request); + memset(&response, 0, sizeof(response)); + + response.xselection.property = _glfwWriteSelection(request); response.xselection.type = SelectionNotify; response.xselection.display = request->display; response.xselection.requestor = request->requestor; @@ -1270,9 +1281,9 @@ static void processSingleEvent(void) response.xselection.target = request->target; response.xselection.time = request->time; - // Send off the event - XSendEvent(_glfwLibrary.X11.display, request->requestor, 0, 0, &response); - + XSendEvent(_glfwLibrary.X11.display, + request->requestor, + False, 0, &response); break; } From 721e0a7fd0e3804d7d162235f295bbf54b4f3fc6 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 11 Apr 2012 23:53:47 +0200 Subject: [PATCH 164/226] Clarified comment. --- src/x11_clipboard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/x11_clipboard.c b/src/x11_clipboard.c index 1b9e1fa3..55259e4f 100644 --- a/src/x11_clipboard.c +++ b/src/x11_clipboard.c @@ -108,7 +108,7 @@ Atom _glfwWriteSelection(XSelectionRequestEvent* request) { if (request->target == _glfwLibrary.X11.selection.formats[i]) { - // The requested format is one we support + // The requested target is one we support XChangeProperty(_glfwLibrary.X11.display, request->requestor, From f868712f0250cb65dd5475ec691bce356c61f2e0 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 12 Apr 2012 00:51:58 +0200 Subject: [PATCH 165/226] Simplified clipboard API. --- include/GL/glfw3.h | 2 +- src/clipboard.c | 9 +++------ src/cocoa_clipboard.m | 15 ++++++--------- src/cocoa_platform.h | 2 ++ src/internal.h | 2 +- src/win32_clipboard.c | 31 +++++++++++-------------------- src/win32_platform.h | 1 + src/x11_clipboard.c | 16 +++------------- tests/clipboard.c | 11 +++++------ 9 files changed, 33 insertions(+), 56 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 32c3899a..ceb3df76 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -581,7 +581,7 @@ GLFWAPI int glfwGetJoystickButtons(int joy, unsigned char* buttons, int numbutto /* Clipboard */ GLFWAPI void glfwSetClipboardString(GLFWwindow window, const char* string); -GLFWAPI size_t glfwGetClipboardString(GLFWwindow window, char* string, size_t size); +GLFWAPI const char* glfwGetClipboardString(GLFWwindow window); /* Time */ GLFWAPI double glfwGetTime(void); diff --git a/src/clipboard.c b/src/clipboard.c index b66d5656..0bdea5b4 100644 --- a/src/clipboard.c +++ b/src/clipboard.c @@ -59,19 +59,16 @@ GLFWAPI void glfwSetClipboardString(GLFWwindow handle, const char* string) // Return the current clipboard contents //======================================================================== -GLFWAPI size_t glfwGetClipboardString(GLFWwindow handle, char* string, size_t size) +GLFWAPI const char* glfwGetClipboardString(GLFWwindow handle) { _GLFWwindow* window = (_GLFWwindow*) handle; if (!_glfwInitialized) { _glfwSetError(GLFW_NOT_INITIALIZED, NULL); - return 0; + return NULL; } - if (!string || !size) - return 0; - - return _glfwPlatformGetClipboardString(window, string, size); + return _glfwPlatformGetClipboardString(window); } diff --git a/src/cocoa_clipboard.m b/src/cocoa_clipboard.m index e52b839e..07bf8856 100644 --- a/src/cocoa_clipboard.m +++ b/src/cocoa_clipboard.m @@ -56,7 +56,7 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) // Return the current clipboard contents //======================================================================== -size_t _glfwPlatformGetClipboardString(_GLFWwindow* window, char* string, size_t size) +const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) { const char* source; size_t targetSize; @@ -65,7 +65,7 @@ size_t _glfwPlatformGetClipboardString(_GLFWwindow* window, char* string, size_t if (![[pasteboard types] containsObject:NSStringPboardType]) { _glfwSetError(GLFW_FORMAT_UNAVAILABLE, NULL); - return 0; + return NULL; } NSString* object = [pasteboard stringForType:NSStringPboardType]; @@ -73,15 +73,12 @@ size_t _glfwPlatformGetClipboardString(_GLFWwindow* window, char* string, size_t { _glfwSetError(GLFW_PLATFORM_ERROR, "Cocoa/NSGL: Failed to retrieve object from pasteboard"); - return 0; + return NULL; } - source = [object UTF8String]; - targetSize = strlen(source) + 1; - if (targetSize > size) - targetSize = size; + free(_glfwLibrary.NS.clipboardString); + _glfwLibrary.NS.clipboardString = strdup([object UTF8String]); - strlcpy(string, source, targetSize); - return 0; + return _glfwLibrary.NS.clipboardString; } diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index ea12273e..77aa3481 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -95,6 +95,8 @@ typedef struct _GLFWlibraryNS CGEventSourceRef eventSource; id delegate; id autoreleasePool; + + char* clipboardString; } _GLFWlibraryNS; diff --git a/src/internal.h b/src/internal.h index 407270ea..4e7bce1a 100644 --- a/src/internal.h +++ b/src/internal.h @@ -290,7 +290,7 @@ void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp); // Clipboard void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string); -size_t _glfwPlatformGetClipboardString(_GLFWwindow* window, char *data, size_t size); +const char* _glfwPlatformGetClipboardString(_GLFWwindow* window); // Joystick int _glfwPlatformGetJoystickParam(int joy, int param); diff --git a/src/win32_clipboard.c b/src/win32_clipboard.c index 9b14f158..2b8742ce 100644 --- a/src/win32_clipboard.c +++ b/src/win32_clipboard.c @@ -94,23 +94,21 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) // Return the current clipboard contents //======================================================================== -size_t _glfwPlatformGetClipboardString(_GLFWwindow* window, char* string, size_t size) +const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) { HANDLE stringHandle; - char* utf8String; - size_t utf8Size; if (!IsClipboardFormatAvailable(CF_UNICODETEXT)) { _glfwSetError(GLFW_FORMAT_UNAVAILABLE, NULL); - return 0; + return NULL; } if (!OpenClipboard(window->Win32.handle)) { _glfwSetError(GLFW_PLATFORM_ERROR, "Win32/WGL: Failed to open clipboard"); - return 0; + return NULL; } stringHandle = GetClipboardData(CF_UNICODETEXT); @@ -120,30 +118,23 @@ size_t _glfwPlatformGetClipboardString(_GLFWwindow* window, char* string, size_t _glfwSetError(GLFW_PLATFORM_ERROR, "Win32/WGL: Failed to retrieve clipboard data"); - return 0; + return NULL; } - utf8String = _glfwCreateUTF8FromWideString(GlobalLock(stringHandle)); + free(_glfwLibrary.Win32.clipboardString); + _glfwLibrary.Win32.clipboardString = + _glfwCreateUTF8FromWideString(GlobalLock(stringHandle)); + GlobalUnlock(stringHandle); CloseClipboard(); - if (!utf8String) + if (!_glfwLibrary.Win32.clipboardString) { _glfwSetError(GLFW_PLATFORM_ERROR, "Win32/WGL: Failed to convert wide string to UTF-8"); - return 0; + return NULL; } - utf8Size = strlen(utf8String) + 1; - if (utf8Size > size) - { - memcpy(string, utf8String, size); - string[size - 1] = '\0'; - } - else - memcpy(string, utf8String, utf8Size); - - free(utf8String); - return utf8Size; + return _glfwLibrary.Win32.clipboardString; } diff --git a/src/win32_platform.h b/src/win32_platform.h index b2ba9182..7c369767 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -177,6 +177,7 @@ typedef struct _GLFWlibraryWin32 ATOM classAtom; // Window class atom HHOOK keyboardHook; // Keyboard hook handle DWORD foregroundLockTimeout; + char* clipboardString; // Default monitor struct { diff --git a/src/x11_clipboard.c b/src/x11_clipboard.c index 55259e4f..a833ed1f 100644 --- a/src/x11_clipboard.c +++ b/src/x11_clipboard.c @@ -152,10 +152,9 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) // Return the current clipboard contents //======================================================================== -size_t _glfwPlatformGetClipboardString(_GLFWwindow* window, char* string, size_t size) +const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) { int i; - size_t sourceSize, targetSize; _glfwLibrary.X11.selection.status = _GLFW_CONVERSION_INACTIVE; @@ -184,18 +183,9 @@ size_t _glfwPlatformGetClipboardString(_GLFWwindow* window, char* string, size_t { _glfwSetError(GLFW_FORMAT_UNAVAILABLE, "X11/GLX: Failed to convert selection to string"); - return 0; + return NULL; } - sourceSize = strlen(_glfwLibrary.X11.selection.string) + 1; - - targetSize = sourceSize; - if (targetSize > size) - targetSize = size; - - memcpy(string, _glfwLibrary.X11.selection.string, targetSize); - string[targetSize - 1] = '\0'; - - return sourceSize; + return _glfwLibrary.X11.selection.string; } diff --git a/tests/clipboard.c b/tests/clipboard.c index da776e61..ebeb98dd 100644 --- a/tests/clipboard.c +++ b/tests/clipboard.c @@ -59,16 +59,15 @@ static void key_callback(GLFWwindow window, int key, int action) case GLFW_KEY_V: if (control_is_down(window)) { - char buffer[4096]; - size_t size; + const char* string; printf("Paste test.\n"); - size = glfwGetClipboardString(window, buffer, sizeof(buffer)); - if (size >= sizeof(buffer)) - printf("Buffer wasn't big enough to hold clipboard data.\n"); + string = glfwGetClipboardString(window); + if (!string) + printf("Failed to retrieve clipboard string\n"); - printf("[%lu]: %s\n", (unsigned long) size, buffer); + printf("%s\n", string); } break; From bf5b436ca58d1203b7b75f229c3fa89271192a21 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 12 Apr 2012 00:55:30 +0200 Subject: [PATCH 166/226] Removed unused variables. --- src/cocoa_clipboard.m | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/cocoa_clipboard.m b/src/cocoa_clipboard.m index 07bf8856..56b98437 100644 --- a/src/cocoa_clipboard.m +++ b/src/cocoa_clipboard.m @@ -58,8 +58,6 @@ void _glfwPlatformSetClipboardString(_GLFWwindow* window, const char* string) const char* _glfwPlatformGetClipboardString(_GLFWwindow* window) { - const char* source; - size_t targetSize; NSPasteboard* pasteboard = [NSPasteboard generalPasteboard]; if (![[pasteboard types] containsObject:NSStringPboardType]) From 9ace27f97b873c0d73c24dd9823864ca8ca27b48 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 12 Apr 2012 17:28:58 +0200 Subject: [PATCH 167/226] Updated clipboard test. --- tests/clipboard.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/tests/clipboard.c b/tests/clipboard.c index ebeb98dd..9f373dd6 100644 --- a/tests/clipboard.c +++ b/tests/clipboard.c @@ -61,13 +61,11 @@ static void key_callback(GLFWwindow window, int key, int action) { const char* string; - printf("Paste test.\n"); - string = glfwGetClipboardString(window); - if (!string) - printf("Failed to retrieve clipboard string\n"); - - printf("%s\n", string); + if (string) + printf("Clipboard contains \"%s\"\n", string); + else + printf("Clipboard does not contain a string\n"); } break; @@ -76,7 +74,7 @@ static void key_callback(GLFWwindow window, int key, int action) { const char* string = "Hello GLFW World!"; glfwSetClipboardString(window, string); - printf("Setting clipboard to: %s\n", string); + printf("Setting clipboard to \"%s\"\n", string); } break; } @@ -89,7 +87,7 @@ static void size_callback(GLFWwindow window, int width, int height) static void error_callback(int error, const char* description) { - fprintf(stderr, "Error: %s in %s\n", glfwErrorString(error), description); + fprintf(stderr, "Error in %s\n", description); } int main(int argc, char** argv) @@ -115,7 +113,7 @@ int main(int argc, char** argv) if (!glfwInit()) { - fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); + fprintf(stderr, "Failed to initialize GLFW\n"); exit(EXIT_FAILURE); } @@ -124,7 +122,7 @@ int main(int argc, char** argv) { glfwTerminate(); - fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError())); + fprintf(stderr, "Failed to open GLFW window\n"); exit(EXIT_FAILURE); } @@ -146,7 +144,7 @@ int main(int argc, char** argv) glRectf(-0.5f, -0.5f, 0.5f, 0.5f); glfwSwapBuffers(); - glfwPollEvents(); + glfwWaitEvents(); } glfwTerminate(); From f8a726371e6ef427fe0125ebb9b28ce91db71055 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 12 Apr 2012 18:42:56 +0200 Subject: [PATCH 168/226] Fixed test description. --- tests/clipboard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/clipboard.c b/tests/clipboard.c index 9f373dd6..3b732290 100644 --- a/tests/clipboard.c +++ b/tests/clipboard.c @@ -1,5 +1,5 @@ //======================================================================== -// Gamma correction test program +// Clipboard test program // Copyright (c) Camilla Berglund // // This software is provided 'as-is', without any express or implied From 88ce656b1e1c76ef77585f50463748a852beb485 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 13 Apr 2012 12:52:07 +0200 Subject: [PATCH 169/226] Removed unused header. --- include/GL/glfw3.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index ceb3df76..6fd41cae 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -173,10 +173,6 @@ extern "C" { #endif #endif -/* This is needed for the declaration of size_t. - */ -#include - /************************************************************************* * GLFW version From 351f2b2664f44431de1f66715b155df31c0e35e8 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 13 Apr 2012 12:57:04 +0200 Subject: [PATCH 170/226] Fixed build setup for clipboard test. --- tests/CMakeLists.txt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index daa17a31..9f2afa9f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -11,9 +11,8 @@ endif() include_directories(${GLFW_SOURCE_DIR}/include ${GLFW_SOURCE_DIR}/support ${OPENGL_INCLUDE_DIR}) -add_executable(clipboard clipboard.c) -target_link_libraries(clipboard ${STATIC_DEPS}) +add_executable(clipboard clipboard.c getopt.c) add_executable(defaults defaults.c) add_executable(events events.c) add_executable(fsaa fsaa.c getopt.c) @@ -43,8 +42,8 @@ add_executable(windows WIN32 MACOSX_BUNDLE windows.c) set_target_properties(windows PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Windows") set(WINDOWS_BINARIES accuracy sharing tearing title windows) -set(CONSOLE_BINARIES defaults events fsaa fsfocus gamma glfwinfo iconify - joysticks listmodes modes peter reopen) +set(CONSOLE_BINARIES clipboard defaults events fsaa fsfocus gamma glfwinfo + iconify joysticks listmodes modes peter reopen) if (MSVC) # Tell MSVC to use main instead of WinMain for Windows subsystem executables From 4994acb7e15ab89f4fe7c71d06384a4cafb4504d Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sat, 14 Apr 2012 23:01:35 +0200 Subject: [PATCH 171/226] Removed superfluous test. --- src/opengl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/opengl.c b/src/opengl.c index f4c6984c..b35f8694 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -517,8 +517,7 @@ GLFWAPI void glfwSwapBuffers(void) return; } - if (_glfwLibrary.currentWindow) - _glfwPlatformSwapBuffers(); + _glfwPlatformSwapBuffers(); } From a7d19ed77e15ad3a4c01a1bc8e47fa5b8cbf25c4 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 15 Apr 2012 00:40:50 +0200 Subject: [PATCH 172/226] Removed superfluous comment. --- src/x11_window.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/x11_window.c b/src/x11_window.c index a84e209a..6fc8c2fd 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -1287,7 +1287,6 @@ static void processSingleEvent(void) break; } - // Was the window destroyed? case DestroyNotify: return; From a73b45b7a7a19f3da1f9dff50902cb1a7dafd81e Mon Sep 17 00:00:00 2001 From: quarnster Date: Mon, 16 Apr 2012 12:33:34 +0300 Subject: [PATCH 173/226] Need to include sys/param.h for MAXPATHLEN. --- src/cocoa_init.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cocoa_init.m b/src/cocoa_init.m index 594266d1..63c09e8a 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -28,7 +28,7 @@ //======================================================================== #include "internal.h" - +#include // For MAXPATHLEN //======================================================================== // Change to our application bundle's resources directory, if present From 53fab2f16bfa3eaeac36eb6b54cd728bd4afcf41 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 17 Apr 2012 17:55:11 +0200 Subject: [PATCH 174/226] Fixed VC++ errors. --- src/win32_joystick.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) mode change 100644 => 100755 src/win32_joystick.c diff --git a/src/win32_joystick.c b/src/win32_joystick.c old mode 100644 new mode 100755 index 9fad3002..c27218db --- a/src/win32_joystick.c +++ b/src/win32_joystick.c @@ -80,6 +80,7 @@ static float calcJoystickPos(DWORD pos, DWORD min, DWORD max) int _glfwPlatformGetJoystickParam(int joy, int param) { JOYCAPS jc; + int hats; if (!isJoystickPresent(joy)) return 0; @@ -91,7 +92,7 @@ int _glfwPlatformGetJoystickParam(int joy, int param) // Get joystick capabilities _glfw_joyGetDevCaps(joy - GLFW_JOYSTICK_1, &jc, sizeof(JOYCAPS)); - const int hats = (jc.wCaps & JOYCAPS_HASPOV) && (jc.wCaps & JOYCAPS_POV4DIR) ? 1 : 0; + hats = (jc.wCaps & JOYCAPS_HASPOV) && (jc.wCaps & JOYCAPS_POV4DIR) ? 1 : 0; switch (param) { @@ -166,7 +167,10 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, { JOYCAPS jc; JOYINFOEX ji; - int button; + int button, hats; + + // Bit fields of button presses for each direction, including nil + const int directions[9] = { 1, 3, 2, 6, 4, 12, 8, 9, 0 }; if (!isJoystickPresent(joy)) return 0; @@ -187,11 +191,11 @@ int _glfwPlatformGetJoystickButtons(int joy, unsigned char* buttons, } // Virtual buttons - Inject data from hats - // Each hat is exposed as 4 buttons which exposes 8 directions with concurrent button presses - // (Note: This API only exposes one hat) + // Each hat is exposed as 4 buttons which exposes 8 directions with + // concurrent button presses + // NOTE: this API exposes only one hat - const int hats = (jc.wCaps & JOYCAPS_HASPOV) && (jc.wCaps & JOYCAPS_POV4DIR) ? 1 : 0; - const int directions[9] = { 1, 3, 2, 6, 4, 12, 8, 9, 0 }; // Bit fields of button presses for each direction, including nil + hats = (jc.wCaps & JOYCAPS_HASPOV) && (jc.wCaps & JOYCAPS_POV4DIR) ? 1 : 0; if (hats > 0) { From 141b56afc0e2852ae26deac2540c8f640c002df2 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 19 Apr 2012 16:57:44 +0200 Subject: [PATCH 175/226] Added libm as direct dependency for tests and examples. --- examples/CMakeLists.txt | 2 +- tests/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 76135a92..3e7065c6 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -3,7 +3,7 @@ link_libraries(glfw ${OPENGL_glu_LIBRARY}) if (BUILD_SHARED_LIBS) add_definitions(-DGLFW_DLL) - link_libraries(${OPENGL_gl_LIBRARY}) + link_libraries(${OPENGL_gl_LIBRARY} ${MATH_LIBRARY}) else() link_libraries(${glfw_LIBRARIES}) endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9f2afa9f..c4db1a57 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -3,7 +3,7 @@ link_libraries(glfw ${OPENGL_glu_LIBRARY}) if (BUILD_SHARED_LIBS) add_definitions(-DGLFW_DLL) - link_libraries(${OPENGL_gl_LIBRARY}) + link_libraries(${OPENGL_gl_LIBRARY} ${MATH_LIBRARY}) else() link_libraries(${glfw_LIBRARIES}) endif() From 7a5c2d5f75be699c450df42b10d76f90beffac28 Mon Sep 17 00:00:00 2001 From: Lambert Clara Date: Sat, 21 Apr 2012 11:47:58 +0200 Subject: [PATCH 176/226] Fix clang warning : self-comparison always evaluates to false --- tests/modes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/modes.c b/tests/modes.c index 9c558d47..07407e13 100644 --- a/tests/modes.c +++ b/tests/modes.c @@ -153,7 +153,7 @@ static void test_modes(GLFWvidmode* modes, int count) glfwGetWindowSize(window, &width, &height); - if (width != modes[i].width || height != height) + if (width != modes[i].width || height != modes[i].height) { printf("*** Size mismatch: %ix%i instead of %ix%i\n", width, height, From 97f7e60f8bd72bab706ddc10678d046065185803 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 22 Apr 2012 00:21:42 +0200 Subject: [PATCH 177/226] Added credits. --- readme.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.html b/readme.html index 790e5ac7..413be001 100644 --- a/readme.html +++ b/readme.html @@ -838,6 +838,8 @@ their skills. Special thanks go out to:

  • Keith Bauer, for his invaluable help with porting and maintaining GLFW on Mac OS X, and for his many ideas
  • +
  • Lambert Clara, for a bug fix for the modes test
  • +
  • Jarrod Davis, for the Delphi port of GLFW
  • Olivier Delannoy, for the initial implementation of FSAA support on From 2ac8da74659005be130882318e5baa31c1f7b655 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 22 Apr 2012 12:58:05 +0200 Subject: [PATCH 178/226] Merged patch #3519669. --- src/cocoa_window.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 9e64b2d3..b5231ec9 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -1168,7 +1168,7 @@ void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y) // calculating the maximum y coordinate of all screens, since Cocoa's // "global coordinates" are upside down from CG's... - NSPoint localPoint = NSMakePoint(x, y); + NSPoint localPoint = NSMakePoint(x, window->height - y); NSPoint globalPoint = [window->NS.object convertBaseToScreen:localPoint]; CGPoint mainScreenOrigin = CGDisplayBounds(CGMainDisplayID()).origin; double mainScreenHeight = CGDisplayBounds(CGMainDisplayID()).size.height; From 21e77fe1a6a429558a6d50dcab376810078bd67b Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 22 Apr 2012 15:53:02 +0200 Subject: [PATCH 179/226] Split platform-specific global data. --- src/cocoa_init.m | 4 ++-- src/cocoa_opengl.m | 2 +- src/cocoa_platform.h | 17 +++++++++++++---- src/internal.h | 3 ++- src/win32_platform.h | 15 +++++++++++++-- src/x11_init.c | 14 +++++++------- src/x11_platform.h | 23 ++++++++++++++++------- src/x11_window.c | 2 +- 8 files changed, 55 insertions(+), 25 deletions(-) diff --git a/src/cocoa_init.m b/src/cocoa_init.m index 63c09e8a..329bcfa4 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -81,9 +81,9 @@ int _glfwPlatformInit(void) { _glfwLibrary.NS.autoreleasePool = [[NSAutoreleasePool alloc] init]; - _glfwLibrary.NS.OpenGLFramework = + _glfwLibrary.NSGL.framework = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.opengl")); - if (_glfwLibrary.NS.OpenGLFramework == NULL) + if (_glfwLibrary.NSGL.framework == NULL) { _glfwSetError(GLFW_PLATFORM_ERROR, "glfwInit: Failed to locate OpenGL framework"); diff --git a/src/cocoa_opengl.m b/src/cocoa_opengl.m index 0ea39076..33bf4ab5 100644 --- a/src/cocoa_opengl.m +++ b/src/cocoa_opengl.m @@ -94,7 +94,7 @@ void* _glfwPlatformGetProcAddress(const char* procname) procname, kCFStringEncodingASCII); - void* symbol = CFBundleGetFunctionPointerForName(_glfwLibrary.NS.OpenGLFramework, + void* symbol = CFBundleGetFunctionPointerForName(_glfwLibrary.NSGL.framework, symbolName); CFRelease(symbolName); diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index 77aa3481..97e903d7 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -43,8 +43,9 @@ typedef void* id; #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowNS NS -#define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryNS NS #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextNSGL NSGL +#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryNS NS +#define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryNSGL NSGL //======================================================================== @@ -80,7 +81,7 @@ typedef struct _GLFWwindowNS //------------------------------------------------------------------------ -// Platform-specific library global data +// Platform-specific library global data for Cocoa //------------------------------------------------------------------------ typedef struct _GLFWlibraryNS { @@ -89,8 +90,6 @@ typedef struct _GLFWlibraryNS double resolution; } timer; - // dlopen handle for dynamically loading OpenGL extension entry points - void* OpenGLFramework; CGDisplayModeRef desktopMode; CGEventSourceRef eventSource; id delegate; @@ -100,6 +99,16 @@ typedef struct _GLFWlibraryNS } _GLFWlibraryNS; +//------------------------------------------------------------------------ +// Platform-specific library global data for NSGL +//------------------------------------------------------------------------ +typedef struct _GLFWlibraryNSGL +{ + // dlopen handle for dynamically loading OpenGL extension entry points + void* framework; +} _GLFWlibraryNSGL; + + //======================================================================== // Prototypes for platform specific internal functions //======================================================================== diff --git a/src/internal.h b/src/internal.h index 4e7bce1a..6398bdc5 100644 --- a/src/internal.h +++ b/src/internal.h @@ -247,7 +247,8 @@ struct _GLFWlibrary int originalRampSize; // This is defined in the current port's platform.h - _GLFW_PLATFORM_LIBRARY_STATE; + _GLFW_PLATFORM_LIBRARY_WINDOW_STATE; + _GLFW_PLATFORM_LIBRARY_OPENGL_STATE; }; diff --git a/src/win32_platform.h b/src/win32_platform.h index 7c369767..e7b7b165 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -111,8 +111,9 @@ typedef DWORD (WINAPI * TIMEGETTIME_T) (void); #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowWin32 Win32 -#define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryWin32 Win32 #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextWGL WGL +#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryWin32 Win32 +#define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryWGL WGL //======================================================================== @@ -169,7 +170,7 @@ typedef struct _GLFWwindowWin32 //------------------------------------------------------------------------ -// Platform-specific library global data +// Platform-specific library global data for Win32 //------------------------------------------------------------------------ typedef struct _GLFWlibraryWin32 { @@ -210,6 +211,16 @@ typedef struct _GLFWlibraryWin32 } _GLFWlibraryWin32; +//------------------------------------------------------------------------ +// Platform-specific library global data for WGL +//------------------------------------------------------------------------ +typedef struct _GLFWlibraryWGL +{ + int dummy; + +} _GLFWlibraryWGL; + + //======================================================================== // Prototypes for platform specific internal functions //======================================================================== diff --git a/src/x11_init.c b/src/x11_init.c index 3af08cf4..d59fbcc6 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -55,8 +55,8 @@ static void initLibraries(void) for (i = 0; libGL_names[i] != NULL; i++) { - _glfwLibrary.X11.libGL = dlopen(libGL_names[i], RTLD_LAZY | RTLD_GLOBAL); - if (_glfwLibrary.X11.libGL) + _glfwLibrary.GLX.libGL = dlopen(libGL_names[i], RTLD_LAZY | RTLD_GLOBAL); + if (_glfwLibrary.GLX.libGL) break; } #endif @@ -569,8 +569,8 @@ static GLboolean initDisplay(void) } if (!glXQueryVersion(_glfwLibrary.X11.display, - &_glfwLibrary.X11.glxMajor, - &_glfwLibrary.X11.glxMinor)) + &_glfwLibrary.GLX.majorVersion, + &_glfwLibrary.GLX.minorVersion)) { _glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11/GLX: Failed to query GLX version"); @@ -775,10 +775,10 @@ int _glfwPlatformTerminate(void) // Unload libGL.so if necessary #ifdef _GLFW_DLOPEN_LIBGL - if (_glfwLibrary.X11.libGL != NULL) + if (_glfwLibrary.GLX.libGL != NULL) { - dlclose(_glfwLibrary.X11.libGL); - _glfwLibrary.X11.libGL = NULL; + dlclose(_glfwLibrary.GLX.libGL); + _glfwLibrary.GLX.libGL = NULL; } #endif diff --git a/src/x11_platform.h b/src/x11_platform.h index 2de3367e..013ca4e0 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -75,15 +75,16 @@ #elif defined(_GLFW_HAS_GLXGETPROCADDRESSEXT) #define _glfw_glXGetProcAddress(x) glXGetProcAddressEXT(x) #elif defined(_GLFW_HAS_DLOPEN) - #define _glfw_glXGetProcAddress(x) dlsym(_glfwLibrary.X11.libGL, x) + #define _glfw_glXGetProcAddress(x) dlsym(_glfwLibrary.GLX.libGL, x) #define _GLFW_DLOPEN_LIBGL #else #error "No OpenGL entry point retrieval mechanism was enabled" #endif #define _GLFW_PLATFORM_WINDOW_STATE _GLFWwindowX11 X11 -#define _GLFW_PLATFORM_LIBRARY_STATE _GLFWlibraryX11 X11 #define _GLFW_PLATFORM_CONTEXT_STATE _GLFWcontextGLX GLX +#define _GLFW_PLATFORM_LIBRARY_WINDOW_STATE _GLFWlibraryX11 X11 +#define _GLFW_PLATFORM_LIBRARY_OPENGL_STATE _GLFWlibraryGLX GLX // Clipboard format atom indices #define _GLFW_CLIPBOARD_FORMAT_UTF8 0 @@ -157,7 +158,7 @@ typedef struct _GLFWwindowX11 //------------------------------------------------------------------------ -// Platform-specific library global data +// Platform-specific library global data for X11 //------------------------------------------------------------------------ typedef struct _GLFWlibraryX11 { @@ -177,9 +178,6 @@ typedef struct _GLFWlibraryX11 // True if window manager supports EWMH GLboolean hasEWMH; - // Server-side GLX version - int glxMajor, glxMinor; - struct { GLboolean available; int eventBase; @@ -248,10 +246,21 @@ typedef struct _GLFWlibraryX11 int status; } selection; +} _GLFWlibraryX11; + + +//------------------------------------------------------------------------ +// Platform-specific library global data for GLX +//------------------------------------------------------------------------ +typedef struct _GLFWlibraryGLX +{ + // Server-side GLX version + int majorVersion, minorVersion; + #if defined(_GLFW_DLOPEN_LIBGL) void* libGL; // dlopen handle for libGL.so #endif -} _GLFWlibraryX11; +} _GLFWlibraryGLX; //------------------------------------------------------------------------ diff --git a/src/x11_window.c b/src/x11_window.c index 6fc8c2fd..ccd99a60 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -131,7 +131,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) *found = 0; - if (_glfwLibrary.X11.glxMajor == 1 && _glfwLibrary.X11.glxMinor < 3) + if (_glfwLibrary.GLX.majorVersion == 1 && _glfwLibrary.GLX.minorVersion < 3) { if (!window->GLX.SGIX_fbconfig) { From 1a99827432cec6057f1e0655653a05a0c6f698a2 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 22 Apr 2012 21:49:38 +0200 Subject: [PATCH 180/226] Moved the type declarations. --- src/internal.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/internal.h b/src/internal.h index 6398bdc5..c20b1c9a 100644 --- a/src/internal.h +++ b/src/internal.h @@ -51,6 +51,17 @@ #define GLFW_STICK 2 +//======================================================================== +// Internal type declarations +//======================================================================== + +typedef struct _GLFWhints _GLFWhints; +typedef struct _GLFWwndconfig _GLFWwndconfig; +typedef struct _GLFWfbconfig _GLFWfbconfig; +typedef struct _GLFWwindow _GLFWwindow; +typedef struct _GLFWlibrary _GLFWlibrary; + + //------------------------------------------------------------------------ // Platform specific definitions goes in platform.h (which also includes // glfw.h) @@ -75,12 +86,6 @@ #error "No supported platform selected" #endif -typedef struct _GLFWhints _GLFWhints; -typedef struct _GLFWwndconfig _GLFWwndconfig; -typedef struct _GLFWfbconfig _GLFWfbconfig; -typedef struct _GLFWwindow _GLFWwindow; -typedef struct _GLFWlibrary _GLFWlibrary; - //------------------------------------------------------------------------ // Window hints, set by glfwOpenWindowHint and consumed by glfwOpenWindow From 49dfbe86b217a3cd94e8951f9c62d24dcb4ad43e Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 23 Apr 2012 12:48:57 +0200 Subject: [PATCH 181/226] Moved the majority of GLX code into opengl module. --- src/x11_opengl.c | 550 +++++++++++++++++++++++++++++++++++++++++++++ src/x11_platform.h | 7 +- src/x11_window.c | 520 +----------------------------------------- 3 files changed, 558 insertions(+), 519 deletions(-) diff --git a/src/x11_opengl.c b/src/x11_opengl.c index fd8bd313..825cacc2 100644 --- a/src/x11_opengl.c +++ b/src/x11_opengl.c @@ -30,15 +30,565 @@ #include "internal.h" +#include + // This is the only glXGetProcAddress variant not declared by glxext.h void (*glXGetProcAddressEXT(const GLubyte* procName))(); +//======================================================================== +// Initialize GLX-specific extensions +//======================================================================== + +static void initGLXExtensions(_GLFWwindow* window) +{ + if (_glfwPlatformExtensionSupported("GLX_EXT_swap_control")) + { + window->GLX.SwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC) + _glfwPlatformGetProcAddress("glXSwapIntervalEXT"); + + if (window->GLX.SwapIntervalEXT) + window->GLX.EXT_swap_control = GL_TRUE; + } + + if (_glfwPlatformExtensionSupported("GLX_SGI_swap_control")) + { + window->GLX.SwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC) + _glfwPlatformGetProcAddress("glXSwapIntervalSGI"); + + if (window->GLX.SwapIntervalSGI) + window->GLX.SGI_swap_control = GL_TRUE; + } + + if (_glfwPlatformExtensionSupported("GLX_SGIX_fbconfig")) + { + window->GLX.GetFBConfigAttribSGIX = (PFNGLXGETFBCONFIGATTRIBSGIXPROC) + _glfwPlatformGetProcAddress("glXGetFBConfigAttribSGIX"); + window->GLX.ChooseFBConfigSGIX = (PFNGLXCHOOSEFBCONFIGSGIXPROC) + _glfwPlatformGetProcAddress("glXChooseFBConfigSGIX"); + window->GLX.CreateContextWithConfigSGIX = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC) + _glfwPlatformGetProcAddress("glXCreateContextWithConfigSGIX"); + window->GLX.GetVisualFromFBConfigSGIX = (PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) + _glfwPlatformGetProcAddress("glXGetVisualFromFBConfigSGIX"); + + if (window->GLX.GetFBConfigAttribSGIX && + window->GLX.ChooseFBConfigSGIX && + window->GLX.CreateContextWithConfigSGIX && + window->GLX.GetVisualFromFBConfigSGIX) + { + window->GLX.SGIX_fbconfig = GL_TRUE; + } + } + + if (_glfwPlatformExtensionSupported("GLX_ARB_multisample")) + window->GLX.ARB_multisample = GL_TRUE; + + if (_glfwPlatformExtensionSupported("GLX_ARB_create_context")) + { + window->GLX.CreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) + _glfwPlatformGetProcAddress("glXCreateContextAttribsARB"); + + if (window->GLX.CreateContextAttribsARB) + window->GLX.ARB_create_context = GL_TRUE; + } + + if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_robustness")) + window->GLX.ARB_create_context_robustness = GL_TRUE; + + if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_profile")) + window->GLX.ARB_create_context_profile = GL_TRUE; + + if (_glfwPlatformExtensionSupported("GLX_EXT_create_context_es2_profile")) + window->GLX.EXT_create_context_es2_profile = GL_TRUE; +} + + +//======================================================================== +// Returns the specified attribute of the specified GLXFBConfig +// NOTE: Do not call this unless we have found GLX 1.3+ or GLX_SGIX_fbconfig +//======================================================================== + +static int getFBConfigAttrib(_GLFWwindow* window, GLXFBConfig fbconfig, int attrib) +{ + int value; + + if (window->GLX.SGIX_fbconfig) + { + window->GLX.GetFBConfigAttribSGIX(_glfwLibrary.X11.display, + fbconfig, attrib, &value); + } + else + glXGetFBConfigAttrib(_glfwLibrary.X11.display, fbconfig, attrib, &value); + + return value; +} + + +//======================================================================== +// Return a list of available and usable framebuffer configs +//======================================================================== + +static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) +{ + GLXFBConfig* fbconfigs; + _GLFWfbconfig* result; + int i, count = 0; + + *found = 0; + + if (_glfwLibrary.GLX.majorVersion == 1 && _glfwLibrary.GLX.minorVersion < 3) + { + if (!window->GLX.SGIX_fbconfig) + { + _glfwSetError(GLFW_OPENGL_UNAVAILABLE, + "X11/GLX: GLXFBConfig support not found"); + return NULL; + } + } + + if (window->GLX.SGIX_fbconfig) + { + fbconfigs = window->GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display, + _glfwLibrary.X11.screen, + NULL, + &count); + if (!count) + { + _glfwSetError(GLFW_OPENGL_UNAVAILABLE, + "X11/GLX: No GLXFBConfigs returned"); + return NULL; + } + } + else + { + fbconfigs = glXGetFBConfigs(_glfwLibrary.X11.display, + _glfwLibrary.X11.screen, + &count); + if (!count) + { + _glfwSetError(GLFW_OPENGL_UNAVAILABLE, + "X11/GLX: No GLXFBConfigs returned"); + return NULL; + } + } + + result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count); + if (!result) + { + _glfwSetError(GLFW_OUT_OF_MEMORY, + "X11/GLX: Failed to allocate _GLFWfbconfig array"); + return NULL; + } + + for (i = 0; i < count; i++) + { + if (!getFBConfigAttrib(window, fbconfigs[i], GLX_DOUBLEBUFFER) || + !getFBConfigAttrib(window, fbconfigs[i], GLX_VISUAL_ID)) + { + // Only consider double-buffered GLXFBConfigs with associated visuals + continue; + } + + if (!(getFBConfigAttrib(window, + fbconfigs[i], + GLX_RENDER_TYPE) & GLX_RGBA_BIT)) + { + // Only consider RGBA GLXFBConfigs + continue; + } + + if (!(getFBConfigAttrib(window, fbconfigs[i], GLX_DRAWABLE_TYPE) & GLX_WINDOW_BIT)) + { + // Only consider window GLXFBConfigs + continue; + } + + result[*found].redBits = getFBConfigAttrib(window, fbconfigs[i], GLX_RED_SIZE); + result[*found].greenBits = getFBConfigAttrib(window, fbconfigs[i], GLX_GREEN_SIZE); + result[*found].blueBits = getFBConfigAttrib(window, fbconfigs[i], GLX_BLUE_SIZE); + + result[*found].alphaBits = getFBConfigAttrib(window, fbconfigs[i], GLX_ALPHA_SIZE); + result[*found].depthBits = getFBConfigAttrib(window, fbconfigs[i], GLX_DEPTH_SIZE); + result[*found].stencilBits = getFBConfigAttrib(window, fbconfigs[i], GLX_STENCIL_SIZE); + + result[*found].accumRedBits = getFBConfigAttrib(window, fbconfigs[i], GLX_ACCUM_RED_SIZE); + result[*found].accumGreenBits = getFBConfigAttrib(window, fbconfigs[i], GLX_ACCUM_GREEN_SIZE); + result[*found].accumBlueBits = getFBConfigAttrib(window, fbconfigs[i], GLX_ACCUM_BLUE_SIZE); + result[*found].accumAlphaBits = getFBConfigAttrib(window, fbconfigs[i], GLX_ACCUM_ALPHA_SIZE); + + result[*found].auxBuffers = getFBConfigAttrib(window, fbconfigs[i], GLX_AUX_BUFFERS); + result[*found].stereo = getFBConfigAttrib(window, fbconfigs[i], GLX_STEREO); + + if (window->GLX.ARB_multisample) + result[*found].samples = getFBConfigAttrib(window, fbconfigs[i], GLX_SAMPLES); + else + result[*found].samples = 0; + + result[*found].platformID = (GLFWintptr) getFBConfigAttrib(window, fbconfigs[i], GLX_FBCONFIG_ID); + + (*found)++; + } + + XFree(fbconfigs); + + return result; +} + + +//======================================================================== +// Error handler for BadMatch errors when requesting context with +// unavailable OpenGL versions using the GLX_ARB_create_context extension +//======================================================================== + +static int errorHandler(Display *display, XErrorEvent* event) +{ + return 0; +} + + +//======================================================================== +// Read back framebuffer parameters from the context +//======================================================================== + +static void refreshContextParams(_GLFWwindow* window, GLXFBConfigID fbconfigID) +{ + int dummy; + GLXFBConfig* fbconfig; + + int attribs[] = { GLX_FBCONFIG_ID, fbconfigID, None }; + + if (window->GLX.SGIX_fbconfig) + { + fbconfig = window->GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display, + _glfwLibrary.X11.screen, + attribs, + &dummy); + } + else + { + fbconfig = glXChooseFBConfig(_glfwLibrary.X11.display, + _glfwLibrary.X11.screen, + attribs, + &dummy); + } + + if (fbconfig == NULL) + { + // This should never ever happen + // TODO: Flag this as an error and propagate up + _glfwSetError(GLFW_PLATFORM_ERROR, "X11/GLX: Cannot find known " + "GLXFBConfig by ID. This cannot " + "happen. Have a nice day.\n"); + abort(); + } + + // There is no clear definition of an "accelerated" context on X11/GLX, and + // true sounds better than false, so we hardcode true here + window->accelerated = GL_TRUE; + + window->redBits = getFBConfigAttrib(window, *fbconfig, GLX_RED_SIZE); + window->greenBits = getFBConfigAttrib(window, *fbconfig, GLX_GREEN_SIZE); + window->blueBits = getFBConfigAttrib(window, *fbconfig, GLX_BLUE_SIZE); + + window->alphaBits = getFBConfigAttrib(window, *fbconfig, GLX_ALPHA_SIZE); + window->depthBits = getFBConfigAttrib(window, *fbconfig, GLX_DEPTH_SIZE); + window->stencilBits = getFBConfigAttrib(window, *fbconfig, GLX_STENCIL_SIZE); + + window->accumRedBits = getFBConfigAttrib(window, *fbconfig, GLX_ACCUM_RED_SIZE); + window->accumGreenBits = getFBConfigAttrib(window, *fbconfig, GLX_ACCUM_GREEN_SIZE); + window->accumBlueBits = getFBConfigAttrib(window, *fbconfig, GLX_ACCUM_BLUE_SIZE); + window->accumAlphaBits = getFBConfigAttrib(window, *fbconfig, GLX_ACCUM_ALPHA_SIZE); + + window->auxBuffers = getFBConfigAttrib(window, *fbconfig, GLX_AUX_BUFFERS); + window->stereo = getFBConfigAttrib(window, *fbconfig, GLX_STEREO) ? GL_TRUE : GL_FALSE; + + // Get FSAA buffer sample count + if (window->GLX.ARB_multisample) + window->samples = getFBConfigAttrib(window, *fbconfig, GLX_SAMPLES); + else + window->samples = 0; + + XFree(fbconfig); +} + + +//======================================================================== +// Create the actual OpenGL context +//======================================================================== + +#define setGLXattrib(attribs, index, attribName, attribValue) \ + attribs[index++] = attribName; \ + attribs[index++] = attribValue; + +static int createContext(_GLFWwindow* window, + const _GLFWwndconfig* wndconfig, + GLXFBConfigID fbconfigID) +{ + int attribs[40]; + int dummy, index; + GLXFBConfig* fbconfig; + GLXContext share = NULL; + + if (wndconfig->share) + share = wndconfig->share->GLX.context; + + // Retrieve the previously selected GLXFBConfig + { + index = 0; + + setGLXattrib(attribs, index, GLX_FBCONFIG_ID, (int) fbconfigID); + setGLXattrib(attribs, index, None, None); + + if (window->GLX.SGIX_fbconfig) + { + fbconfig = window->GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display, + _glfwLibrary.X11.screen, + attribs, + &dummy); + } + else + { + fbconfig = glXChooseFBConfig(_glfwLibrary.X11.display, + _glfwLibrary.X11.screen, + attribs, + &dummy); + } + + if (fbconfig == NULL) + { + _glfwSetError(GLFW_PLATFORM_ERROR, + "X11/GLX: Failed to retrieve the selected GLXFBConfig"); + return GL_FALSE; + } + } + + // Retrieve the corresponding visual + if (window->GLX.SGIX_fbconfig) + { + window->GLX.visual = window->GLX.GetVisualFromFBConfigSGIX(_glfwLibrary.X11.display, + *fbconfig); + } + else + { + window->GLX.visual = glXGetVisualFromFBConfig(_glfwLibrary.X11.display, + *fbconfig); + } + + if (window->GLX.visual == NULL) + { + XFree(fbconfig); + + _glfwSetError(GLFW_PLATFORM_ERROR, + "X11/GLX: Failed to retrieve visual for GLXFBConfig"); + return GL_FALSE; + } + + if (window->GLX.ARB_create_context) + { + index = 0; + + if (wndconfig->glMajor != 1 || wndconfig->glMinor != 0) + { + // Request an explicitly versioned context + + setGLXattrib(attribs, index, GLX_CONTEXT_MAJOR_VERSION_ARB, wndconfig->glMajor); + setGLXattrib(attribs, index, GLX_CONTEXT_MINOR_VERSION_ARB, wndconfig->glMinor); + } + + if (wndconfig->glForward || wndconfig->glDebug || wndconfig->glRobustness) + { + int flags = 0; + + if (wndconfig->glForward) + flags |= GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB; + + if (wndconfig->glDebug) + flags |= GLX_CONTEXT_DEBUG_BIT_ARB; + + if (wndconfig->glRobustness) + flags |= GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB; + + setGLXattrib(attribs, index, GLX_CONTEXT_FLAGS_ARB, flags); + } + + if (wndconfig->glProfile) + { + int flags = 0; + + if (!window->GLX.ARB_create_context_profile) + { + _glfwSetError(GLFW_VERSION_UNAVAILABLE, + "X11/GLX: An OpenGL profile requested but " + "GLX_ARB_create_context_profile is unavailable"); + return GL_FALSE; + } + + if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE && + !window->GLX.EXT_create_context_es2_profile) + { + _glfwSetError(GLFW_VERSION_UNAVAILABLE, + "X11/GLX: OpenGL ES 2.x profile requested but " + "GLX_EXT_create_context_es2_profile is unavailable"); + return GL_FALSE; + } + + if (wndconfig->glProfile == GLFW_OPENGL_CORE_PROFILE) + flags = GLX_CONTEXT_CORE_PROFILE_BIT_ARB; + else if (wndconfig->glProfile == GLFW_OPENGL_COMPAT_PROFILE) + flags = GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; + else if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE) + flags = GLX_CONTEXT_ES2_PROFILE_BIT_EXT; + + setGLXattrib(attribs, index, GLX_CONTEXT_PROFILE_MASK_ARB, flags); + } + + if (wndconfig->glRobustness) + { + int strategy; + + if (!window->GLX.ARB_create_context_robustness) + { + _glfwSetError(GLFW_VERSION_UNAVAILABLE, + "X11/GLX: An OpenGL robustness strategy was " + "requested but GLX_ARB_create_context_robustness " + "is unavailable"); + return GL_FALSE; + } + + if (wndconfig->glRobustness == GLFW_OPENGL_NO_RESET_NOTIFICATION) + strategy = GLX_NO_RESET_NOTIFICATION_ARB; + else if (wndconfig->glRobustness == GLFW_OPENGL_LOSE_CONTEXT_ON_RESET) + strategy = GLX_LOSE_CONTEXT_ON_RESET_ARB; + + setGLXattrib(attribs, + index, + GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, + strategy); + } + + setGLXattrib(attribs, index, None, None); + + // This is the only place we set an Xlib error handler, and we only do + // it because glXCreateContextAttribsARB generates a BadMatch error if + // the requested OpenGL version is unavailable (instead of a civilized + // response like returning NULL) + XSetErrorHandler(errorHandler); + + window->GLX.context = + window->GLX.CreateContextAttribsARB(_glfwLibrary.X11.display, + *fbconfig, + share, + True, + attribs); + + // We are done, so unset the error handler again (see above) + XSetErrorHandler(NULL); + } + else + { + if (window->GLX.SGIX_fbconfig) + { + window->GLX.context = + window->GLX.CreateContextWithConfigSGIX(_glfwLibrary.X11.display, + *fbconfig, + GLX_RGBA_TYPE, + share, + True); + } + else + { + window->GLX.context = glXCreateNewContext(_glfwLibrary.X11.display, + *fbconfig, + GLX_RGBA_TYPE, + share, + True); + } + } + + XFree(fbconfig); + + if (window->GLX.context == NULL) + { + // TODO: Handle all the various error codes here + + _glfwSetError(GLFW_PLATFORM_ERROR, + "X11/GLX: Failed to create OpenGL context"); + return GL_FALSE; + } + + refreshContextParams(window, fbconfigID); + + return GL_TRUE; +} + +#undef setGLXattrib + + ////////////////////////////////////////////////////////////////////////// ////// GLFW internal API ////// ////////////////////////////////////////////////////////////////////////// +//======================================================================== +// Prepare for creation of the OpenGL context +//======================================================================== + +int _glfwCreateContext(_GLFWwindow* window, + const _GLFWwndconfig* wndconfig, + const _GLFWfbconfig* fbconfig) +{ + _GLFWfbconfig closest; + + initGLXExtensions(window); + + // Choose the best available fbconfig + { + unsigned int fbcount; + _GLFWfbconfig* fbconfigs; + const _GLFWfbconfig* result; + + fbconfigs = getFBConfigs(window, &fbcount); + if (!fbconfigs) + { + _glfwSetError(GLFW_PLATFORM_ERROR, + "X11/GLX: No usable GLXFBConfigs found"); + return GL_FALSE; + } + + result = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount); + if (!result) + { + _glfwSetError(GLFW_PLATFORM_ERROR, + "X11/GLX: No GLXFBConfig matched the criteria"); + + free(fbconfigs); + return GL_FALSE; + } + + closest = *result; + free(fbconfigs); + } + + return createContext(window, wndconfig, closest.platformID); +} + + +//======================================================================== +// Destroy the OpenGL context +//======================================================================== + +void _glfwDestroyContext(_GLFWwindow* window) +{ + if (window->GLX.context) + { + // Release and destroy the context + glXMakeCurrent(_glfwLibrary.X11.display, None, NULL); + glXDestroyContext(_glfwLibrary.X11.display, window->GLX.context); + window->GLX.context = NULL; + } +} + + //======================================================================== // Make the OpenGL context associated with the specified window current //======================================================================== diff --git a/src/x11_platform.h b/src/x11_platform.h index 013ca4e0..96fb64fa 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -113,7 +113,6 @@ typedef intptr_t GLFWintptr; //------------------------------------------------------------------------ typedef struct _GLFWcontextGLX { - GLXFBConfigID fbconfigID; // ID of selected GLXFBConfig GLXContext context; // OpenGL rendering context XVisualInfo* visual; // Visual for selected GLXFBConfig @@ -283,6 +282,12 @@ GLFWGLOBAL struct { // Time void _glfwInitTimer(void); +// OpenGL support +int _glfwCreateContext(_GLFWwindow* window, + const _GLFWwndconfig* wndconfig, + const _GLFWfbconfig* fbconfig); +void _glfwDestroyContext(_GLFWwindow* window); + // Fullscreen support int _glfwGetClosestVideoMode(int* width, int* height, int* rate); void _glfwSetVideoModeMODE(int mode, int rate); diff --git a/src/x11_window.c b/src/x11_window.c index ccd99a60..a5e7b0d8 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -43,17 +43,6 @@ #define Button6 6 #define Button7 7 -//======================================================================== -// Error handler for BadMatch errors when requesting context with -// unavailable OpenGL versions using the GLX_ARB_create_context extension -//======================================================================== - -static int errorHandler(Display *display, XErrorEvent* event) -{ - return 0; -} - - //======================================================================== // Checks whether the event is a MapNotify for the specified window //======================================================================== @@ -98,417 +87,6 @@ static int translateChar(XKeyEvent* event) } -//======================================================================== -// Returns the specified attribute of the specified GLXFBConfig -// NOTE: Do not call this unless we have found GLX 1.3+ or GLX_SGIX_fbconfig -//======================================================================== - -static int getFBConfigAttrib(_GLFWwindow* window, GLXFBConfig fbconfig, int attrib) -{ - int value; - - if (window->GLX.SGIX_fbconfig) - { - window->GLX.GetFBConfigAttribSGIX(_glfwLibrary.X11.display, - fbconfig, attrib, &value); - } - else - glXGetFBConfigAttrib(_glfwLibrary.X11.display, fbconfig, attrib, &value); - - return value; -} - - -//======================================================================== -// Return a list of available and usable framebuffer configs -//======================================================================== - -static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) -{ - GLXFBConfig* fbconfigs; - _GLFWfbconfig* result; - int i, count = 0; - - *found = 0; - - if (_glfwLibrary.GLX.majorVersion == 1 && _glfwLibrary.GLX.minorVersion < 3) - { - if (!window->GLX.SGIX_fbconfig) - { - _glfwSetError(GLFW_OPENGL_UNAVAILABLE, - "X11/GLX: GLXFBConfig support not found"); - return NULL; - } - } - - if (window->GLX.SGIX_fbconfig) - { - fbconfigs = window->GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display, - _glfwLibrary.X11.screen, - NULL, - &count); - if (!count) - { - _glfwSetError(GLFW_OPENGL_UNAVAILABLE, - "X11/GLX: No GLXFBConfigs returned"); - return NULL; - } - } - else - { - fbconfigs = glXGetFBConfigs(_glfwLibrary.X11.display, - _glfwLibrary.X11.screen, - &count); - if (!count) - { - _glfwSetError(GLFW_OPENGL_UNAVAILABLE, - "X11/GLX: No GLXFBConfigs returned"); - return NULL; - } - } - - result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count); - if (!result) - { - _glfwSetError(GLFW_OUT_OF_MEMORY, - "X11/GLX: Failed to allocate _GLFWfbconfig array"); - return NULL; - } - - for (i = 0; i < count; i++) - { - if (!getFBConfigAttrib(window, fbconfigs[i], GLX_DOUBLEBUFFER) || - !getFBConfigAttrib(window, fbconfigs[i], GLX_VISUAL_ID)) - { - // Only consider double-buffered GLXFBConfigs with associated visuals - continue; - } - - if (!(getFBConfigAttrib(window, - fbconfigs[i], - GLX_RENDER_TYPE) & GLX_RGBA_BIT)) - { - // Only consider RGBA GLXFBConfigs - continue; - } - - if (!(getFBConfigAttrib(window, fbconfigs[i], GLX_DRAWABLE_TYPE) & GLX_WINDOW_BIT)) - { - // Only consider window GLXFBConfigs - continue; - } - - result[*found].redBits = getFBConfigAttrib(window, fbconfigs[i], GLX_RED_SIZE); - result[*found].greenBits = getFBConfigAttrib(window, fbconfigs[i], GLX_GREEN_SIZE); - result[*found].blueBits = getFBConfigAttrib(window, fbconfigs[i], GLX_BLUE_SIZE); - - result[*found].alphaBits = getFBConfigAttrib(window, fbconfigs[i], GLX_ALPHA_SIZE); - result[*found].depthBits = getFBConfigAttrib(window, fbconfigs[i], GLX_DEPTH_SIZE); - result[*found].stencilBits = getFBConfigAttrib(window, fbconfigs[i], GLX_STENCIL_SIZE); - - result[*found].accumRedBits = getFBConfigAttrib(window, fbconfigs[i], GLX_ACCUM_RED_SIZE); - result[*found].accumGreenBits = getFBConfigAttrib(window, fbconfigs[i], GLX_ACCUM_GREEN_SIZE); - result[*found].accumBlueBits = getFBConfigAttrib(window, fbconfigs[i], GLX_ACCUM_BLUE_SIZE); - result[*found].accumAlphaBits = getFBConfigAttrib(window, fbconfigs[i], GLX_ACCUM_ALPHA_SIZE); - - result[*found].auxBuffers = getFBConfigAttrib(window, fbconfigs[i], GLX_AUX_BUFFERS); - result[*found].stereo = getFBConfigAttrib(window, fbconfigs[i], GLX_STEREO); - - if (window->GLX.ARB_multisample) - result[*found].samples = getFBConfigAttrib(window, fbconfigs[i], GLX_SAMPLES); - else - result[*found].samples = 0; - - result[*found].platformID = (GLFWintptr) getFBConfigAttrib(window, fbconfigs[i], GLX_FBCONFIG_ID); - - (*found)++; - } - - XFree(fbconfigs); - - return result; -} - - -//======================================================================== -// Create the OpenGL context -//======================================================================== - -#define setGLXattrib(attribs, index, attribName, attribValue) \ - attribs[index++] = attribName; \ - attribs[index++] = attribValue; - -static int createContext(_GLFWwindow* window, - const _GLFWwndconfig* wndconfig, - GLXFBConfigID fbconfigID) -{ - int attribs[40]; - int dummy, index; - GLXFBConfig* fbconfig; - GLXContext share = NULL; - - if (wndconfig->share) - share = wndconfig->share->GLX.context; - - // Retrieve the previously selected GLXFBConfig - { - index = 0; - - setGLXattrib(attribs, index, GLX_FBCONFIG_ID, (int) fbconfigID); - setGLXattrib(attribs, index, None, None); - - if (window->GLX.SGIX_fbconfig) - { - fbconfig = window->GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display, - _glfwLibrary.X11.screen, - attribs, - &dummy); - } - else - { - fbconfig = glXChooseFBConfig(_glfwLibrary.X11.display, - _glfwLibrary.X11.screen, - attribs, - &dummy); - } - - if (fbconfig == NULL) - { - _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/GLX: Failed to retrieve the selected GLXFBConfig"); - return GL_FALSE; - } - } - - // Retrieve the corresponding visual - if (window->GLX.SGIX_fbconfig) - { - window->GLX.visual = window->GLX.GetVisualFromFBConfigSGIX(_glfwLibrary.X11.display, - *fbconfig); - } - else - { - window->GLX.visual = glXGetVisualFromFBConfig(_glfwLibrary.X11.display, - *fbconfig); - } - - if (window->GLX.visual == NULL) - { - XFree(fbconfig); - - _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/GLX: Failed to retrieve visual for GLXFBConfig"); - return GL_FALSE; - } - - if (window->GLX.ARB_create_context) - { - index = 0; - - if (wndconfig->glMajor != 1 || wndconfig->glMinor != 0) - { - // Request an explicitly versioned context - - setGLXattrib(attribs, index, GLX_CONTEXT_MAJOR_VERSION_ARB, wndconfig->glMajor); - setGLXattrib(attribs, index, GLX_CONTEXT_MINOR_VERSION_ARB, wndconfig->glMinor); - } - - if (wndconfig->glForward || wndconfig->glDebug || wndconfig->glRobustness) - { - int flags = 0; - - if (wndconfig->glForward) - flags |= GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB; - - if (wndconfig->glDebug) - flags |= GLX_CONTEXT_DEBUG_BIT_ARB; - - if (wndconfig->glRobustness) - flags |= GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB; - - setGLXattrib(attribs, index, GLX_CONTEXT_FLAGS_ARB, flags); - } - - if (wndconfig->glProfile) - { - int flags = 0; - - if (!window->GLX.ARB_create_context_profile) - { - _glfwSetError(GLFW_VERSION_UNAVAILABLE, - "X11/GLX: An OpenGL profile requested but " - "GLX_ARB_create_context_profile is unavailable"); - return GL_FALSE; - } - - if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE && - !window->GLX.EXT_create_context_es2_profile) - { - _glfwSetError(GLFW_VERSION_UNAVAILABLE, - "X11/GLX: OpenGL ES 2.x profile requested but " - "GLX_EXT_create_context_es2_profile is unavailable"); - return GL_FALSE; - } - - if (wndconfig->glProfile == GLFW_OPENGL_CORE_PROFILE) - flags = GLX_CONTEXT_CORE_PROFILE_BIT_ARB; - else if (wndconfig->glProfile == GLFW_OPENGL_COMPAT_PROFILE) - flags = GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; - else if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE) - flags = GLX_CONTEXT_ES2_PROFILE_BIT_EXT; - - setGLXattrib(attribs, index, GLX_CONTEXT_PROFILE_MASK_ARB, flags); - } - - if (wndconfig->glRobustness) - { - int strategy; - - if (!window->GLX.ARB_create_context_robustness) - { - _glfwSetError(GLFW_VERSION_UNAVAILABLE, - "X11/GLX: An OpenGL robustness strategy was " - "requested but GLX_ARB_create_context_robustness " - "is unavailable"); - return GL_FALSE; - } - - if (wndconfig->glRobustness == GLFW_OPENGL_NO_RESET_NOTIFICATION) - strategy = GLX_NO_RESET_NOTIFICATION_ARB; - else if (wndconfig->glRobustness == GLFW_OPENGL_LOSE_CONTEXT_ON_RESET) - strategy = GLX_LOSE_CONTEXT_ON_RESET_ARB; - - setGLXattrib(attribs, - index, - GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, - strategy); - } - - setGLXattrib(attribs, index, None, None); - - // This is the only place we set an Xlib error handler, and we only do - // it because glXCreateContextAttribsARB generates a BadMatch error if - // the requested OpenGL version is unavailable (instead of a civilized - // response like returning NULL) - XSetErrorHandler(errorHandler); - - window->GLX.context = - window->GLX.CreateContextAttribsARB(_glfwLibrary.X11.display, - *fbconfig, - share, - True, - attribs); - - // We are done, so unset the error handler again (see above) - XSetErrorHandler(NULL); - } - else - { - if (window->GLX.SGIX_fbconfig) - { - window->GLX.context = - window->GLX.CreateContextWithConfigSGIX(_glfwLibrary.X11.display, - *fbconfig, - GLX_RGBA_TYPE, - share, - True); - } - else - { - window->GLX.context = glXCreateNewContext(_glfwLibrary.X11.display, - *fbconfig, - GLX_RGBA_TYPE, - share, - True); - } - } - - XFree(fbconfig); - - if (window->GLX.context == NULL) - { - // TODO: Handle all the various error codes here - - _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/GLX: Failed to create OpenGL context"); - return GL_FALSE; - } - - window->GLX.fbconfigID = fbconfigID; - - return GL_TRUE; -} - -#undef setGLXattrib - - -//======================================================================== -// Initialize GLX-specific extensions -//======================================================================== - -static void initGLXExtensions(_GLFWwindow* window) -{ - if (_glfwPlatformExtensionSupported("GLX_EXT_swap_control")) - { - window->GLX.SwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC) - _glfwPlatformGetProcAddress("glXSwapIntervalEXT"); - - if (window->GLX.SwapIntervalEXT) - window->GLX.EXT_swap_control = GL_TRUE; - } - - if (_glfwPlatformExtensionSupported("GLX_SGI_swap_control")) - { - window->GLX.SwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC) - _glfwPlatformGetProcAddress("glXSwapIntervalSGI"); - - if (window->GLX.SwapIntervalSGI) - window->GLX.SGI_swap_control = GL_TRUE; - } - - if (_glfwPlatformExtensionSupported("GLX_SGIX_fbconfig")) - { - window->GLX.GetFBConfigAttribSGIX = (PFNGLXGETFBCONFIGATTRIBSGIXPROC) - _glfwPlatformGetProcAddress("glXGetFBConfigAttribSGIX"); - window->GLX.ChooseFBConfigSGIX = (PFNGLXCHOOSEFBCONFIGSGIXPROC) - _glfwPlatformGetProcAddress("glXChooseFBConfigSGIX"); - window->GLX.CreateContextWithConfigSGIX = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC) - _glfwPlatformGetProcAddress("glXCreateContextWithConfigSGIX"); - window->GLX.GetVisualFromFBConfigSGIX = (PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) - _glfwPlatformGetProcAddress("glXGetVisualFromFBConfigSGIX"); - - if (window->GLX.GetFBConfigAttribSGIX && - window->GLX.ChooseFBConfigSGIX && - window->GLX.CreateContextWithConfigSGIX && - window->GLX.GetVisualFromFBConfigSGIX) - { - window->GLX.SGIX_fbconfig = GL_TRUE; - } - } - - if (_glfwPlatformExtensionSupported("GLX_ARB_multisample")) - window->GLX.ARB_multisample = GL_TRUE; - - if (_glfwPlatformExtensionSupported("GLX_ARB_create_context")) - { - window->GLX.CreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) - _glfwPlatformGetProcAddress("glXCreateContextAttribsARB"); - - if (window->GLX.CreateContextAttribsARB) - window->GLX.ARB_create_context = GL_TRUE; - } - - if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_robustness")) - window->GLX.ARB_create_context_robustness = GL_TRUE; - - if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_profile")) - window->GLX.ARB_create_context_profile = GL_TRUE; - - if (_glfwPlatformExtensionSupported("GLX_EXT_create_context_es2_profile")) - window->GLX.EXT_create_context_es2_profile = GL_TRUE; -} - - //======================================================================== // Create the X11 window (and its colormap) //======================================================================== @@ -1339,42 +917,10 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWfbconfig* fbconfig) { - _GLFWfbconfig closest; - window->refreshRate = wndconfig->refreshRate; window->resizable = wndconfig->resizable; - initGLXExtensions(window); - - // Choose the best available fbconfig - { - unsigned int fbcount; - _GLFWfbconfig* fbconfigs; - const _GLFWfbconfig* result; - - fbconfigs = getFBConfigs(window, &fbcount); - if (!fbconfigs) - { - _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/GLX: No usable GLXFBConfigs found"); - return GL_FALSE; - } - - result = _glfwChooseFBConfig(fbconfig, fbconfigs, fbcount); - if (!result) - { - _glfwSetError(GLFW_PLATFORM_ERROR, - "X11/GLX: No GLXFBConfig matched the criteria"); - - free(fbconfigs); - return GL_FALSE; - } - - closest = *result; - free(fbconfigs); - } - - if (!createContext(window, wndconfig, (GLXFBConfigID) closest.platformID)) + if (!_glfwCreateContext(window, wndconfig, fbconfig)) return GL_FALSE; if (!createWindow(window, wndconfig)) @@ -1431,13 +977,7 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window) if (window->mode == GLFW_FULLSCREEN) leaveFullscreenMode(window); - if (window->GLX.context) - { - // Release and destroy the context - glXMakeCurrent(_glfwLibrary.X11.display, None, NULL); - glXDestroyContext(_glfwLibrary.X11.display, window->GLX.context); - window->GLX.context = NULL; - } + _glfwDestroyContext(window); if (window->GLX.visual) { @@ -1604,8 +1144,6 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window) void _glfwPlatformRefreshWindowParams(void) { - int dummy; - GLXFBConfig* fbconfig; #if defined(_GLFW_HAS_XRANDR) XRRScreenConfiguration* sc; #endif /*_GLFW_HAS_XRANDR*/ @@ -1616,58 +1154,6 @@ void _glfwPlatformRefreshWindowParams(void) #endif /*_GLFW_HAS_XF86VIDMODE*/ _GLFWwindow* window = _glfwLibrary.currentWindow; - int attribs[] = { GLX_FBCONFIG_ID, window->GLX.fbconfigID, None }; - - if (window->GLX.SGIX_fbconfig) - { - fbconfig = window->GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display, - _glfwLibrary.X11.screen, - attribs, - &dummy); - } - else - { - fbconfig = glXChooseFBConfig(_glfwLibrary.X11.display, - _glfwLibrary.X11.screen, - attribs, - &dummy); - } - - if (fbconfig == NULL) - { - // This should never ever happen - // TODO: Flag this as an error and propagate up - fprintf(stderr, "Cannot find known GLXFBConfig by ID. " - "This cannot happen. Have a nice day.\n"); - abort(); - } - - // There is no clear definition of an "accelerated" context on X11/GLX, and - // true sounds better than false, so we hardcode true here - window->accelerated = GL_TRUE; - - window->redBits = getFBConfigAttrib(window, *fbconfig, GLX_RED_SIZE); - window->greenBits = getFBConfigAttrib(window, *fbconfig, GLX_GREEN_SIZE); - window->blueBits = getFBConfigAttrib(window, *fbconfig, GLX_BLUE_SIZE); - - window->alphaBits = getFBConfigAttrib(window, *fbconfig, GLX_ALPHA_SIZE); - window->depthBits = getFBConfigAttrib(window, *fbconfig, GLX_DEPTH_SIZE); - window->stencilBits = getFBConfigAttrib(window, *fbconfig, GLX_STENCIL_SIZE); - - window->accumRedBits = getFBConfigAttrib(window, *fbconfig, GLX_ACCUM_RED_SIZE); - window->accumGreenBits = getFBConfigAttrib(window, *fbconfig, GLX_ACCUM_GREEN_SIZE); - window->accumBlueBits = getFBConfigAttrib(window, *fbconfig, GLX_ACCUM_BLUE_SIZE); - window->accumAlphaBits = getFBConfigAttrib(window, *fbconfig, GLX_ACCUM_ALPHA_SIZE); - - window->auxBuffers = getFBConfigAttrib(window, *fbconfig, GLX_AUX_BUFFERS); - window->stereo = getFBConfigAttrib(window, *fbconfig, GLX_STEREO) ? GL_TRUE : GL_FALSE; - - // Get FSAA buffer sample count - if (window->GLX.ARB_multisample) - window->samples = getFBConfigAttrib(window, *fbconfig, GLX_SAMPLES); - else - window->samples = 0; - // Retrieve refresh rate if possible if (_glfwLibrary.X11.RandR.available) { @@ -1694,8 +1180,6 @@ void _glfwPlatformRefreshWindowParams(void) // Zero means unknown according to the GLFW spec window->refreshRate = 0; } - - XFree(fbconfig); } From 9614b9b22f458ab4449b3e9584cf8c73bab2884e Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 23 Apr 2012 13:00:49 +0200 Subject: [PATCH 182/226] Moved OpenGL init and terminate to opengl module. --- src/x11_init.c | 58 +++------------------------------------ src/x11_opengl.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++ src/x11_platform.h | 2 ++ 3 files changed, 74 insertions(+), 54 deletions(-) diff --git a/src/x11_init.c b/src/x11_init.c index d59fbcc6..6b2f473e 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -36,33 +36,6 @@ #include -//======================================================================== -// Dynamically load libraries -//======================================================================== - -static void initLibraries(void) -{ -#ifdef _GLFW_DLOPEN_LIBGL - int i; - char* libGL_names[ ] = - { - "libGL.so", - "libGL.so.1", - "/usr/lib/libGL.so", - "/usr/lib/libGL.so.1", - NULL - }; - - for (i = 0; libGL_names[i] != NULL; i++) - { - _glfwLibrary.GLX.libGL = dlopen(libGL_names[i], RTLD_LAZY | RTLD_GLOBAL); - if (_glfwLibrary.GLX.libGL) - break; - } -#endif -} - - //======================================================================== // Translate an X11 key code to a GLFW key code. //======================================================================== @@ -561,22 +534,6 @@ static GLboolean initDisplay(void) _glfwLibrary.X11.RandR.available = GL_FALSE; #endif /*_GLFW_HAS_XRANDR*/ - // Check if GLX is supported on this display - if (!glXQueryExtension(_glfwLibrary.X11.display, NULL, NULL)) - { - _glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11/GLX: GLX supported not found"); - return GL_FALSE; - } - - if (!glXQueryVersion(_glfwLibrary.X11.display, - &_glfwLibrary.GLX.majorVersion, - &_glfwLibrary.GLX.minorVersion)) - { - _glfwSetError(GLFW_OPENGL_UNAVAILABLE, - "X11/GLX: Failed to query GLX version"); - return GL_FALSE; - } - // Check if Xkb is supported on this display #if defined(_GLFW_HAS_XKB) _glfwLibrary.X11.Xkb.majorVersion = 1; @@ -739,15 +696,15 @@ int _glfwPlatformInit(void) if (!initDisplay()) return GL_FALSE; + if (!_glfwInitOpenGL()) + return GL_FALSE; + initGammaRamp(); initEWMH(); _glfwLibrary.X11.cursor = createNULLCursor(); - // Try to load libGL.so if necessary - initLibraries(); - _glfwInitJoysticks(); // Start the timer @@ -773,14 +730,7 @@ int _glfwPlatformTerminate(void) _glfwTerminateJoysticks(); - // Unload libGL.so if necessary -#ifdef _GLFW_DLOPEN_LIBGL - if (_glfwLibrary.GLX.libGL != NULL) - { - dlclose(_glfwLibrary.GLX.libGL); - _glfwLibrary.GLX.libGL = NULL; - } -#endif + _glfwTerminateOpenGL(); // Free clipboard memory if (_glfwLibrary.X11.selection.string) diff --git a/src/x11_opengl.c b/src/x11_opengl.c index 825cacc2..a09f00fd 100644 --- a/src/x11_opengl.c +++ b/src/x11_opengl.c @@ -529,6 +529,74 @@ static int createContext(_GLFWwindow* window, ////// GLFW internal API ////// ////////////////////////////////////////////////////////////////////////// +//======================================================================== +// Initialize GLX +//======================================================================== + +int _glfwInitOpenGL(void) +{ +#ifdef _GLFW_DLOPEN_LIBGL + int i; + char* libGL_names[ ] = + { + "libGL.so", + "libGL.so.1", + "/usr/lib/libGL.so", + "/usr/lib/libGL.so.1", + NULL + }; + + for (i = 0; libGL_names[i] != NULL; i++) + { + _glfwLibrary.GLX.libGL = dlopen(libGL_names[i], RTLD_LAZY | RTLD_GLOBAL); + if (_glfwLibrary.GLX.libGL) + break; + } + + if (!_glfwLibrary.GLX.libGL) + { + _glfwSetError(GLFW_PLATFORM_ERROR, "X11/GLX: Failed to find libGL"); + return GL_FALSE; + } +#endif + + // Check if GLX is supported on this display + if (!glXQueryExtension(_glfwLibrary.X11.display, NULL, NULL)) + { + _glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11/GLX: GLX supported not found"); + return GL_FALSE; + } + + if (!glXQueryVersion(_glfwLibrary.X11.display, + &_glfwLibrary.GLX.majorVersion, + &_glfwLibrary.GLX.minorVersion)) + { + _glfwSetError(GLFW_OPENGL_UNAVAILABLE, + "X11/GLX: Failed to query GLX version"); + return GL_FALSE; + } + + return GL_TRUE; +} + + +//======================================================================== +// Terminate GLX +//======================================================================== + +void _glfwTerminateOpenGL(void) +{ + // Unload libGL.so if necessary +#ifdef _GLFW_DLOPEN_LIBGL + if (_glfwLibrary.GLX.libGL != NULL) + { + dlclose(_glfwLibrary.GLX.libGL); + _glfwLibrary.GLX.libGL = NULL; + } +#endif +} + + //======================================================================== // Prepare for creation of the OpenGL context //======================================================================== diff --git a/src/x11_platform.h b/src/x11_platform.h index 96fb64fa..bf959f85 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -283,6 +283,8 @@ GLFWGLOBAL struct { void _glfwInitTimer(void); // OpenGL support +int _glfwInitOpenGL(void); +void _glfwTerminateOpenGL(void); int _glfwCreateContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWfbconfig* fbconfig); From f77c8f8b218edfe591b0370d61b69e581db4ddba Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 23 Apr 2012 13:08:34 +0200 Subject: [PATCH 183/226] Made GLX extension management global instead of per-window. --- src/x11_opengl.c | 218 +++++++++++++++++++++------------------------ src/x11_platform.h | 34 +++---- 2 files changed, 121 insertions(+), 131 deletions(-) diff --git a/src/x11_opengl.c b/src/x11_opengl.c index a09f00fd..5ec47ee5 100644 --- a/src/x11_opengl.c +++ b/src/x11_opengl.c @@ -37,73 +37,6 @@ void (*glXGetProcAddressEXT(const GLubyte* procName))(); -//======================================================================== -// Initialize GLX-specific extensions -//======================================================================== - -static void initGLXExtensions(_GLFWwindow* window) -{ - if (_glfwPlatformExtensionSupported("GLX_EXT_swap_control")) - { - window->GLX.SwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC) - _glfwPlatformGetProcAddress("glXSwapIntervalEXT"); - - if (window->GLX.SwapIntervalEXT) - window->GLX.EXT_swap_control = GL_TRUE; - } - - if (_glfwPlatformExtensionSupported("GLX_SGI_swap_control")) - { - window->GLX.SwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC) - _glfwPlatformGetProcAddress("glXSwapIntervalSGI"); - - if (window->GLX.SwapIntervalSGI) - window->GLX.SGI_swap_control = GL_TRUE; - } - - if (_glfwPlatformExtensionSupported("GLX_SGIX_fbconfig")) - { - window->GLX.GetFBConfigAttribSGIX = (PFNGLXGETFBCONFIGATTRIBSGIXPROC) - _glfwPlatformGetProcAddress("glXGetFBConfigAttribSGIX"); - window->GLX.ChooseFBConfigSGIX = (PFNGLXCHOOSEFBCONFIGSGIXPROC) - _glfwPlatformGetProcAddress("glXChooseFBConfigSGIX"); - window->GLX.CreateContextWithConfigSGIX = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC) - _glfwPlatformGetProcAddress("glXCreateContextWithConfigSGIX"); - window->GLX.GetVisualFromFBConfigSGIX = (PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) - _glfwPlatformGetProcAddress("glXGetVisualFromFBConfigSGIX"); - - if (window->GLX.GetFBConfigAttribSGIX && - window->GLX.ChooseFBConfigSGIX && - window->GLX.CreateContextWithConfigSGIX && - window->GLX.GetVisualFromFBConfigSGIX) - { - window->GLX.SGIX_fbconfig = GL_TRUE; - } - } - - if (_glfwPlatformExtensionSupported("GLX_ARB_multisample")) - window->GLX.ARB_multisample = GL_TRUE; - - if (_glfwPlatformExtensionSupported("GLX_ARB_create_context")) - { - window->GLX.CreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) - _glfwPlatformGetProcAddress("glXCreateContextAttribsARB"); - - if (window->GLX.CreateContextAttribsARB) - window->GLX.ARB_create_context = GL_TRUE; - } - - if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_robustness")) - window->GLX.ARB_create_context_robustness = GL_TRUE; - - if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_profile")) - window->GLX.ARB_create_context_profile = GL_TRUE; - - if (_glfwPlatformExtensionSupported("GLX_EXT_create_context_es2_profile")) - window->GLX.EXT_create_context_es2_profile = GL_TRUE; -} - - //======================================================================== // Returns the specified attribute of the specified GLXFBConfig // NOTE: Do not call this unless we have found GLX 1.3+ or GLX_SGIX_fbconfig @@ -113,10 +46,10 @@ static int getFBConfigAttrib(_GLFWwindow* window, GLXFBConfig fbconfig, int attr { int value; - if (window->GLX.SGIX_fbconfig) + if (_glfwLibrary.GLX.SGIX_fbconfig) { - window->GLX.GetFBConfigAttribSGIX(_glfwLibrary.X11.display, - fbconfig, attrib, &value); + _glfwLibrary.GLX.GetFBConfigAttribSGIX(_glfwLibrary.X11.display, + fbconfig, attrib, &value); } else glXGetFBConfigAttrib(_glfwLibrary.X11.display, fbconfig, attrib, &value); @@ -139,7 +72,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) if (_glfwLibrary.GLX.majorVersion == 1 && _glfwLibrary.GLX.minorVersion < 3) { - if (!window->GLX.SGIX_fbconfig) + if (!_glfwLibrary.GLX.SGIX_fbconfig) { _glfwSetError(GLFW_OPENGL_UNAVAILABLE, "X11/GLX: GLXFBConfig support not found"); @@ -147,12 +80,12 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) } } - if (window->GLX.SGIX_fbconfig) + if (_glfwLibrary.GLX.SGIX_fbconfig) { - fbconfigs = window->GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display, - _glfwLibrary.X11.screen, - NULL, - &count); + fbconfigs = _glfwLibrary.GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display, + _glfwLibrary.X11.screen, + NULL, + &count); if (!count) { _glfwSetError(GLFW_OPENGL_UNAVAILABLE, @@ -220,7 +153,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) result[*found].auxBuffers = getFBConfigAttrib(window, fbconfigs[i], GLX_AUX_BUFFERS); result[*found].stereo = getFBConfigAttrib(window, fbconfigs[i], GLX_STEREO); - if (window->GLX.ARB_multisample) + if (_glfwLibrary.GLX.ARB_multisample) result[*found].samples = getFBConfigAttrib(window, fbconfigs[i], GLX_SAMPLES); else result[*found].samples = 0; @@ -258,12 +191,12 @@ static void refreshContextParams(_GLFWwindow* window, GLXFBConfigID fbconfigID) int attribs[] = { GLX_FBCONFIG_ID, fbconfigID, None }; - if (window->GLX.SGIX_fbconfig) + if (_glfwLibrary.GLX.SGIX_fbconfig) { - fbconfig = window->GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display, - _glfwLibrary.X11.screen, - attribs, - &dummy); + fbconfig = _glfwLibrary.GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display, + _glfwLibrary.X11.screen, + attribs, + &dummy); } else { @@ -304,7 +237,7 @@ static void refreshContextParams(_GLFWwindow* window, GLXFBConfigID fbconfigID) window->stereo = getFBConfigAttrib(window, *fbconfig, GLX_STEREO) ? GL_TRUE : GL_FALSE; // Get FSAA buffer sample count - if (window->GLX.ARB_multisample) + if (_glfwLibrary.GLX.ARB_multisample) window->samples = getFBConfigAttrib(window, *fbconfig, GLX_SAMPLES); else window->samples = 0; @@ -340,12 +273,12 @@ static int createContext(_GLFWwindow* window, setGLXattrib(attribs, index, GLX_FBCONFIG_ID, (int) fbconfigID); setGLXattrib(attribs, index, None, None); - if (window->GLX.SGIX_fbconfig) + if (_glfwLibrary.GLX.SGIX_fbconfig) { - fbconfig = window->GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display, - _glfwLibrary.X11.screen, - attribs, - &dummy); + fbconfig = _glfwLibrary.GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display, + _glfwLibrary.X11.screen, + attribs, + &dummy); } else { @@ -364,10 +297,10 @@ static int createContext(_GLFWwindow* window, } // Retrieve the corresponding visual - if (window->GLX.SGIX_fbconfig) + if (_glfwLibrary.GLX.SGIX_fbconfig) { - window->GLX.visual = window->GLX.GetVisualFromFBConfigSGIX(_glfwLibrary.X11.display, - *fbconfig); + window->GLX.visual = _glfwLibrary.GLX.GetVisualFromFBConfigSGIX(_glfwLibrary.X11.display, + *fbconfig); } else { @@ -384,7 +317,7 @@ static int createContext(_GLFWwindow* window, return GL_FALSE; } - if (window->GLX.ARB_create_context) + if (_glfwLibrary.GLX.ARB_create_context) { index = 0; @@ -416,7 +349,7 @@ static int createContext(_GLFWwindow* window, { int flags = 0; - if (!window->GLX.ARB_create_context_profile) + if (!_glfwLibrary.GLX.ARB_create_context_profile) { _glfwSetError(GLFW_VERSION_UNAVAILABLE, "X11/GLX: An OpenGL profile requested but " @@ -425,7 +358,7 @@ static int createContext(_GLFWwindow* window, } if (wndconfig->glProfile == GLFW_OPENGL_ES2_PROFILE && - !window->GLX.EXT_create_context_es2_profile) + !_glfwLibrary.GLX.EXT_create_context_es2_profile) { _glfwSetError(GLFW_VERSION_UNAVAILABLE, "X11/GLX: OpenGL ES 2.x profile requested but " @@ -447,7 +380,7 @@ static int createContext(_GLFWwindow* window, { int strategy; - if (!window->GLX.ARB_create_context_robustness) + if (!_glfwLibrary.GLX.ARB_create_context_robustness) { _glfwSetError(GLFW_VERSION_UNAVAILABLE, "X11/GLX: An OpenGL robustness strategy was " @@ -476,25 +409,25 @@ static int createContext(_GLFWwindow* window, XSetErrorHandler(errorHandler); window->GLX.context = - window->GLX.CreateContextAttribsARB(_glfwLibrary.X11.display, - *fbconfig, - share, - True, - attribs); + _glfwLibrary.GLX.CreateContextAttribsARB(_glfwLibrary.X11.display, + *fbconfig, + share, + True, + attribs); // We are done, so unset the error handler again (see above) XSetErrorHandler(NULL); } else { - if (window->GLX.SGIX_fbconfig) + if (_glfwLibrary.GLX.SGIX_fbconfig) { window->GLX.context = - window->GLX.CreateContextWithConfigSGIX(_glfwLibrary.X11.display, - *fbconfig, - GLX_RGBA_TYPE, - share, - True); + _glfwLibrary.GLX.CreateContextWithConfigSGIX(_glfwLibrary.X11.display, + *fbconfig, + GLX_RGBA_TYPE, + share, + True); } else { @@ -576,6 +509,65 @@ int _glfwInitOpenGL(void) return GL_FALSE; } + if (_glfwPlatformExtensionSupported("GLX_EXT_swap_control")) + { + _glfwLibrary.GLX.SwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC) + _glfwPlatformGetProcAddress("glXSwapIntervalEXT"); + + if (_glfwLibrary.GLX.SwapIntervalEXT) + _glfwLibrary.GLX.EXT_swap_control = GL_TRUE; + } + + if (_glfwPlatformExtensionSupported("GLX_SGI_swap_control")) + { + _glfwLibrary.GLX.SwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC) + _glfwPlatformGetProcAddress("glXSwapIntervalSGI"); + + if (_glfwLibrary.GLX.SwapIntervalSGI) + _glfwLibrary.GLX.SGI_swap_control = GL_TRUE; + } + + if (_glfwPlatformExtensionSupported("GLX_SGIX_fbconfig")) + { + _glfwLibrary.GLX.GetFBConfigAttribSGIX = (PFNGLXGETFBCONFIGATTRIBSGIXPROC) + _glfwPlatformGetProcAddress("glXGetFBConfigAttribSGIX"); + _glfwLibrary.GLX.ChooseFBConfigSGIX = (PFNGLXCHOOSEFBCONFIGSGIXPROC) + _glfwPlatformGetProcAddress("glXChooseFBConfigSGIX"); + _glfwLibrary.GLX.CreateContextWithConfigSGIX = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC) + _glfwPlatformGetProcAddress("glXCreateContextWithConfigSGIX"); + _glfwLibrary.GLX.GetVisualFromFBConfigSGIX = (PFNGLXGETVISUALFROMFBCONFIGSGIXPROC) + _glfwPlatformGetProcAddress("glXGetVisualFromFBConfigSGIX"); + + if (_glfwLibrary.GLX.GetFBConfigAttribSGIX && + _glfwLibrary.GLX.ChooseFBConfigSGIX && + _glfwLibrary.GLX.CreateContextWithConfigSGIX && + _glfwLibrary.GLX.GetVisualFromFBConfigSGIX) + { + _glfwLibrary.GLX.SGIX_fbconfig = GL_TRUE; + } + } + + if (_glfwPlatformExtensionSupported("GLX_ARB_multisample")) + _glfwLibrary.GLX.ARB_multisample = GL_TRUE; + + if (_glfwPlatformExtensionSupported("GLX_ARB_create_context")) + { + _glfwLibrary.GLX.CreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC) + _glfwPlatformGetProcAddress("glXCreateContextAttribsARB"); + + if (_glfwLibrary.GLX.CreateContextAttribsARB) + _glfwLibrary.GLX.ARB_create_context = GL_TRUE; + } + + if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_robustness")) + _glfwLibrary.GLX.ARB_create_context_robustness = GL_TRUE; + + if (_glfwPlatformExtensionSupported("GLX_ARB_create_context_profile")) + _glfwLibrary.GLX.ARB_create_context_profile = GL_TRUE; + + if (_glfwPlatformExtensionSupported("GLX_EXT_create_context_es2_profile")) + _glfwLibrary.GLX.EXT_create_context_es2_profile = GL_TRUE; + return GL_TRUE; } @@ -607,8 +599,6 @@ int _glfwCreateContext(_GLFWwindow* window, { _GLFWfbconfig closest; - initGLXExtensions(window); - // Choose the best available fbconfig { unsigned int fbcount; @@ -693,14 +683,14 @@ void _glfwPlatformSwapInterval(int interval) { _GLFWwindow* window = _glfwLibrary.currentWindow; - if (window->GLX.EXT_swap_control) + if (_glfwLibrary.GLX.EXT_swap_control) { - window->GLX.SwapIntervalEXT(_glfwLibrary.X11.display, - window->X11.handle, - interval); + _glfwLibrary.GLX.SwapIntervalEXT(_glfwLibrary.X11.display, + window->X11.handle, + interval); } - else if (window->GLX.SGI_swap_control) - window->GLX.SwapIntervalSGI(interval); + else if (_glfwLibrary.GLX.SGI_swap_control) + _glfwLibrary.GLX.SwapIntervalSGI(interval); } diff --git a/src/x11_platform.h b/src/x11_platform.h index bf959f85..d45ad9a3 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -116,23 +116,6 @@ typedef struct _GLFWcontextGLX GLXContext context; // OpenGL rendering context XVisualInfo* visual; // Visual for selected GLXFBConfig - // GLX extensions - PFNGLXSWAPINTERVALSGIPROC SwapIntervalSGI; - PFNGLXSWAPINTERVALEXTPROC SwapIntervalEXT; - PFNGLXGETFBCONFIGATTRIBSGIXPROC GetFBConfigAttribSGIX; - PFNGLXCHOOSEFBCONFIGSGIXPROC ChooseFBConfigSGIX; - PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC CreateContextWithConfigSGIX; - PFNGLXGETVISUALFROMFBCONFIGSGIXPROC GetVisualFromFBConfigSGIX; - PFNGLXCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB; - GLboolean SGIX_fbconfig; - GLboolean SGI_swap_control; - GLboolean EXT_swap_control; - GLboolean ARB_multisample; - GLboolean ARB_create_context; - GLboolean ARB_create_context_profile; - GLboolean ARB_create_context_robustness; - GLboolean EXT_create_context_es2_profile; - } _GLFWcontextGLX; @@ -256,6 +239,23 @@ typedef struct _GLFWlibraryGLX // Server-side GLX version int majorVersion, minorVersion; + // GLX extensions + PFNGLXSWAPINTERVALSGIPROC SwapIntervalSGI; + PFNGLXSWAPINTERVALEXTPROC SwapIntervalEXT; + PFNGLXGETFBCONFIGATTRIBSGIXPROC GetFBConfigAttribSGIX; + PFNGLXCHOOSEFBCONFIGSGIXPROC ChooseFBConfigSGIX; + PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC CreateContextWithConfigSGIX; + PFNGLXGETVISUALFROMFBCONFIGSGIXPROC GetVisualFromFBConfigSGIX; + PFNGLXCREATECONTEXTATTRIBSARBPROC CreateContextAttribsARB; + GLboolean SGIX_fbconfig; + GLboolean SGI_swap_control; + GLboolean EXT_swap_control; + GLboolean ARB_multisample; + GLboolean ARB_create_context; + GLboolean ARB_create_context_profile; + GLboolean ARB_create_context_robustness; + GLboolean EXT_create_context_es2_profile; + #if defined(_GLFW_DLOPEN_LIBGL) void* libGL; // dlopen handle for libGL.so #endif From a22fbf7e9b0561e07ce6abdb1c345a3e30a1fa1d Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 23 Apr 2012 22:31:55 +0200 Subject: [PATCH 184/226] Moved remaining X visual management into opengl module. --- src/x11_opengl.c | 16 ++++++++++++++++ src/x11_platform.h | 1 + src/x11_window.c | 13 ++++--------- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/x11_opengl.c b/src/x11_opengl.c index 5ec47ee5..35dc6d0f 100644 --- a/src/x11_opengl.c +++ b/src/x11_opengl.c @@ -637,6 +637,12 @@ int _glfwCreateContext(_GLFWwindow* window, void _glfwDestroyContext(_GLFWwindow* window) { + if (window->GLX.visual) + { + XFree(window->GLX.visual); + window->GLX.visual = NULL; + } + if (window->GLX.context) { // Release and destroy the context @@ -647,6 +653,16 @@ void _glfwDestroyContext(_GLFWwindow* window) } +//======================================================================== +// Return the X visual associated with the specified context +//======================================================================== + +XVisualInfo* _glfwGetContextVisual(_GLFWwindow* window) +{ + return window->GLX.visual; +} + + //======================================================================== // Make the OpenGL context associated with the specified window current //======================================================================== diff --git a/src/x11_platform.h b/src/x11_platform.h index d45ad9a3..4d432f80 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -289,6 +289,7 @@ int _glfwCreateContext(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWfbconfig* fbconfig); void _glfwDestroyContext(_GLFWwindow* window); +XVisualInfo* _glfwGetContextVisual(_GLFWwindow* window); // Fullscreen support int _glfwGetClosestVideoMode(int* width, int* height, int* rate); diff --git a/src/x11_window.c b/src/x11_window.c index a5e7b0d8..9ec54493 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -97,13 +97,14 @@ static GLboolean createWindow(_GLFWwindow* window, XEvent event; unsigned long wamask; XSetWindowAttributes wa; + XVisualInfo* visual = _glfwGetContextVisual(window); // Every window needs a colormap // Create one based on the visual used by the current context window->X11.colormap = XCreateColormap(_glfwLibrary.X11.display, _glfwLibrary.X11.root, - window->GLX.visual->visual, + visual->visual, AllocNone); // Create the actual window @@ -133,9 +134,9 @@ static GLboolean createWindow(_GLFWwindow* window, 0, 0, // Upper left corner of this window on root window->width, window->height, 0, // Border width - window->GLX.visual->depth, // Color depth + visual->depth, // Color depth InputOutput, - window->GLX.visual->visual, + visual->visual, wamask, &wa ); @@ -979,12 +980,6 @@ void _glfwPlatformCloseWindow(_GLFWwindow* window) _glfwDestroyContext(window); - if (window->GLX.visual) - { - XFree(window->GLX.visual); - window->GLX.visual = NULL; - } - if (window->X11.handle) { XUnmapWindow(_glfwLibrary.X11.display, window->X11.handle); From d0c298de6e09fe83b7eeaeb6fd475d60c0b89136 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 3 May 2012 13:00:54 +0200 Subject: [PATCH 185/226] Removed legacy documentation. --- docs/Makefile | 57 -- docs/cleanup.bat | 22 - docs/glfwdoc.sty | 81 -- docs/glfwrm.tex | 2364 ---------------------------------------------- docs/glfwug.tex | 1313 ------------------------- docs/readme.txt | 52 - 6 files changed, 3889 deletions(-) delete mode 100644 docs/Makefile delete mode 100644 docs/cleanup.bat delete mode 100644 docs/glfwdoc.sty delete mode 100644 docs/glfwrm.tex delete mode 100644 docs/glfwug.tex delete mode 100644 docs/readme.txt diff --git a/docs/Makefile b/docs/Makefile deleted file mode 100644 index 6bc7da29..00000000 --- a/docs/Makefile +++ /dev/null @@ -1,57 +0,0 @@ -########################################################################## -# Makefile for the GLFW documentation. -########################################################################## - -PDFDOCS = glfwrm.pdf glfwug.pdf -DVIDOCS = glfwrm.dvi glfwug.dvi - - -########################################################################## -# Build macros -########################################################################## -default: pdf -pdf: $(PDFDOCS) -dvi: $(DVIDOCS) - - -########################################################################## -# Clean macros -########################################################################## -clean: - rm -f glfwrm.dvi glfwrm.aux glfwrm.log glfwrm.out glfwrm.pdf glfwrm.toc glfwrm.lot - rm -f glfwug.dvi glfwug.aux glfwug.log glfwug.out glfwug.pdf glfwug.toc - -clean-win: - @.\\cleanup.bat - - -########################################################################## -# Rules for building the GLFW Reference Manual -########################################################################## - -glfwrm.pdf: glfwrm.tex glfwrm.toc glfwrm.lot glfwdoc.sty - pdflatex glfwrm.tex - -glfwrm.dvi: glfwrm.tex glfwrm.toc glfwrm.lot glfwdoc.sty - latex glfwrm.tex - -glfwrm.toc: glfwrm.tex glfwdoc.sty - latex glfwrm.tex - -glfwrm.lot: glfwrm.tex glfwdoc.sty - latex glfwrm.tex - - -########################################################################## -# Rules for building the GLFW Users Guide -########################################################################## - -glfwug.pdf: glfwug.tex glfwug.toc glfwdoc.sty - pdflatex glfwug.tex - -glfwug.dvi: glfwug.tex glfwug.toc glfwdoc.sty - latex glfwug.tex - -glfwug.toc: glfwug.tex glfwdoc.sty - latex glfwug.tex - diff --git a/docs/cleanup.bat b/docs/cleanup.bat deleted file mode 100644 index 268a27b6..00000000 --- a/docs/cleanup.bat +++ /dev/null @@ -1,22 +0,0 @@ -@echo off - -REM ---------------------------------------------------------------------- -REM Windows cleanup batch file for the GLFW documentation. -REM ---------------------------------------------------------------------- - -REM GLFW Reference Manual -if exist glfwrm.dvi del glfwrm.dvi -if exist glfwrm.aux del glfwrm.aux -if exist glfwrm.log del glfwrm.log -if exist glfwrm.out del glfwrm.out -if exist glfwrm.pdf del glfwrm.pdf -if exist glfwrm.toc del glfwrm.toc -if exist glfwrm.lot del glfwrm.lot - -REM GLFW Users Guide -if exist glfwug.dvi del glfwug.dvi -if exist glfwug.aux del glfwug.aux -if exist glfwug.log del glfwug.log -if exist glfwug.out del glfwug.out -if exist glfwug.pdf del glfwug.pdf -if exist glfwug.toc del glfwug.toc diff --git a/docs/glfwdoc.sty b/docs/glfwdoc.sty deleted file mode 100644 index e415570e..00000000 --- a/docs/glfwdoc.sty +++ /dev/null @@ -1,81 +0,0 @@ -%------------------------------------------------------------------------- -% Common document formatting and macros for GLFW manuals -%------------------------------------------------------------------------- - -% Misc. document info -\date{\today} - -% Packages -\usepackage{fancyhdr} -\usepackage{titling} -\usepackage{lastpage} -\usepackage{listings} -\usepackage{color} -\usepackage[overload]{textcase} -\usepackage{needspace} -\usepackage{times} - -% Logo macros -\newcommand{\OpenGL}[1][0]{OpenGL\textsuperscript{\textregistered}} -\newcommand{\GLFW}[1][0]{GLFW} - -% Encoding -\usepackage[latin1]{inputenc} -\usepackage[T1]{fontenc} - -% Page formatting -\usepackage[hmargin=2.5cm]{geometry} -\raggedright -\raggedbottom -\sloppy -\usepackage{parskip} - -% Header and footer -\pagestyle{fancy} -%\lhead{\textit{GLFW Reference Manual}} -\lhead{\textit{GLFW \glfwdoctype}} -\chead{API version \glfwapiver} -\rhead{Page \thepage/\pageref{LastPage}} -\lfoot{} -\cfoot{} -\rfoot{} -\renewcommand{\headrulewidth}{0.4pt} -\renewcommand{\footrulewidth}{0.0pt} - -% Titlepage -\newcommand{\glfwmaketitle}{\begin{titlepage}\ \\% - \begin{center}% - \vspace{7.0cm}{\Huge\textbf{GLFW}}\\% - \rule{10.0cm}{0.5pt}\\% - \vspace{0.5cm}{\LARGE\textbf{\glfwdoctype}}\\% - \vspace{0.8cm}{\large\textbf{API version \glfwapiver}}\\% - \textit{\today}\\% - \vspace{1.5cm}\textbf{\textcopyright2002-2006 Marcus Geelnard}\\ - \textbf{\textcopyright2006-2010 Camilla Berglund}\\% - \end{center}\end{titlepage}\newpage} - -% Colors -\definecolor{code}{rgb}{0.9,0.9,1.0} -\definecolor{link}{rgb}{0.6,0.0,0.0} -\definecolor{codeA}{rgb}{0.9,1.0,0.9} -\definecolor{codeB}{rgb}{1.0,0.9,0.9} - -% Code listings -\lstset{frame=single,frameround=tttt,backgroundcolor=\color{code},% - language=C,basicstyle={\ttfamily},% - breaklines,breakindent=0pt,postbreak=\space\space\space\space} - - -% A simple hack for keeping lines together -\newenvironment{mysamepage}[1][2]{\begin{samepage}\needspace{#1\baselineskip}}{\end{samepage}} - -% Macros for automating function reference entries -\newenvironment{refparameters}[1][0]{\begin{mysamepage}\textbf{Parameters}\\}{\end{mysamepage}\bigskip} -\newenvironment{refreturn}[1][0]{\begin{mysamepage}\textbf{Return values}\\}{\end{mysamepage}\bigskip} -\newenvironment{refdescription}[1][0]{\begin{mysamepage}\textbf{Description}\\}{\end{mysamepage}\bigskip} -\newenvironment{refnotes}[1][0]{\begin{mysamepage}\textbf{Notes}\\}{\end{mysamepage}\bigskip} - -% hyperref (bookmarks, links etc) - use this package last -\usepackage[colorlinks=true,linkcolor=link,bookmarks=true,bookmarksopen=true,% - pdfhighlight=/N,bookmarksnumbered=true,bookmarksopenlevel=1,% - pdfview=FitH,pdfstartview=FitH]{hyperref} diff --git a/docs/glfwrm.tex b/docs/glfwrm.tex deleted file mode 100644 index 48c80b42..00000000 --- a/docs/glfwrm.tex +++ /dev/null @@ -1,2364 +0,0 @@ -%------------------------------------------------------------------------- -% GLFW Reference Manual -% API Version: 3.0 -%------------------------------------------------------------------------- - -% Document class -\documentclass[a4paper,11pt,oneside]{report} - -% Document title and API version -\newcommand{\glfwdoctype}[1][0]{Reference Manual} -\newcommand{\glfwapiver}[1][0]{3.0} - -% Common document settings and macros -\input{glfwdoc.sty} - -% PDF specific document settings -\hypersetup{pdftitle={GLFW Reference Manual}} -\hypersetup{pdfauthor={Camilla Berglund}} -\hypersetup{pdfkeywords={GLFW,OpenGL,reference,manual}} - - -%------------------------------------------------------------------------- -% Document body -%------------------------------------------------------------------------- - -\begin{document} - -\pagestyle{plain} - -% Title page -\glfwmaketitle - -% Summary, trademarks and table of contents -\pagenumbering{roman} -\setcounter{page}{1} - -%------------------------------------------------------------------------- -% Summary and Trademarks -%------------------------------------------------------------------------- -\chapter*{Summary} - -This document is primarily a function reference manual for the \GLFW\ API. -For a description of how to use \GLFW\ you should refer to the -\textit{GLFW Users Guide}. -\vspace{5cm} - -\large -Trademarks - -\small -OpenGL and IRIX are registered trademarks of Silicon Graphics, Inc.\linebreak -Microsoft and Windows are registered trademarks of Microsoft Corporation.\linebreak -Mac OS is a registered trademark of Apple Computer, Inc.\linebreak -Linux is a registered trademark of Linus Torvalds.\linebreak -FreeBSD is a registered trademark of Wind River Systems, Inc.\linebreak -Solaris is a trademark of Sun Microsystems, Inc.\linebreak -UNIX is a registered trademark of The Open Group.\linebreak -X Window System is a trademark of The Open Group.\linebreak -POSIX is a trademark of IEEE.\linebreak -Truevision, TARGA and TGA are registered trademarks of Truevision, Inc.\linebreak - -All other trademarks mentioned in this document are the property of their respective owners. -\normalsize - - -%------------------------------------------------------------------------- -% Table of contents -%------------------------------------------------------------------------- -\tableofcontents - -%------------------------------------------------------------------------- -% List of tables -%------------------------------------------------------------------------- -\listoftables -\pagebreak - - -% Document chapters starts here... -\pagenumbering{arabic} -\setcounter{page}{1} - -\pagestyle{fancy} - - -%------------------------------------------------------------------------- -% Introduction -%------------------------------------------------------------------------- -\chapter{Introduction} -\thispagestyle{fancy} - -\GLFW\ is a portable API (Application Program Interface) that handles -operating system specific tasks related to \OpenGL\ programming. While -\OpenGL\ in general is portable, easy to use and often results in tidy and -compact code, the operating system specific mechanisms that are required -to set up and manage an \OpenGL\ window are quite the opposite. \GLFW\ tries -to remedy this by providing the following functionality: - -\begin{itemize} -\item Opening and managing an \OpenGL\ context and its associated window. -\item Keyboard, mouse and joystick input. -\item A high precision timer. -\item Support for querying and using \OpenGL\ extensions. -\end{itemize} - -All this functionality is implemented as a set of easy-to-use functions, -which makes it possible to write an \OpenGL\ application framework in just a -few lines of code. The \GLFW\ API looks and behaves the same on all supported -platforms, making it very simple to port \GLFW\ based \OpenGL\ applications to -a variety of platforms. - -Currently supported platforms are: -\begin{itemize} -\item Microsoft Windows\textsuperscript{\textregistered} (32-bit only). -\item Unix\textsuperscript{\textregistered} or Unix­-like systems running -resonably a modern version of the X Window -System\texttrademark\footnote{X11.app on Mac OS X is not supported due to its -incomplete implementation of GLXFBConfigs} e.g. -Linux\textsuperscript{\textregistered}, -FreeBSD\textsuperscript{\textregistered} and Solaris\texttrademark (32- and -64-bit). -\item Mac OS\textsuperscript{\textregistered} X, using Cocoa\footnote{Joystick -input is not yet supported on Mac OS X.} (32- and 64-bit). -\end{itemize} - - - -%------------------------------------------------------------------------- -% GLFW Operation -%------------------------------------------------------------------------- -\chapter{GLFW Operation Overview} -\thispagestyle{fancy} - - -%------------------------------------------------------------------------- -\section{The GLFW Window} -\GLFW\ only supports having one window open at a time. The window can be either -a normal desktop window or a fullscreen window. The latter is completely -undecorated, without window borders, and covers the entire monitor. With a -fullscreen window, it is also possible to select which video mode to use. - -When a window is opened, an \OpenGL\ rendering context is created and -attached to the entire client area of the window. When the window is closed, -the \OpenGL\ rendering context is detached and destroyed. - -Through a window it is possible to receive user input in the form of -keyboard and mouse input. User input is exposed through the \GLFW\ API -primarily via a set of callback functions. Also, \GLFW\ stores most user input -as internal state that can be queried through different \GLFW\ API functions -(for instance it is possible to query the position of the mouse cursor with the -\textbf{glfwGetMousePos} function). - -As for user input, it is possible to receive information about window -state changes, such as window resize or close events, through callback -functions. It is also possible to query some kinds of information about the -window information using \GLFW\ API functions. - - -%------------------------------------------------------------------------- -\section{The GLFW Event Loop} -The \GLFW\ event loop is an open loop, which means that it is up to the -programmer to design the loop. Events are processed by calling specific -\GLFW\ functions, which in turn query the system for new input and window -events and reports these events back to the program through callback -functions. - -The programmer decides when to call the event processing functions and -when to abort the event loop. - -In pseudo language, a typical event loop might look like this: - -\begin{lstlisting} - repeat until window is closed - { - poll events - draw OpenGL graphics - } -\end{lstlisting} - -There are two ways to handle events in \GLFW : - -\begin{itemize} - \item Block the event loop while waiting for new events. - \item Poll for new events and continue the loop regardless of whether there - are any new events or not. -\end{itemize} - -The first method is useful for interactive applications that do not -need to refresh the \OpenGL\ display unless the user interacts with the -application through user input. Typical applications are CAD software -and other kinds of editors. - -The second method is useful for applications that need to refresh the -\OpenGL\ display constantly, regardless of user input, such as games, -demos, 3D animations, screen savers and so on. - - -%------------------------------------------------------------------------- -\section{Callback Functions} -Using callback functions can be a good method for receiving up to date -information about window state and user input. When a window has been -opened, it is possible to register custom callback functions that will -be called when certain events occur. - -Callback functions are called from any of the event polling functions -\textbf{glfwPollEvents}, \textbf{glfwWaitEvents} or -\textbf{glfwSwapBuffers}. - -Callback functions should \emph{only} be used to gather information. Since -the callback functions are called from within the internal \GLFW\ event -polling loops, they should not call any \GLFW\ functions that might -result in considerable \GLFW\ state changes, nor stall the event polling -loop for a lengthy period of time. - -In other words, most or all \OpenGL\ rendering should be called from the -main application event loop, not from any of the \GLFW\ callback -functions. Also, the only \GLFW\ functions that may be safely called from -callback functions are the different Get functions (e.g. -\textbf{glfwGetKey}, \textbf{glfwGetTime}, \textbf{glfwGetWindowParam} -etc.). - - -%------------------------------------------------------------------------- -% Function Reference -%------------------------------------------------------------------------- -\chapter{Function Reference} -\thispagestyle{fancy} - -%------------------------------------------------------------------------- -\section{GLFW Initialization and Termination} -Before any other \GLFW\ functions can be used, \GLFW\ must be initialized to -ensure proper functionality, and before a program terminates \GLFW\ should be -terminated in order to free allocated resources, memory, etc. - - -%------------------------------------------------------------------------- -\subsection{glfwInit} - -\textbf{C language syntax} -\begin{lstlisting} -int glfwInit(void) -\end{lstlisting} - -\begin{refparameters} -none -\end{refparameters} - -\begin{refreturn} -If the function succeeds, GL\_TRUE is returned.\\ -If the function fails, GL\_FALSE is returned. -\end{refreturn} - -\begin{refdescription} -The glfwInit function initializes \GLFW. No other \GLFW\ functions may be -called before this function has succeeded. -\end{refdescription} - -\begin{refnotes} -This function may take several seconds to complete on some systems, while -on other systems it may take only a fraction of a second to complete. - -This function registers a function calling \textbf{glfwTerminate} with the -atexit facility of the C library. - -On Mac OS X, this function will change the current directory of the application -to the \textbf{Contents/Resources} subdirectory of the application's bundle, if -present. For more information on bundles, see the Bundle Programming Guide -provided by Apple. -\end{refnotes} - - -%------------------------------------------------------------------------- -\subsection{glfwTerminate} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwTerminate(void) -\end{lstlisting} - -\begin{refparameters} -none -\end{refparameters} - -\begin{refreturn} -none -\end{refreturn} - -\begin{refdescription} -This function terminates \GLFW. Among other things it closes the window, if -open. This function should be called before a program exits. -\end{refdescription} - - -%------------------------------------------------------------------------- -\subsection{glfwGetVersion} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwGetVersion(int* major, int* minor, int* rev) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{major}]\ \\ - Pointer to an integer that will hold the major version number. -\item [\textit{minor}]\ \\ - Pointer to an integer that will hold the minor version number. -\item [\textit{rev}]\ \\ - Pointer to an integer that will hold the revision. -\end{description} -\end{refparameters} - -\begin{refreturn} -The function returns the major and minor version numbers and the revision -for the currently linked \GLFW\ library. -\end{refreturn} - -\begin{refdescription} -This function returns the \GLFW\ library version. -\end{refdescription} - - -%------------------------------------------------------------------------- -\pagebreak -\section{Window Handling} -The primary purpose of \GLFW\ is to provide a simple interface to -\OpenGL\ context creation and window management. \GLFW\ supports one window at -a time, which can be either a normal desktop window or a fullscreen window. - - -%------------------------------------------------------------------------- -\subsection{glfwOpenWindow} - -\textbf{C language syntax} -\begin{lstlisting} -int glfwOpenWindow(int width, int height, - int redbits, int greenbits, int bluebits, - int alphabits, int depthbits, int stencilbits, - int mode) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{width}]\ \\ - The width of the window. If \textit{width} is zero, it will be - calculated as ${width=\frac{4}{3}height}$, if \textit{height} is not - zero. If both \textit{width} and \textit{height} are zero, - \textit{width} will be set to 640. -\item [\textit{height}]\ \\ - The height of the window. If \textit{height} is zero, it will be - calculated as ${height=\frac{3}{4}width}$, if \textit{width} is not - zero. If both \textit{width} and \textit{height} are zero, - \textit{height} will be set to 480. -\item [\textit{redbits, greenbits, bluebits}]\ \\ - The number of bits to use for each color component of the color buffer - (0 means default color depth). For instance, setting \textit{redbits=5, - greenbits=6 and bluebits=5} will create a 16-­bit color buffer, if - possible. -\item [\textit{alphabits}]\ \\ - The number of bits to use for the alpha channel of the color buffer (0 means - no alpha channel). -\item [\textit{depthbits}]\ \\ - The number of bits to use for the depth buffer (0 means no depth - buffer). -\item [\textit{stencilbits}]\ \\ - The number of bits to use for the stencil buffer (0 means no stencil - buffer). -\item [\textit{mode}]\ \\ - Selects which type of \OpenGL\ window to use. \textit{mode} must be - either GLFW\_WINDOW, which will generate a normal desktop window, or - GLFW\_FULLSCREEN, which will generate a window which covers the entire - screen. When GLFW\_FULLSCREEN is selected, the video mode will be - changed to the resolution that closest matches the \textit{width} and - \textit{height} parameters. -\end{description} -\end{refparameters} - -\begin{refreturn} -If the function succeeds, GL\_TRUE is returned.\\ -If the function fails, GL\_FALSE is returned. -\end{refreturn} - -\begin{refdescription} -This function opens a window that best matches the parameters given to the -function. How well the resulting window matches the desired window depends -mostly on the available hardware and \OpenGL\ drivers. In general, -selecting a fullscreen mode has better chances of generating a close match -of buffers and channel sizes than does a normal desktop window, since \GLFW\ -can freely select from all the available video modes. A desktop window is -normally restricted to the video mode of the desktop. -\end{refdescription} - -\begin{refnotes} -For additional control of window properties, see -\textbf{glfwOpenWindowHint}. - -In fullscreen mode the mouse cursor is hidden by default and the -screensaver is prohibited from starting. In windowed mode the mouse -cursor is visible and screensavers are allowed to start. To change the -visibility of the mouse cursor, use \textbf{glfwEnable} or -\textbf{glfwDisable} with the argument GLFW\_MOUSE\_CURSOR. - -In order to determine the actual properties of an opened window, use -\textbf{glfwGetWindowParam} and \textbf{glfwGetWindowSize} (or -\textbf{glfwSetWindowSizeCallback}). - -On Microsoft Windows, if the executable has an icon resource named -\textbf{GLFW\_ICON}, it will be set as the icon for the window. If no such -icon is present, the \textbf{IDI\_WINLOGO} icon will be used instead. - -On Mac OS X the \GLFW\ window has no icon, but programs using \GLFW\ will use -the application bundle's icon. For more information on bundles, see the Bundle -Programming Guide provided by Apple. - -For information on how the availability of different platform-specific -extensions affect the behavior of this function, see appendix -\ref{chap:compatibility}. -\end{refnotes} - - -%------------------------------------------------------------------------- -\begin{table}[p] -\begin{center} -\begin{tabular}{|l|l|p{7.0cm}|} \hline \raggedright -\textbf{Name} & \textbf{Default} & \textbf{Description} \\ \hline -GLFW\_REFRESH\_RATE & 0 & Vertical monitor refresh rate in Hz (only used for fullscreen windows). Zero means system default.\\ \hline -GLFW\_ACCUM\_RED\_BITS & 0 & Number of bits for the red channel of the accumulation buffer.\\ \hline -GLFW\_ACCUM\_GREEN\_BITS & 0 & Number of bits for the green channel of the accumulation buffer.\\ \hline -GLFW\_ACCUM\_BLUE\_BITS & 0 & Number of bits for the blue channel of the accumulation buffer.\\ \hline -GLFW\_ACCUM\_ALPHA\_BITS & 0 & Number of bits for the alpha channel of the accumulation buffer.\\ \hline -GLFW\_AUX\_BUFFERS & 0 & Number of auxiliary buffers.\\ \hline -GLFW\_STEREO & GL\_FALSE & Specify if stereo rendering should be supported (can be GL\_TRUE or GL\_FALSE).\\ \hline -GLFW\_WINDOW\_NO\_RESIZE & GL\_FALSE & Specify whether the window can be resized by the user (not used for fullscreen windows).\\ \hline -GLFW\_FSAA\_SAMPLES & 0 & Number of samples to use for the multisampling buffer. Zero disables multisampling.\\ \hline -GLFW\_OPENGL\_VERSION\_MAJOR & 1 & Major number of the desired minimum \OpenGL\ version.\\ \hline -GLFW\_OPENGL\_VERSION\_MINOR & 1 & Minor number of the desired minimum \OpenGL\ version.\\ \hline -GLFW\_OPENGL\_FORWARD\_COMPAT & GL\_FALSE & Specify whether the \OpenGL\ context should be forward-compatible (i.e. disallow legacy functionality). - This should only be used when requesting \OpenGL\ version 3.0 or above.\\ \hline -GLFW\_OPENGL\_DEBUG\_CONTEXT & GL\_FALSE & Specify whether a debug context should be created.\\ \hline -GLFW\_OPENGL\_PROFILE & 0 & The \OpenGL\ profile the context should implement, or zero to let the system choose. - Available profiles are GLFW\_OPENGL\_CORE\_PROFILE and GLFW\_OPENGL\_COMPAT\_PROFILE.\\ \hline -\end{tabular} -\end{center} -\caption{Targets for \textbf{glfwOpenWindowHint}} -\label{tab:winhints} -\end{table} - - -%------------------------------------------------------------------------- -\subsection{glfwOpenWindowHint} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwOpenWindowHint(int target, int hint) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{target}]\ \\ - Can be any of the tokens in the table \ref{tab:winhints}. -\item [\textit{hint}]\ \\ - An integer giving the value of the corresponding token (see table - \ref{tab:winhints}). -\end{description} -\end{refparameters} - -\begin{refreturn} -none -\end{refreturn} - -\begin{refdescription} -This function sets additional properties for a window that is to be opened. -For a hint to be registered, the function must be called before calling -\textbf{glfwOpenWindow}. When the \textbf{glfwOpenWindow} function is -called, any hints that were registered with the \textbf{glfwOpenWindowHint} -function are used for setting the corresponding window properties, and -then all hints are reset to their default values. -\end{refdescription} - -\begin{refnotes} -In order to determine the actual properties of an opened window, use -\textbf{glfwGetWindowParam} (after the window has been opened). - -GLFW\_STEREO is a hard constraint. If stereo rendering is requested, but no -stereo rendering capable pixel formats / framebuffer configs are available, -\textbf{glfwOpenWindow} will fail. - -The GLFW\_REFRESH\_RATE hint should be used with caution. Most -systems have default values for monitor refresh rates that are optimal -for the specific system. Specifying the refresh rate can override these -settings, which can result in suboptimal operation. The monitor may be -unable to display the resulting video signal, or in the worst case it may -even be damaged! - -The GLFW\_WINDOW\_NO\_RESIZE hint applies only to manual resizing by the user. -A window created with this hint enabled can still be resized by the application -by calling \textbf{glfwSetWindowSize}. - -The GLFW\_OPENGL\_VERSION\_MAJOR and GLFW\_OPENGL\_VERSION\_MINOR hints specify -the \OpenGL\ version that the created context must be compatible with, -\emph{not} the exact version to use. It is therefore perfectly safe to use the -default of version 1.1 for legacy code and you will still get -backwards-compatible contexts of version 3.0 and above when available. - -To make the behavior of the above version hints consistent across both modern -and legacy drivers, \textbf{glfwOpenWindow} will fail if the modern creation -mechanism (as specified in \textbf{WGL\_ARB\_create\_context} -and \textbf{GLX\_ARB\_create\_context}) is unavailable \emph{and} the created -context is of a version lower than the one that was requested. - -At the time of release, the exact meaning of what a "debug context" is (as -created using the GLFW\_OPENGL\_DEBUG\_CONTEXT hint) has yet to be defined by -the Khronos ARB WG. - -For information on how the availability of different extensions affect the -behavior of this function, see appendix \ref{chap:compatibility}. - -For full details on the workings of the \OpenGL\ version, forward-compatibility -and debug hints, see the specifications for \textbf{WGL\_ARB\_create\_context} -and \textbf{GLX\_ARB\_create\_context}, respectively. The relevant \GLFW\ -hints map very closely to their platform-specific counterparts. -\end{refnotes} - - -%------------------------------------------------------------------------- -\subsection{glfwCloseWindow} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwCloseWindow(void) -\end{lstlisting} - -\begin{refparameters} -none -\end{refparameters} - -\begin{refreturn} -none -\end{refreturn} - -\begin{refdescription} -This function closes an opened window and destroys the associated \OpenGL\ -context. -\end{refdescription} - - -%------------------------------------------------------------------------- -\subsection{glfwSetWindowCloseCallback} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwSetWindowCloseCallback(GLFWwindowclosefun cbfun) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{cbfun}]\ \\ - Pointer to a callback function that will be called when a user requests - that the window should be closed, typically by clicking the window close - icon (e.g. the cross in the upper right corner of a window under - Microsoft Windows), and on Mac OS X also when selecting \textbf{Quit} from - the application menu. The function should have the following C language - prototype: - - \texttt{int functionname(void);} - - Where \textit{functionname} is the name of the callback function. The - return value of the callback function indicates wether or not the window - close action should continue. If the function returns GL\_TRUE, the - window will be closed. If the function returns GL\_FALSE, the window - will not be closed. - - If \textit{cbfun} is NULL, any previously set callback function - will be unset. -\end{description} -\end{refparameters} - -\begin{refreturn} -none -\end{refreturn} - -\begin{refdescription} -This function sets the callback for window close events. - -A window has to be opened for this function to have any effect. -\end{refdescription} - -\begin{refnotes} -Window close events are recorded continuously, but only reported when -\textbf{glfwPollEvents}, \textbf{glfwWaitEvents} or \textbf{glfwSwapBuffers} -(with GLFW\_AUTO\_POLL\_EVENTS enabled) is called. - -The \OpenGL\ context is still valid when this function is called. - -Note that the window close callback function is not called when -\textbf{glfwCloseWindow} is called, but only when the close request -comes from the window manager. - -Do \emph{not} call \textbf{glfwCloseWindow} from a window close -callback function. Close the window by returning GL\_TRUE from the -function. -\end{refnotes} - - -%------------------------------------------------------------------------- -\subsection{glfwSetWindowTitle} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwSetWindowTitle(const char* title) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{title}]\ \\ - Pointer to a null terminated ISO~8859-1 (8-bit Latin~1) string that - holds the title of the window. -\end{description} -\end{refparameters} - -\begin{refreturn} -none -\end{refreturn} - -\begin{refdescription} -This function changes the title of the opened window. -\end{refdescription} - -\begin{refnotes} -The title property of a window is often used in situations other than for -the window title, such as the title of an application icon when it is in -iconified state. -\end{refnotes} - - -%------------------------------------------------------------------------- -\subsection{glfwSetWindowSize} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwSetWindowSize(int width, int height) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{width}]\ \\ - Width of the window. -\item [\textit{height}]\ \\ - Height of the window. -\end{description} -\end{refparameters} - -\begin{refreturn} -none -\end{refreturn} - -\begin{refdescription} -This function changes the size of an opened window. The \textit{width} and -\textit{height} parameters denote the size of the client area of the -window (i.e. excluding any window borders and decorations). - -If the window is in fullscreen mode, the video mode will be changed to a -resolution that closest matches the width and height parameters (the -number of color bits will not be changed). -\end{refdescription} - -\begin{refnotes} -This function has no effect if the window is iconified. - -The \OpenGL\ context is guaranteed to be preserved after calling -\textbf{glfwSetWindowSize}, even if the video mode is changed. - -This function is not affected by the value of the GLFW\_WINDOW\_NO\_RESIZE -hint. -\end{refnotes} - - -%------------------------------------------------------------------------- -\subsection{glfwSetWindowPos} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwSetWindowPos(int x, int y) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{x}]\ \\ - Horizontal position of the window, relative to the upper left corner - of the desktop. -\item [\textit{y}]\ \\ - Vertical position of the window, relative to the upper left corner of - the desktop. -\end{description} -\end{refparameters} - -\begin{refreturn} -none -\end{refreturn} - -\begin{refdescription} -This function changes the position of an opened window. It does not have -any effect on a fullscreen window. -\end{refdescription} - -\begin{refnotes} -This function has no effect if the window is iconified. - -The behaviour of this function on multi-monitor systems is ill-defined. -\end{refnotes} - - -%------------------------------------------------------------------------- -\subsection{glfwGetWindowSize} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwGetWindowSize(int* width, int* height) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{width}]\ \\ - Pointer to an integer that will hold the width of the window. -\item [\textit{height}]\ \\ - Pointer to an integer that will hold the height of the window. -\end{description} -\end{refparameters} - -\begin{refreturn} -The current width and height of the opened window is returned in the -\textit{width} and \textit{height} parameters, respectively. -\end{refreturn} - -\begin{refdescription} -This function is used for determining the size of an opened window. -The returned values are dimensions of the client area of the window -(i.e. excluding any window borders and decorations). -\end{refdescription} - -\begin{refnotes} -Even if the size of a fullscreen window does not change once the window -has been opened, it does not necessarily have to be the same as the size -that was requested using \textbf{glfwOpenWindow}. Therefor it is wise to -use this function to determine the true size of the window once it has -been opened. -\end{refnotes} - - -%------------------------------------------------------------------------- -\subsection{glfwSetWindowSizeCallback} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwSetWindowSizeCallback(GLFWwindowsizefun cbfun) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{cbfun}]\ \\ - Pointer to a callback function that will be called every time the - window size changes. The function should have the following C language - prototype: - - \texttt{void functionname(int width, int height);} - - Where \textit{functionname} is the name of the callback function, and - \textit{width} and \textit{height} are the dimensions of the window - client area. - - If \textit{cbfun} is NULL, any previously set callback function - will be unset. -\end{description} -\end{refparameters} - -\begin{refreturn} -none -\end{refreturn} - -\begin{refdescription} -This function sets the callback for window size change events. - -A window has to be opened for this function to have any effect. -\end{refdescription} - -\begin{refnotes} -Window size changes are recorded continuously, but only reported when -\textbf{glfwPollEvents}, \textbf{glfwWaitEvents} or \textbf{glfwSwapBuffers} -(with GLFW\_AUTO\_POLL\_EVENTS enabled) is called. - -When a callback function is set, it will be called with the current window -size before this function returns. -\end{refnotes} - - -%------------------------------------------------------------------------- -\subsection{glfwIconifyWindow} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwIconifyWindow(void) -\end{lstlisting} - -\begin{refparameters} -none -\end{refparameters} - -\begin{refreturn} -none -\end{refreturn} - -\begin{refdescription} -Iconify a window. If the window is in fullscreen mode, then the desktop -video mode will be restored. -\end{refdescription} - - -%------------------------------------------------------------------------- -\subsection{glfwRestoreWindow} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwRestoreWindow(void) -\end{lstlisting} - -\begin{refparameters} -none -\end{refparameters} - -\begin{refreturn} -none -\end{refreturn} - -\begin{refdescription} -Restore an iconified window. If the window that is restored is in -fullscreen mode, then the fullscreen video mode will be restored. -\end{refdescription} - - -%------------------------------------------------------------------------- -\begin{table}[p] -\begin{center} -\begin{tabular}{|l|p{9.5cm}|} \hline \raggedright -\textbf{Name} & \textbf{Description} \\ \hline -GLFW\_OPENED & GL\_TRUE if window is opened, else GL\_FALSE.\\ \hline -GLFW\_ACTIVE & GL\_TRUE if window has focus, else GL\_FALSE.\\ \hline -GLFW\_ICONIFIED & GL\_TRUE if window is iconified, else GL\_FALSE.\\ \hline -GLFW\_ACCELERATED & GL\_TRUE if window is hardware accelerated, else GL\_FALSE.\\ \hline -GLFW\_RED\_BITS & Number of bits for the red color component.\\ \hline -GLFW\_GREEN\_BITS & Number of bits for the green color component.\\ \hline -GLFW\_BLUE\_BITS & Number of bits for the blue color component.\\ \hline -GLFW\_ALPHA\_BITS & Number of bits for the alpha buffer.\\ \hline -GLFW\_DEPTH\_BITS & Number of bits for the depth buffer.\\ \hline -GLFW\_STENCIL\_BITS & Number of bits for the stencil buffer.\\ \hline -GLFW\_REFRESH\_RATE & Vertical monitor refresh rate in Hz. Zero indicates an unknown or a default refresh rate.\\ \hline -GLFW\_ACCUM\_RED\_BITS & Number of bits for the red channel of the accumulation buffer.\\ \hline -GLFW\_ACCUM\_GREEN\_BITS & Number of bits for the green channel of the accumulation buffer.\\ \hline -GLFW\_ACCUM\_BLUE\_BITS & Number of bits for the blue channel of the accumulation buffer.\\ \hline -GLFW\_ACCUM\_ALPHA\_BITS & Number of bits for the alpha channel of the accumulation buffer.\\ \hline -GLFW\_AUX\_BUFFERS & Number of auxiliary buffers.\\ \hline -GLFW\_STEREO & GL\_TRUE if stereo rendering is supported, else GL\_FALSE.\\ \hline -GLFW\_WINDOW\_NO\_RESIZE & GL\_TRUE if the window cannot be resized by the user, else GL\_FALSE.\\ \hline -GLFW\_FSAA\_SAMPLES & Number of multisampling buffer samples. Zero indicated multisampling is disabled.\\ \hline -GLFW\_OPENGL\_VERSION\_MAJOR & Major number of the actual version of the context.\\ \hline -GLFW\_OPENGL\_VERSION\_MINOR & Minor number of the actual version of the context.\\ \hline -GLFW\_OPENGL\_FORWARD\_COMPAT & GL\_TRUE if the context is forward-compatible, else GL\_FALSE.\\ \hline -GLFW\_OPENGL\_DEBUG\_CONTEXT & GL\_TRUE if the context is a debug context.\\ \hline -GLFW\_OPENGL\_PROFILE & The profile implemented by the context, or zero.\\ \hline -\end{tabular} -\end{center} -\caption{Window parameters for \textbf{glfwGetWindowParam}} -\label{tab:winparams} -\end{table} - - -%------------------------------------------------------------------------- -\subsection{glfwGetWindowParam} - -\textbf{C language syntax} -\begin{lstlisting} -int glfwGetWindowParam(int param) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{param}]\ \\ - A token selecting which parameter the function should return (see - table \ref{tab:winparams}). -\end{description} -\end{refparameters} - -\begin{refreturn} -The function returns the value the window parameter corresponding to the token -\textit{param}. Table \ref{tab:winparams} lists the available tokens. -\end{refreturn} - -\begin{refdescription} -This function is used for acquiring various properties of an opened window. -\end{refdescription} - -\begin{refnotes} -GLFW\_ACCELERATED is only supported under Windows. Other systems will -always return GL\_TRUE. Under Windows, GLFW\_ACCELERATED means that the -\OpenGL\ renderer is a 3rd party renderer, rather than the fallback -Microsoft software \OpenGL\ renderer. In other words, it is not a real -guarantee that the \OpenGL\ renderer is actually hardware accelerated. - -GLFW\_OPENGL\_VERSION\_MAJOR and GLFW\_OPENGL\_VERSION\_MINOR always return the -same values as those returned by \textbf{glfwGetGLVersion}. -\end{refnotes} - - -%------------------------------------------------------------------------- -\subsection{glfwSwapBuffers} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwSwapBuffers(void) -\end{lstlisting} - -\begin{refparameters} -none -\end{refparameters} - -\begin{refreturn} -none -\end{refreturn} - -\begin{refdescription} -This function swaps the back and front color buffers of the window. If -GLFW\_AUTO\_POLL\_EVENTS is enabled (which is the default), -\textbf{glfwPollEvents} is called after swapping the front and back -buffers. -\end{refdescription} - -\begin{refnotes} -In previous versions of \GLFW , \textbf{glfwPollEvents} was called -\emph{before} buffer swap. This was changed in order to decrease input -lag but may affect code that relied on the former behavior. -\end{refnotes} - - -%------------------------------------------------------------------------- -\subsection{glfwSwapInterval} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwSwapInterval(int interval) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{interval}]\ \\ - Minimum number of monitor vertical retraces between each buffer swap - performed by \textbf{glfwSwapBuffers}. If \textit{interval} is zero, - buffer swaps will not be synchronized to the vertical refresh of the - monitor (also known as 'VSync off'). -\end{description} -\end{refparameters} - -\begin{refreturn} -none -\end{refreturn} - -\begin{refdescription} -This function selects the minimum number of monitor vertical retraces that -should occur between two buffer swaps. If the selected swap interval is -one, the rate of buffer swaps will never be higher than the vertical -refresh rate of the monitor. If the selected swap interval is zero, the -rate of buffer swaps is only limited by the speed of the software and -the hardware. -\end{refdescription} - -\begin{refnotes} -This function will only have an effect on hardware and drivers that support -user selection of the swap interval. ATI drivers in particular have been known -to ignore this setting. -\end{refnotes} - - -%------------------------------------------------------------------------- -\subsection{glfwSetWindowRefreshCallback} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwSetWindowRefreshCallback(GLFWwindowrefreshfun cbfun) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{cbfun}]\ \\ - Pointer to a callback function that will be called when the window client - area needs to be refreshed. The function should have the following C - language prototype: - - \texttt{void functionname(void);} - - Where \textit{functionname} is the name of the callback function. - - If \textit{cbfun} is NULL, any previously set callback function - will be unset. -\end{description} -\end{refparameters} - -\begin{refreturn} -none -\end{refreturn} - -\begin{refdescription} -This function sets the callback for window refresh events, which occurs when -any part of the window client area has been damaged, and needs to be repainted -(for instance, if a part of the window that was previously occluded by another -window has become visible). - -A window has to be opened for this function to have any effect. -\end{refdescription} - -\begin{refnotes} -Window refresh events are recorded continuously, but only reported when -\textbf{glfwPollEvents}, \textbf{glfwWaitEvents} or \textbf{glfwSwapBuffers} -(with GLFW\_AUTO\_POLL\_EVENTS enabled) is called. - -Modern windowing systems using hardware compositing, such as Aqua, Aero and -Compiz, very rarely need to refresh the contents of windows, so the specified -callback will very rarely be called on such systems. -\end{refnotes} - - -%------------------------------------------------------------------------- -\pagebreak -\section{Video Modes} -Since \GLFW\ supports video mode changes when using a fullscreen window, -it also provides functionality for querying which video modes are -supported on a system. - - -%------------------------------------------------------------------------- -\subsection{glfwGetVideoModes} - -\textbf{C language syntax} -\begin{lstlisting} -int glfwGetVideoModes(GLFWvidmode* list, int maxcount) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{list}]\ \\ - A vector of \textit{GLFWvidmode} structures, which will be filled out - by the function. -\item [\textit{maxcount}]\ \\ - Maximum number of video modes that \textit{list} vector can hold. -\end{description} -\end{refparameters} - -\begin{refreturn} -The function returns the number of detected video modes (this number -will never exceed \textit{maxcount}). The \textit{list} vector is -filled out with the video modes that are supported by the system. -\end{refreturn} - -\begin{refdescription} -This function returns a list of supported video modes. Each video mode is -represented by a \textit{GLFWvidmode} structure, which has the following -definition: - -\begin{lstlisting} -typedef struct { - int Width, Height; // Video resolution - int RedBits; // Number of red bits - int GreenBits; // Number of green bits - int BlueBits; // Number of blue bits -} GLFWvidmode; -\end{lstlisting} -\end{refdescription} - -\begin{refnotes} -The returned list is sorted, first by color depth ($RedBits + GreenBits + -BlueBits$), and then by resolution ($Width \times Height$), with the -lowest resolution, fewest bits per pixel mode first. -\end{refnotes} - - -%------------------------------------------------------------------------- -\subsection{glfwGetDesktopMode} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwGetDesktopMode(GLFWvidmode* mode) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{mode}]\ \\ - Pointer to a \textit{GLFWvidmode} structure, which will be filled out - by the function. -\end{description} -\end{refparameters} - -\begin{refreturn} -The \textit{GLFWvidmode} structure pointed to by \textit{mode} is filled -out with the desktop video mode. -\end{refreturn} - -\begin{refdescription} -This function returns the desktop video mode in a \textit{GLFWvidmode} -structure. See \textbf{glfwGetVideoModes} for a definition of the -\textit{GLFWvidmode} structure. -\end{refdescription} - -\begin{refnotes} -The color depth of the desktop display is always reported as the number -of bits for each individual color component (red, green and blue), even -if the desktop is not using an RGB or RGBA color format. For instance, an -indexed 256 color display may report \textit{RedBits} = 3, -\textit{GreenBits} = 3 and \textit{BlueBits} = 2, which adds up to 8 bits -in total. - -The desktop video mode is the video mode used by the desktop at the time -the \GLFW\ window was opened, \textit{not} the current video mode (which -may differ from the desktop video mode if the \GLFW\ window is a -fullscreen window). -\end{refnotes} - - -%------------------------------------------------------------------------- -\pagebreak -\section{Input Handling} -\GLFW\ supports three channels of user input: keyboard input, mouse input -and joystick input. - -Keyboard and mouse input can be treated either as events, using callback -functions, or as state, using functions for polling specific keyboard and -mouse states. Regardless of which method is used, all keyboard and mouse -input is collected using window event polling. - -Joystick input is asynchronous to the keyboard and mouse input, and does -not require event polling for keeping up to date joystick information. -Also, joystick input is independent of any window, so a window does not -have to be opened for joystick input to be used. - - -%------------------------------------------------------------------------- -\subsection{glfwPollEvents} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwPollEvents(void) -\end{lstlisting} - -\begin{refparameters} -none -\end{refparameters} - -\begin{refreturn} -none -\end{refreturn} - -\begin{refdescription} -This function is used for polling for events, such as user input and -window resize events. Upon calling this function, all window states, -keyboard states and mouse states are updated. If any related callback -functions are registered, these are called during the call to -\textbf{glfwPollEvents}. -\end{refdescription} - -\begin{refnotes} -\textbf{glfwPollEvents} is called implicitly from \textbf{glfwSwapBuffers} -if GLFW\_AUTO\_POLL\_EVENTS is enabled (as it is by default). Thus, if -\textbf{glfwSwapBuffers} is called frequently, which is normally the case, -there is no need to call \textbf{glfwPollEvents}. -\end{refnotes} - - -%------------------------------------------------------------------------- -\subsection{glfwWaitEvents} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwWaitEvents(void) -\end{lstlisting} - -\begin{refparameters} -none -\end{refparameters} - -\begin{refreturn} -none -\end{refreturn} - -\begin{refdescription} -This function is used for waiting for events, such as user input and -window resize events. Upon calling this function, the calling thread will -be put to sleep until any event appears in the event queue. When events -are available, they will be processed just as they are processed by -\textbf{glfwPollEvents}. - -If there are any events in the queue when the function is called, the -function will behave exactly like \textbf{glfwPollEvents} (i.e. process -all messages and then return, without blocking the calling thread). -\end{refdescription} - -\begin{refnotes} -It is guaranteed that \textbf{glfwWaitEvents} will wake up on any event that -can be processed by \textbf{glfwPollEvents}. However, \GLFW\ receives many -events that are only processed internally and the function may behave -differently on different systems. Do not make any assumptions about when or why -\textbf{glfwWaitEvents} will return. -\end{refnotes} - - -%------------------------------------------------------------------------- -\begin{table}[p] -\begin{center} -\begin{tabular}{|l|l|} \hline \raggedright -\textbf{Name} & \textbf{Description} \\ \hline -GLFW\_KEY\_\textit{X} & Letter (\textit{X} can be in the range A..Z)\\ \hline -GLFW\_KEY\_\textit{n} & Number (\textit{n} can be in the range 0..9)\\ \hline -GLFW\_KEY\_SPACE & Space\\ \hline -GLFW\_KEY\_MINUS & Minus (-)\\ \hline -GLFW\_KEY\_EQUAL & Equal (=)\\ \hline -GLFW\_KEY\_LEFT\_BRACKET & Left bracket ([)\\ \hline -GLFW\_KEY\_RIGHT\_BRACKET & Right bracket (])\\ \hline -GLFW\_KEY\_GRAVE\_ACCENT & Grave accent (`)\\ \hline -GLFW\_KEY\_APOSTROPHE & Apostrophe (')\\ \hline -GLFW\_KEY\_COMMA & Comma (,)\\ \hline -GLFW\_KEY\_PERIOD & Period (.)\\ \hline -GLFW\_KEY\_SEMICOLON & Semicolon (;)\\ \hline -GLFW\_KEY\_SLASH & Slash ($/$)\\ \hline -GLFW\_KEY\_BACKSLASH & Backslash ($\backslash$)\\ \hline -GLFW\_KEY\_WORLD\_1 & Non-US character no. 1\\ \hline -GLFW\_KEY\_WORLD\_2 & Non-US character no. 2\\ \hline -\end{tabular} -\end{center} -\caption[Key codes for printable keys]{Key codes for printable keys. The keys are named according to the US keyboard layout, but represent physical keys (so for instance, GLFW\_KEY\_Z represents the same physical key, regardless of the system input language).} -\label{tab:keys1} -\end{table} - -\begin{table}[p] -\begin{center} -\begin{tabular}{|l|l|} \hline \raggedright -\textbf{Name} & \textbf{Description} \\ \hline -GLFW\_KEY\_ESCAPE & Escape\\ \hline -GLFW\_KEY\_F\textit{n} & Function key \textit{n} (\textit{n} can be in the range 1..25)\\ \hline -GLFW\_KEY\_UP & Cursor up\\ \hline -GLFW\_KEY\_DOWN & Cursor down\\ \hline -GLFW\_KEY\_LEFT & Cursor left\\ \hline -GLFW\_KEY\_RIGHT & Cursor right\\ \hline -GLFW\_KEY\_LEFT\_SHIFT & Left shift key\\ \hline -GLFW\_KEY\_RIGHT\_SHIFT & Right shift key\\ \hline -GLFW\_KEY\_LEFT\_CTRL & Left control key\\ \hline -GLFW\_KEY\_RIGHT\_CTRL & Right control key\\ \hline -GLFW\_KEY\_LEFT\_ALT & Left alternate function key\\ \hline -GLFW\_KEY\_RIGHT\_ALT & Right alternate function key\\ \hline -GLFW\_KEY\_LEFT\_SUPER & Left super key, WinKey, or command key\\ \hline -GLFW\_KEY\_RIGHT\_SUPER & Right super key, WinKey, or command key\\ \hline -GLFW\_KEY\_TAB & Tabulator\\ \hline -GLFW\_KEY\_ENTER & Enter\\ \hline -GLFW\_KEY\_BACKSPACE & Backspace\\ \hline -GLFW\_KEY\_INSERT & Insert\\ \hline -GLFW\_KEY\_DELETE & Delete\\ \hline -GLFW\_KEY\_PAGE\_UP & Page up\\ \hline -GLFW\_KEY\_PAGE\_DOWN & Page down\\ \hline -GLFW\_KEY\_HOME & Home\\ \hline -GLFW\_KEY\_END & End\\ \hline -GLFW\_KEY\_KP\_\textit{n} & Keypad numeric key \textit{n} (\textit{n} can be in the range 0..9)\\ \hline -GLFW\_KEY\_KP\_DIVIDE & Keypad divide ($\div$)\\ \hline -GLFW\_KEY\_KP\_MULTIPLY & Keypad multiply ($\times$)\\ \hline -GLFW\_KEY\_KP\_SUBTRACT & Keypad subtract ($-$)\\ \hline -GLFW\_KEY\_KP\_ADD & Keypad add ($+$)\\ \hline -GLFW\_KEY\_KP\_DECIMAL & Keypad decimal (. or ,)\\ \hline -GLFW\_KEY\_KP\_EQUAL & Keypad equal (=)\\ \hline -GLFW\_KEY\_KP\_ENTER & Keypad enter\\ \hline -GLFW\_KEY\_NUM\_LOCK & Num lock\\ \hline -GLFW\_KEY\_CAPS\_LOCK & Caps lock\\ \hline -GLFW\_KEY\_SCROLL\_LOCK & Scroll lock\\ \hline -GLFW\_KEY\_PAUSE & Pause key\\ \hline -GLFW\_KEY\_MENU & Menu key\\ \hline -\end{tabular} -\end{center} -\caption{Key codes for function keys} -\label{tab:keys2} -\end{table} - - -%------------------------------------------------------------------------- -\begin{table}[p] -\begin{center} -\begin{tabular}{|l|l|} \hline \raggedright -\textbf{Name} & \textbf{Description} \\ \hline -GLFW\_MOUSE\_BUTTON\_LEFT & Left mouse button (button 1) \\ \hline -GLFW\_MOUSE\_BUTTON\_RIGHT & Right mouse button (button 2) \\ \hline -GLFW\_MOUSE\_BUTTON\_MIDDLE & Middle mouse button (button 3) \\ \hline -GLFW\_MOUSE\_BUTTON\_\textit{n} & Mouse button \textit{n} (\textit{n} can be in the range 1..8)\\ \hline -\end{tabular} -\end{center} -\caption{Valid mouse button identifiers} -\label{tab:mousebuttons} -\end{table} - - -%------------------------------------------------------------------------- -\subsection{glfwGetKey} - -\textbf{C language syntax} -\begin{lstlisting} -int glfwGetKey(int key) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{key}]\ \\ - A keyboard key identifier, which can be any of the key codes in tables - \ref{tab:keys1} and \ref{tab:keys2}. -\end{description} -\end{refparameters} - -\begin{refreturn} -The function returns GLFW\_PRESS if the key is held down, or GLFW\_RELEASE -if the key is not held down. -\end{refreturn} - -\begin{refdescription} -This function queries the current state of a specific keyboard key. The -physical location of each key depends on the system keyboard layout -setting. -\end{refdescription} - -\begin{refnotes} -The constant GLFW\_KEY\_SPACE is equal to 32, which is the ISO~8859-1 code -for space. This is the only named \GLFW\ key identifier with a value in the -ISO~8859-1 range. - -Not all key codes are supported on all systems. Also, while some keys are -available on some keyboard layouts, they may not be available on other -keyboard layouts. - -For systems that do not distinguish between left and right versions of -modifier keys (shift, alt and control), the left version is used (e.g. -GLFW\_KEY\_LSHIFT). - -A window must be opened for the function to have any effect, and -\textbf{glfwPollEvents}, \textbf{glfwWaitEvents} or \textbf{glfwSwapBuffers} -(with GLFW\_AUTO\_POLL\_EVENTS enabled) must be called before any keyboard -events are recorded and reported by \textbf{glfwGetKey}. -\end{refnotes} - - -%------------------------------------------------------------------------- -\subsection{glfwGetMouseButton} - -\textbf{C language syntax} -\begin{lstlisting} -int glfwGetMouseButton(int button) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{button}]\ \\ - A mouse button identifier, which can be one of the mouse button - identifiers listed in table \ref{tab:mousebuttons}. -\end{description} -\end{refparameters} - -\begin{refreturn} -The function returns GLFW\_PRESS if the mouse button is held down, or -GLFW\_RELEASE if the mouse button is not held down. -\end{refreturn} - -\begin{refdescription} -This function queries the current state of a specific mouse button. -\end{refdescription} - -\begin{refnotes} -A window must be opened for the function to have any effect, and -\textbf{glfwPollEvents}, \textbf{glfwWaitEvents} or \textbf{glfwSwapBuffers} -(with GLFW\_AUTO\_POLL\_EVENTS enabled) must be called before any mouse button -events are recorded and reported by \textbf{glfwGetMouseButton}. - -GLFW\_MOUSE\_BUTTON\_LEFT is equal to GLFW\_MOUSE\_BUTTON\_1. -GLFW\_MOUSE\_BUTTON\_RIGHT is equal to GLFW\_MOUSE\_BUTTON\_2. -GLFW\_MOUSE\_BUTTON\_MIDDLE is equal to GLFW\_MOUSE\_BUTTON\_3. -\end{refnotes} - - -%------------------------------------------------------------------------- -\subsection{glfwGetMousePos} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwGetMousePos(int* xpos, int* ypos) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{xpos}]\ \\ - Pointer to an integer that will be set to the horizontal position of the - mouse cursor. -\item [\textit{ypos}]\ \\ - Pointer to an integer that will be set to the vertical position of the mouse cursor. -\end{description} -\end{refparameters} - -\begin{refreturn} -The function returns the current mouse cursor position in \textit{xpos} and -\textit{ypos}. -\end{refreturn} - -\begin{refdescription} -This function returns the current mouse position. If the cursor is not -hidden, the mouse position is the cursor position, relative to the upper -left corner of the window and with the Y-axis down. If the cursor is hidden, -the mouse position is a virtual absolute position, not limited to any -boundaries except to those implied by the maximum number that can be -represented by a signed integer. -\end{refdescription} - -\begin{refnotes} -A window must be opened for the function to have any effect, and -\textbf{glfwPollEvents}, \textbf{glfwWaitEvents} or \textbf{glfwSwapBuffers} -(with GLFW\_AUTO\_POLL\_EVENTS enabled) must be called before any mouse -movements are recorded and reported by \textbf{glfwGetMousePos}. -\end{refnotes} - - -%------------------------------------------------------------------------- -\subsection{glfwSetMousePos} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwSetMousePos(int xpos, int ypos) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{xpos}]\ \\ - Horizontal position of the mouse. -\item [\textit{ypos}]\ \\ - Vertical position of the mouse. -\end{description} -\end{refparameters} - -\begin{refreturn} -none -\end{refreturn} - -\begin{refdescription} -This function changes the position of the mouse. If the cursor is visible (not -disabled), the cursor will be moved to the specified position, relative to the -upper left corner of the window client area and with the Y-axis down. If the -cursor is hidden (disabled), only the mouse position that is reported by \GLFW\ -is changed. -\end{refdescription} - - -%------------------------------------------------------------------------- -\subsection{glfwGetMouseWheel} - -\textbf{C language syntax} -\begin{lstlisting} -int glfwGetMouseWheel(void) -\end{lstlisting} - -\begin{refparameters} -none -\end{refparameters} - -\begin{refreturn} -The function returns the current mouse wheel position. -\end{refreturn} - -\begin{refdescription} -This function returns the current mouse wheel position. The mouse wheel can -be thought of as a third mouse axis, which is available as a separate -wheel or up/down stick on some mice. -\end{refdescription} - -\begin{refnotes} -A window must be opened for the function to have any effect, and -\textbf{glfwPollEvents}, \textbf{glfwWaitEvents} or \textbf{glfwSwapBuffers} -(with GLFW\_AUTO\_POLL\_EVENTS enabled) must be called before any mouse wheel -movements are recorded and reported by \textbf{glfwGetMouseWheel}. -\end{refnotes} - - -%------------------------------------------------------------------------- -\subsection{glfwSetMouseWheel} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwSetMouseWheel(int pos) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{pos}]\ \\ - Position of the mouse wheel. -\end{description} -\end{refparameters} - -\begin{refreturn} -none -\end{refreturn} - -\begin{refdescription} -This function changes the position of the mouse wheel. -\end{refdescription} - - -%------------------------------------------------------------------------- -\subsection{glfwSetKeyCallback} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwSetKeyCallback(GLFWkeyfun cbfun) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{cbfun}]\ \\ - Pointer to a callback function that will be called every time a key is - pressed or released. The function should have the following C language - prototype: - - \texttt{void functionname(int key, int action);} - - Where \textit{functionname} is the name of the callback function, - \textit{key} is a key code (see tables \ref{tab:keys1} and \ref{tab:keys2}), - and \textit{action} is either GLFW\_PRESS or GLFW\_RELEASE. - - If \textit{cbfun} is NULL, any previously set callback function - will be unset. -\end{description} -\end{refparameters} - -\begin{refreturn} -none -\end{refreturn} - -\begin{refdescription} -This function sets the callback for keyboard key events. The callback function -is called every time the state of a single key is changed (from released to -pressed or vice versa). The reported keys are unaffected by any modifiers (such -as shift or alt) and each modifier is reported as a separate key. - -A window has to be opened for this function to have any effect. -\end{refdescription} - -\begin{refnotes} -Keyboard key events are not intended for text input and many languages -will not be able to be input using it. Use Unicode character events for -text input instead. - -Keyboard events are recorded continuously, but only reported when -\textbf{glfwPollEvents}, \textbf{glfwWaitEvents} or \textbf{glfwSwapBuffers} -(with GLFW\_AUTO\_POLL\_EVENTS enabled) is called. -\end{refnotes} - - -%------------------------------------------------------------------------- -\subsection{glfwSetCharCallback} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwSetCharCallback(GLFWcharfun cbfun) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{cbfun}]\ \\ - Pointer to a callback function that will be called every time a - printable character is generated by the keyboard. The function should - have the following C language prototype: - - \texttt{void functionname(int character, int action);} - - Where \textit{functionname} is the name of the callback function, - \textit{character} is a Unicode (ISO~10646) character, and - \textit{action} is either GLFW\_PRESS or GLFW\_RELEASE. - - If \textit{cbfun} is NULL, any previously set callback function - will be unset. -\end{description} -\end{refparameters} - -\begin{refreturn} -none -\end{refreturn} - -\begin{refdescription} -This function sets the callback for keyboard character events. The callback -function is called every time a key that results in a printable Unicode -character is pressed or released. Characters are affected by modifiers (such -as shift or alt). - -A window has to be opened for this function to have any effect. -\end{refdescription} - -\begin{refnotes} -Character events are recorded continuously, but only reported when -\textbf{glfwPollEvents}, \textbf{glfwWaitEvents} or \textbf{glfwSwapBuffers} -(with GLFW\_AUTO\_POLL\_EVENTS enabled) is called. - -Control characters such as tab and carriage return are not reported to -the character callback function, since they are not part of the Unicode -character set. Use the key callback function for such events (see -\textbf{glfwSetKeyCallback}). - -The Unicode character set supports character codes above 255, so never -cast a Unicode character to an eight bit data type (e.g. the C language -'char' type) without first checking that the character code is less than -256. Also note that Unicode character codes 0 to 255 are equal to -ISO~8859-1 (Latin~1). -\end{refnotes} - - -%------------------------------------------------------------------------- -\subsection{glfwSetMouseButtonCallback} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwSetMouseButtonCallback(GLFWmousebuttonfun cbfun) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{cbfun}]\ \\ - Pointer to a callback function that will be called every time a mouse - button is pressed or released. The function should have the following C - language prototype: - - \texttt{void functionname(int button, int action);} - - Where \textit{functionname} is the name of the callback function, - \textit{button} is a mouse button identifier (see table - \ref{tab:mousebuttons} on page \pageref{tab:mousebuttons}), and - \textit{action} is either GLFW\_PRESS or GLFW\_RELEASE. - - If \textit{cbfun} is NULL, any previously set callback function - will be unset. -\end{description} -\end{refparameters} - -\begin{refreturn} -none -\end{refreturn} - -\begin{refdescription} -This function sets the callback for mouse button events. - -A window has to be opened for this function to have any effect. -\end{refdescription} - -\begin{refnotes} -Mouse button events are recorded continuously, but only reported when -\textbf{glfwPollEvents}, \textbf{glfwWaitEvents} or \textbf{glfwSwapBuffers} -(with GLFW\_AUTO\_POLL\_EVENTS enabled) is called. - -GLFW\_MOUSE\_BUTTON\_LEFT is equal to GLFW\_MOUSE\_BUTTON\_1. -GLFW\_MOUSE\_BUTTON\_RIGHT is equal to GLFW\_MOUSE\_BUTTON\_2. -GLFW\_MOUSE\_BUTTON\_MIDDLE is equal to GLFW\_MOUSE\_BUTTON\_3. -\end{refnotes} - - -%------------------------------------------------------------------------- -\subsection{glfwSetMousePosCallback} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwSetMousePosCallback(GLFWmouseposfun cbfun) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{cbfun}]\ \\ - Pointer to a callback function that will be called every time the mouse - is moved. The function should have the following C language prototype: - - \texttt{void functionname(int x, int y);} - - Where \textit{functionname} is the name of the callback function, and - \textit{x} and \textit{y} are the mouse coordinates (see - \textbf{glfwGetMousePos} for more information on mouse coordinates). - - If \textit{cbfun} is NULL, any previously set callback function - will be unset. -\end{description} -\end{refparameters} - -\begin{refreturn} -none -\end{refreturn} - -\begin{refdescription} -This function sets the callback for mouse motion events. - -A window has to be opened for this function to have any effect. -\end{refdescription} - -\begin{refnotes} -Mouse motion events are recorded continuously, but only reported when -\textbf{glfwPollEvents}, \textbf{glfwWaitEvents} or \textbf{glfwSwapBuffers} -(with GLFW\_AUTO\_POLL\_EVENTS enabled) is called. -\end{refnotes} - - -%------------------------------------------------------------------------- -\subsection{glfwSetMouseWheelCallback} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwSetMouseWheelCallback(GLFWmousewheelfun cbfun) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{cbfun}]\ \\ - Pointer to a callback function that will be called every time the mouse - wheel is moved. The function should have the following C language - prototype: - - \texttt{void functionname(int pos);} - - Where \textit{functionname} is the name of the callback function, and - \textit{pos} is the mouse wheel position. - - If \textit{cbfun} is NULL, any previously set callback function - will be unset. -\end{description} -\end{refparameters} - -\begin{refreturn} -none -\end{refreturn} - -\begin{refdescription} -This function sets the callback for mouse wheel events. - -A window has to be opened for this function to have any effect. -\end{refdescription} - -\begin{refnotes} -Mouse wheel events are recorded continuously, but only reported when -\textbf{glfwPollEvents}, \textbf{glfwWaitEvents} or \textbf{glfwSwapBuffers} -(with GLFW\_AUTO\_POLL\_EVENTS enabled) is called. -\end{refnotes} - - -%------------------------------------------------------------------------- -\begin{table}[p] -\begin{center} -\begin{tabular}{|l|l|}\hline \raggedright -\textbf{Name} & \textbf{Return value}\\ \hline -GLFW\_PRESENT & GL\_TRUE if the joystick is connected, else GL\_FALSE.\\ \hline -GLFW\_AXES & Number of axes supported by the joystick.\\ \hline -GLFW\_BUTTONS & Number of buttons supported by the joystick.\\ \hline -\end{tabular} -\end{center} -\caption{Joystick parameters for \textbf{glfwGetJoystickParam}} -\label{tab:joyparams} -\end{table} - - -%------------------------------------------------------------------------- -\subsection{glfwGetJoystickParam} - -\textbf{C language syntax} -\begin{lstlisting} -int glfwGetJoystickParam(int joy, int param) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{joy}]\ \\ - A joystick identifier, which should be GLFW\_JOYSTICK\_\textit{n}, where - \textit{n} is in the range 1 to 16. -\item [\textit{param}]\ \\ - A token selecting which parameter the function should return (see table - \ref{tab:joyparams}). -\end{description} -\end{refparameters} - -\begin{refreturn} -The function returns different parameters depending on the value of -\textit{param}. Table \ref{tab:joyparams} lists valid \textit{param} -values, and their corresponding return values. -\end{refreturn} - -\begin{refdescription} -This function is used for acquiring various properties of a joystick. -\end{refdescription} - -\begin{refnotes} -The joystick information is updated every time the function is called. - -No window has to be opened for joystick information to be available. -\end{refnotes} - - -%------------------------------------------------------------------------- -\subsection{glfwGetJoystickPos} - -\textbf{C language syntax} -\begin{lstlisting} -int glfwGetJoystickPos(int joy, float* pos, int numaxes) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{joy}]\ \\ - A joystick identifier, which should be GLFW\_JOYSTICK\_\textit{n}, where - \textit{n} is in the range 1 to 16. -\item [\textit{pos}]\ \\ - An array that will hold the positional values for all requested axes. -\item [\textit{numaxes}]\ \\ - Specifies how many axes should be returned. -\end{description} -\end{refparameters} - -\begin{refreturn} -The function returns the number of actually returned axes. This is the -minimum of \textit{numaxes} and the number of axes supported by the -joystick. If the joystick is not supported or connected, the function will -return 0 (zero). -\end{refreturn} - -\begin{refdescription} -This function queries the current position of one or more axes of a -joystick. The positional values are returned in an array, where the first -element represents the first axis of the joystick (normally the X axis). -Each position is in the range -1.0 to 1.0. Where applicable, the positive -direction of an axis is right, forward or up, and the negative direction -is left, back or down. - -If \textit{numaxes} exceeds the number of axes supported by the joystick, -or if the joystick is not available, the unused elements in the -\textit{pos} array will be set to 0.0 (zero). -\end{refdescription} - -\begin{refnotes} -The joystick state is updated every time the function is called, so there -is no need to call \textbf{glfwPollEvents} or \textbf{glfwWaitEvents} for -joystick state to be updated. - -Use \textbf{glfwGetJoystickParam} to retrieve joystick capabilities, such -as joystick availability and number of supported axes. - -No window has to be opened for joystick input to be available. -\end{refnotes} - - -%------------------------------------------------------------------------- -\subsection{glfwGetJoystickButtons} - -\textbf{C language syntax} -\begin{lstlisting} -int glfwGetJoystickButtons(int joy, unsigned char* buttons, - int numbuttons) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{joy}]\ \\ - A joystick identifier, which should be GLFW\_JOYSTICK\_\textit{n}, where - \textit{n} is in the range 1 to 16. -\item [\textit{buttons}]\ \\ - An array that will hold the button states for all requested buttons. -\item [\textit{numbuttons}]\ \\ - Specifies how many buttons should be returned. -\end{description} -\end{refparameters} - -\begin{refreturn} -The function returns the number of actually returned buttons. This is the -minimum of \textit{numbuttons} and the number of buttons supported by the -joystick. If the joystick is not supported or connected, the function will -return 0 (zero). -\end{refreturn} - -\begin{refdescription} -This function queries the current state of one or more buttons of a -joystick. The button states are returned in an array, where the first -element represents the first button of the joystick. Each state can be -either GLFW\_PRESS or GLFW\_RELEASE. - -If \textit{numbuttons} exceeds the number of buttons supported by the -joystick, or if the joystick is not available, the unused elements in the -\textit{buttons} array will be set to GLFW\_RELEASE. -\end{refdescription} - -\begin{refnotes} -The joystick state is updated every time the function is called, so there -is no need to call \textbf{glfwPollEvents} or \textbf{glfwWaitEvents} for -joystick state to be updated. - -Use \textbf{glfwGetJoystickParam} to retrieve joystick capabilities, such -as joystick availability and number of supported buttons. - -No window has to be opened for joystick input to be available. -\end{refnotes} - - -%------------------------------------------------------------------------- -\pagebreak -\section{Timing} - -%------------------------------------------------------------------------- -\subsection{glfwGetTime} - -\textbf{C language syntax} -\begin{lstlisting} -double glfwGetTime(void) -\end{lstlisting} - -\begin{refparameters} -none -\end{refparameters} - -\begin{refreturn} -The function returns the value of the high precision timer. The time is -measured in seconds, and is returned as a double precision floating point -value. -\end{refreturn} - -\begin{refdescription} -This function returns the state of a high precision timer. Unless the timer -has been set by the \textbf{glfwSetTime} function, the time is measured as -the number of seconds that have passed since \textbf{glfwInit} was called. -\end{refdescription} - -\begin{refnotes} -The resolution of the timer depends on which system the program is running -on. -\end{refnotes} - - -%------------------------------------------------------------------------- -\subsection{glfwSetTime} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwSetTime(double time) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{time}]\ \\ - Time (in seconds) that the timer should be set to. -\end{description} -\end{refparameters} - -\begin{refreturn} -none -\end{refreturn} - -\begin{refdescription} -This function sets the current time of the high precision timer to the -specified time. Subsequent calls to \textbf{glfwGetTime} will be relative -to this time. The time is given in seconds. -\end{refdescription} - - -%------------------------------------------------------------------------- -\pagebreak -\section{OpenGL Extension Support} -One of the great features of \OpenGL\ is its support for extensions, which -allow independent vendors to supply non-standard functionality in their -\OpenGL\ implementations. As the mechanism for querying extensions varies -among systems, \GLFW\ provides an operating system independent interface for -querying \OpenGL\ version, extensions and entry points. - - -%------------------------------------------------------------------------- -\subsection{glfwExtensionSupported} - -\textbf{C language syntax} -\begin{lstlisting} -int glfwExtensionSupported(const char* extension) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{extension}]\ \\ - A null terminated ISO~8859-1 string containing the name of an \OpenGL\ - extension. -\end{description} -\end{refparameters} - -\begin{refreturn} -The function returns GL\_TRUE if the extension is supported. Otherwise it -returns GL\_FALSE. -\end{refreturn} - -\begin{refdescription} -This function does a string search in the list of supported \OpenGL\ -extensions to find if the specified extension is listed. -\end{refdescription} - -\begin{refnotes} -An \OpenGL\ context must be created before this function can be called -(i.e. an \OpenGL\ window must have been opened with -\textbf{glfwOpenWindow}). - -In addition to checking for \OpenGL\ extensions, \GLFW\ also checks for -extensions in the operating system ``glue API'', such as WGL extensions -under Microsoft Windows and GLX extensions under the X Window System. -\end{refnotes} - - -%------------------------------------------------------------------------- -\subsection{glfwGetProcAddress} - -\textbf{C language syntax} -\begin{lstlisting} -void* glfwGetProcAddress(const char* procname) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{procname}]\ \\ - A null terminated ISO~8859-1 string containing the name of an \OpenGL\ - extension function. -\end{description} -\end{refparameters} - -\begin{refreturn} -The function returns the address of the specified \OpenGL\ function, if it -is available. Otherwise NULL is returned. -\end{refreturn} - -\begin{refdescription} -This function acquires the pointer to an \OpenGL\ extension function. Some -(but not all) \OpenGL\ extensions define new API functions, which are -usually not available through normal linking. It is therefore necessary to -get access to those API functions at runtime. -\end{refdescription} - -\begin{refnotes} -An \OpenGL\ context must be created before this function can be called -(i.e. an \OpenGL\ window must have been opened with -\textbf{glfwOpenWindow}). - -Some systems do not support dynamic function pointer retrieval, in which -case \textbf{glfwGetProcAddress} will always return NULL. -\end{refnotes} - - -%------------------------------------------------------------------------- -\subsection{glfwGetGLVersion} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwGetGLVersion(int* major, int* minor, int* rev) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{major}]\ \\ - Pointer to an integer that will hold the major version number. -\item [\textit{minor}]\ \\ - Pointer to an integer that will hold the minor version number. -\item [\textit{rev}]\ \\ - Pointer to an integer that will hold the revision. -\end{description} -\end{refparameters} - -\begin{refreturn} -The function returns the major and minor version numbers and the revision -for the currently used \OpenGL\ implementation. -\end{refreturn} - -\begin{refdescription} -This function returns the \OpenGL\ implementation version. This is a -convenient function that parses the version number information at the beginning -of the string returned by calling \texttt{glGetString(~GL\_VERSION~)}. The -\OpenGL\ version information can be used to determine what functionality is -supported by the used \OpenGL\ implementation. -\end{refdescription} - -\begin{refnotes} -An \OpenGL\ context must be created before this function can be called -(i.e. an \OpenGL\ window must have been opened with -\textbf{glfwOpenWindow}). -\end{refnotes} - - -%------------------------------------------------------------------------- -\pagebreak -\section{Miscellaneous} - - -%------------------------------------------------------------------------- -\subsection{glfwEnable/glfwDisable} - -\textbf{C language syntax} -\begin{lstlisting} -void glfwEnable(int token) -void glfwDisable(int token) -\end{lstlisting} - -\begin{refparameters} -\begin{description} -\item [\textit{token}]\ \\ - A value specifying a feature to enable or disable. Valid tokens are - listed in table \ref{tab:enable}. -\end{description} -\end{refparameters} - -\begin{refreturn} -none -\end{refreturn} - -\begin{refdescription} -\textbf{glfwEnable} is used to enable a certain feature, while -\textbf{glfwDisable} is used to disable it. Below follows a description of -each feature. -\end{refdescription} - - -\begin{table}[p] -\begin{center} -\begin{tabular}{|l|p{5.0cm}|p{3.0cm}|} \hline \raggedright -\textbf{Name} & \textbf{Controls} & \textbf{Default}\\ \hline -\hyperlink{lnk:autopollevents}{GLFW\_AUTO\_POLL\_EVENTS} & Automatic event polling when \textbf{glfwSwapBuffers} is called & Enabled\\ \hline -\hyperlink{lnk:keyrepeat}{GLFW\_KEY\_REPEAT} & Keyboard key repeat & Disabled\\ \hline -\hyperlink{lnk:mousecursor}{GLFW\_MOUSE\_CURSOR} & Mouse cursor visibility & Enabled in windowed mode. Disabled in fullscreen mode.\\ \hline -\hyperlink{lnk:stickykeys}{GLFW\_STICKY\_KEYS} & Keyboard key ``stickiness'' & Disabled\\ \hline -\hyperlink{lnk:stickymousebuttons}{GLFW\_STICKY\_MOUSE\_BUTTONS} & Mouse button ``stickiness'' & Disabled\\ \hline -\hyperlink{lnk:systemkeys}{GLFW\_SYSTEM\_KEYS} & Special system key actions & Enabled\\ \hline -\end{tabular} -\end{center} -\caption{Tokens for \textbf{glfwEnable}/\textbf{glfwDisable}} -\label{tab:enable} -\end{table} - - -\bigskip\begin{mysamepage}\hypertarget{lnk:autopollevents}{} -\textbf{GLFW\_AUTO\_POLL\_EVENTS}\\ -When GLFW\_AUTO\_POLL\_EVENTS is enabled, \textbf{glfwPollEvents} is -automatically called each time that \textbf{glfwSwapBuffers} is called, -immediately after the buffer swap itself. - -When GLFW\_AUTO\_POLL\_EVENTS is disabled, calling -\textbf{glfwSwapBuffers} will not result in a call to -\textbf{glfwPollEvents}. This can be useful if for example \textbf{glfwSwapBuffers} -needs to be called from within a callback function, since calling -\textbf{glfwPollEvents} from a callback function is not allowed. -\end{mysamepage} - - -\bigskip\begin{mysamepage}\hypertarget{lnk:keyrepeat}{} -\textbf{GLFW\_KEY\_REPEAT}\\ -When GLFW\_KEY\_REPEAT is enabled, the key and character callback -functions are called repeatedly when a key is held down long enough -(according to the system key repeat configuration). - -When GLFW\_KEY\_REPEAT is disabled, the key and character callback -functions are only called once when a key is pressed (and once when it is -released). -\end{mysamepage} - - -\bigskip\begin{mysamepage}\hypertarget{lnk:mousecursor}{} -\textbf{GLFW\_MOUSE\_CURSOR}\\ -When GLFW\_MOUSE\_CURSOR is enabled, the mouse cursor is visible, and -mouse coordinates are relative to the upper left corner of the client area -of the \GLFW\ window. The coordinates are limited to the client area of -the window. - -When GLFW\_MOUSE\_CURSOR is disabled, the mouse cursor is invisible, and -mouse coordinates are not limited to the drawing area of the window. It is -as if the mouse coordinates are received directly from the mouse, without -being restricted or manipulated by the windowing system. -\end{mysamepage} - - -\bigskip\begin{mysamepage}\hypertarget{lnk:stickykeys}{} -\textbf{GLFW\_STICKY\_KEYS}\\ -When GLFW\_STICKY\_KEYS is enabled, keys which are pressed will not be -released until they are physically released and checked with -\textbf{glfwGetKey}. This behavior makes it possible to catch keys that -were pressed and then released again between two calls to -\textbf{glfwPollEvents}, \textbf{glfwWaitEvents} or -\textbf{glfwSwapBuffers}, which would otherwise have been reported as -released. Care should be taken when using this mode, since keys that are -not checked with \textbf{glfwGetKey} will never be released. Note also -that enabling GLFW\_STICKY\_KEYS does not affect the behavior of the -keyboard callback functionality. - -When GLFW\_STICKY\_KEYS is disabled, the status of a key that is reported -by \textbf{glfwGetKey} is always the physical state of the key. Disabling -GLFW\_STICKY\_KEYS also clears the sticky information for all keys. -\end{mysamepage} - - -\bigskip\begin{mysamepage}\hypertarget{lnk:stickymousebuttons}{} -\textbf{GLFW\_STICKY\_MOUSE\_BUTTONS}\\ -When GLFW\_STICKY\_MOUSE\_BUTTONS is enabled, mouse buttons that are pressed -will not be released until they are physically released and checked with -\textbf{glfwGetMouseButton}. This behavior makes it possible to catch mouse -buttons which were pressed and then released again between two calls to -\textbf{glfwPollEvents}, \textbf{glfwWaitEvents} or \textbf{glfwSwapBuffers} -(with GLFW\_AUTO\_POLL\_EVENTS enabled), which would otherwise have been -reported as released. Care should be taken when using this mode, since mouse -buttons that are not checked with \textbf{glfwGetMouseButton} will never be -released. Note also that enabling GLFW\_STICKY\_MOUSE\_BUTTONS does not affect -the behavior of the mouse button callback functionality. - -When GLFW\_STICKY\_MOUSE\_BUTTONS is disabled, the status of a mouse -button that is reported by \textbf{glfwGetMouseButton} is always the -physical state of the mouse button. Disabling GLFW\_STICKY\_MOUSE\_BUTTONS -also clears the sticky information for all mouse buttons. -\end{mysamepage} - - -\bigskip\begin{mysamepage}\hypertarget{lnk:systemkeys}{} -\textbf{GLFW\_SYSTEM\_KEYS}\\ -When GLFW\_SYSTEM\_KEYS is enabled, pressing standard system key -combinations, such as \texttt{Alt+Tab} under Windows, will give the normal -behavior. Note that when \texttt{Alt+Tab} is issued under Windows in this -mode so that the \GLFW\ application is deselected when \GLFW\ is operating -in fullscreen mode, the \GLFW\ application window will be minimized and -the video mode will be set to the original desktop mode. When the \GLFW\ -application is re-selected, the video mode will be set to the \GLFW\ video -mode again. - -When GLFW\_SYSTEM\_KEYS is disabled, pressing standard system key -combinations will have no effect, since those key combinations are blocked -by \GLFW . This mode can be useful in situations when the \GLFW\ program -must not be interrupted (normally for games in fullscreen mode). -\end{mysamepage} - - -%------------------------------------------------------------------------- -% GLFW Standards Conformance -%------------------------------------------------------------------------- -\appendix -\chapter{GLFW Compatibility} -\label{chap:compatibility} -\thispagestyle{fancy} - -This chapter describes the various API extensions used by this version of -\GLFW . It lists what are essentially implementation details, but which are -nonetheless vital knowledge for developers wishing to deploy their applications -on machines with varied specifications. - -Note that the information in this appendix is not a part of the API -specification but merely list some of the preconditions for certain parts of -the API to function on a given machine. As such, any part of it may change in -future versions without this being considered a breaking API change. - -%------------------------------------------------------------------------- -\section{ICCCM and EWMH Conformance} - -As \GLFW\ uses \textbf{Xlib}, directly, without any intervening toolkit -library, it has sole responsibility for interacting well with the many and -varied window managers in use on Unix-like systems. In order for applications -and window managers to work well together, a number of standards and -conventions have been developed that regulate behavior outside the scope of the -X11 API; most importantly the \textbf{Inter-Client Communication Conventions -Manual} (ICCCM) and \textbf{Extended Window Manager Hints} (EWMH) standards. - -\GLFW\ uses the ICCCM \textbf{WM\_DELETE\_WINDOW} protocol to intercept the user -attempting to close the \GLFW\ window. If the running window manager does not -support this protocol, the close callback will never be called. - -\GLFW\ uses the EWMH \textbf{\_NET\_WM\_PING} protocol, allowing the window -manager notify the user when the application has stopped responding, i.e. when -it has ceased to process events. If the running window manager does not -support this protocol, the user will not be notified if the application locks -up. - -\GLFW\ uses the EWMH \textbf{\_NET\_WM\_STATE} protocol to tell the window -manager to make the \GLFW\ window fullscreen. If the running window manager -does not support this protocol, fullscreen windows may not work properly. -\GLFW\ has a fallback code path in case this protocol is unavailable, but every -window manager behaves slightly differently in this regard. - -%------------------------------------------------------------------------- -\section{GLX Extensions} - -The \textbf{GLX} API is used to create \OpenGL\ contexts on Unix-like systems -using the X Window System. - -\GLFW\ uses the \textbf{GLXFBConfig} API to enumerate and select framebuffer -pixel formats. This requires either \textbf{GLX} 1.3 or greater, or the -\textbf{GLX\_SGIX\_fbconfig} extension. Where both are available, the SGIX -extension is preferred. If neither is available, \GLFW\ will be unable to open -windows. - -% This paragraph repeated almost verbatim below -\GLFW\ uses the \textbf{GLX\_SGI\_swap\_control} extension to provide vertical -retrace synchronization (or ``vsync''). Where this extension is unavailable, -calling \textbf{glfwSwapInterval} will have no effect. - -% This paragraph repeated almost verbatim below -\GLFW\ uses the \textbf{GLX\_ARB\_multisample} extension to create contexts -with multisampling anti-aliasing. Where this extension is unavailable, the -GLFW\_FSAA\_SAMPLES hint will have no effect. - -% This paragraph repeated almost verbatim below -\GLFW\ uses the \textbf{GLX\_ARB\_create\_context} extension when available, -even when creating \OpenGL\ contexts of version 2.1 and below. Where this -extension is unavailable, the GLFW\_OPENGL\_VERSION\_MAJOR and -GLFW\_OPENGL\_VERSION\_MINOR hints will only be partially supported, the -GLFW\_OPENGL\_DEBUG\_CONTEXT hint will have no effect, and setting the -GLFW\_OPENGL\_PROFILE or GLFW\_FORWARD\_COMPAT hints to a non-zero value will -cause \textbf{glfwOpenWindow} to fail. - -% This paragraph repeated almost verbatim below -\GLFW\ uses the \textbf{GLX\_ARB\_create\_context\_profile} extension to -provide support for context profiles. Where this extension is unavailable, -setting the GLFW\_OPENGL\_PROFILE hint to anything but zero will cause -\textbf{glfwOpenWindow} to fail. - -%------------------------------------------------------------------------- -\section{WGL Extensions} - -The \textbf{WGL} API is used to create \OpenGL\ contexts on Microsoft Windows -and other implementations of the Win32 API, such as Wine. - -\GLFW\ uses either the \textbf{WGL\_EXT\_extension\_string} or the -\textbf{WGL\_ARB\_extension\_string} extension to check for the presence of all -other \textbf{WGL} extensions listed below. If both are available, the EXT one -is preferred. If neither is available, no other extensions are used and many -\GLFW\ features related to context creation will have no effect or cause errors -when used. - -% This paragraph repeated almost verbatim above -\GLFW\ uses the \textbf{WGL\_EXT\_swap\_control} extension to provide vertical -retrace synchronization (or ``vsync''). Where this extension is unavailable, -calling \textbf{glfwSwapInterval} will have no effect. - -% This paragraph repeated almost verbatim above -\GLFW\ uses the \textbf{WGL\_ARB\_pixel\_format} and -\textbf{WGL\_ARB\_multisample} extensions to create contexts with multisampling -anti-aliasing. Where these extensions are unavailable, the GLFW\_FSAA\_SAMPLES -hint will have no effect. - -% This paragraph repeated almost verbatim above -\GLFW\ uses the \textbf{WGL\_ARB\_create\_context} extension when available, -even when creating \OpenGL\ contexts of version 2.1 and below. Where this -extension is unavailable, the GLFW\_OPENGL\_VERSION\_MAJOR and -GLFW\_OPENGL\_VERSION\_MINOR hints will only be partially supported, the -GLFW\_OPENGL\_DEBUG\_CONTEXT hint will have no effect, and setting the -GLFW\_OPENGL\_PROFILE or GLFW\_FORWARD\_COMPAT hints to a non-zero value will -cause \textbf{glfwOpenWindow} to fail. - -% This paragraph repeated almost verbatim above -\GLFW\ uses the \textbf{WGL\_ARB\_create\_context\_profile} extension to -provide support for context profiles. Where this extension is unavailable, -setting the GLFW\_OPENGL\_PROFILE hint to anything but zero will cause -\textbf{glfwOpenWindow} to fail. - -%------------------------------------------------------------------------- -\section{OpenGL 3.0+ on Mac OS X} - -At the time of writing, Mac OS X does not support OpenGL 3.0 or above. -Because of this, the GLFW\_OPENGL\_VERSION\_MAJOR and -GLFW\_OPENGL\_VERSION\_MINOR hints will fail if given a version above 2.1, the -GLFW\_OPENGL\_DEBUG\_CONTEXT hint will have no effect, and setting the -GLFW\_OPENGL\_PROFILE or GLFW\_FORWARD\_COMPAT hints to a non-zero value will -cause \textbf{glfwOpenWindow} to fail. - - -\end{document} diff --git a/docs/glfwug.tex b/docs/glfwug.tex deleted file mode 100644 index 4f769a2c..00000000 --- a/docs/glfwug.tex +++ /dev/null @@ -1,1313 +0,0 @@ -%------------------------------------------------------------------------- -% GLFW Users Guide -% API Version: 3.0 -%------------------------------------------------------------------------- - -% Document class -\documentclass[a4paper,11pt,oneside]{report} - -% Document title and API version -\newcommand{\glfwdoctype}[1][0]{Users Guide} -\newcommand{\glfwapiver}[1][0]{3.0} - -% Common document settings and macros -\input{glfwdoc.sty} - -% PDF specific document settings -\hypersetup{pdftitle={GLFW Users Guide}} -\hypersetup{pdfauthor={Marcus Geelnard}} -\hypersetup{pdfkeywords={GLFW,OpenGL,guide,manual}} - - -%------------------------------------------------------------------------- -% Document body -%------------------------------------------------------------------------- - -\begin{document} - -\pagestyle{plain} - -% Title page -\glfwmaketitle - -% Summary, trademarks and table of contents -\pagenumbering{roman} -\setcounter{page}{1} - -%------------------------------------------------------------------------- -% Summary and Trademarks -%------------------------------------------------------------------------- -\chapter*{Summary} - -This document is a users guide for the \GLFW\ API that gives a practical -introduction to using \GLFW . For a more detailed description of the -\GLFW\ API you should refer to the \textit{GLFW Reference Manual}. -\vspace{5cm} - -\large -Trademarks - -\small -OpenGL and IRIX are registered trademarks of Silicon Graphics, Inc.\linebreak -Microsoft and Windows are registered trademarks of Microsoft Corporation.\linebreak -Mac OS is a registered trademark of Apple Computer, Inc.\linebreak -Linux is a registered trademark of Linus Torvalds.\linebreak -FreeBSD is a registered trademark of Wind River Systems, Inc.\linebreak -Solaris is a trademark of Sun Microsystems, Inc.\linebreak -UNIX is a registered trademark of The Open Group.\linebreak -X Window System is a trademark of The Open Group.\linebreak -POSIX is a trademark of IEEE.\linebreak -Truevision, TARGA and TGA are registered trademarks of Truevision, Inc.\linebreak -IBM is a registered trademark of IBM Corporation.\linebreak - -All other trademarks mentioned in this document are the property of their respective owners. -\normalsize - - -%------------------------------------------------------------------------- -% Table of contents -%------------------------------------------------------------------------- -\tableofcontents -\pagebreak - - -% Document chapters starts here... -\pagenumbering{arabic} -\setcounter{page}{1} - -\pagestyle{fancy} - - -%------------------------------------------------------------------------- -% Introduction -%------------------------------------------------------------------------- -\chapter{Introduction} -\thispagestyle{fancy} -\GLFW\ is a portable API (Application Program Interface) that handles -operating system specific tasks related to \OpenGL\ programming. While -\OpenGL\ in general is portable, easy to use and often results in tidy and -compact code, the operating system specific mechanisms that are required -to set up and manage an \OpenGL\ window are quite the opposite. \GLFW\ tries -to remedy this by providing the following functionality: - -\begin{itemize} -\item Opening and managing an \OpenGL\ window. -\item Keyboard, mouse and joystick input. -\item High precision time input. -\item Support for querying and using \OpenGL\ extensions. -\end{itemize} -\vspace{18pt} - -All this functionality is implemented as a set of easy-to-use functions, -which makes it possible to write an \OpenGL\ application framework in just a -few lines of code. The \GLFW\ API is operating system and platform independent, -making it very simple to port \GLFW\ based \OpenGL\ applications between the -supported platforms. - -Currently supported platforms are: -\begin{itemize} -\item Microsoft Windows\textsuperscript{\textregistered} -\item Unix\textsuperscript{\textregistered} or Unix­-like systems running the -X Window System\texttrademark with GLX version 1.3 or later -\item Mac OS X\textsuperscript{\textregistered} 10.5 and later, using Cocoa\footnote{Support for joysticks missing at the time of writing.} -\end{itemize} - -There is also deprecated support for Mac OS X versions 10.3 and 10.4, using the Carbon API. - - -%------------------------------------------------------------------------- -% Getting Started -%------------------------------------------------------------------------- -\chapter{Getting Started} -\thispagestyle{fancy} -In this chapter you will learn how to write a simple \OpenGL\ application -using \GLFW . We start by initializing \GLFW , then we open a window and -read some user keyboard input. - - -%------------------------------------------------------------------------- -\section{Initializing GLFW} -Before using any of the \GLFW\ functions, it is necessary to call -\textbf{glfwInit}. It initializes the parts of \GLFW\ that are not dependent on -a window, such as time and joystick input. The C syntax is: - -\begin{lstlisting} -int glfwInit(void) -\end{lstlisting} - -\textbf{glfwInit} returns GL\_TRUE if initialization succeeded, or -GL\_FALSE if it failed. - -When your application is done using \GLFW , typically at the very end of -the program, you should call \textbf{glfwTerminate}. The C syntax is: - -\begin{lstlisting} -void glfwTerminate(void) -\end{lstlisting} - -This releases any resources allocated by GLFW and closes the window if it is -open. After this call, you must call \textbf{glfwInit} again before using any -\GLFW\ functions). - -%------------------------------------------------------------------------- -\section{Opening An OpenGL Window} -Opening an \OpenGL\ window is done with the \textbf{glfwOpenWindow} function. -The function takes nine arguments, which are used to describe the following -properties of the requested window: - -\begin{itemize} -\item Window dimensions (width and height) in pixels. -\item Color and alpha buffer bit depth. -\item Depth buffer (Z-buffer) bit depth. -\item Stencil buffer bit depth. -\item Whether to use fullscreen or windowed mode. -\end{itemize} - -The C language syntax for \textbf{glfwOpenWindow} is: -\begin{lstlisting} -int glfwOpenWindow(int width, int height, - int redbits, int greenbits, int bluebits, - int alphabits, int depthbits, int stencilbits, - int mode) -\end{lstlisting} - -\textbf{glfwOpenWindow} returns GL\_TRUE if the window was opened -correctly, or GL\_FALSE if \GLFW\ failed to open the window. - -\GLFW\ tries to open a window that best matches the requested parameters. -Some parameters may be omitted by setting them to zero, which will result -in \GLFW\ either using a default value, or the related functionality to be -disabled. For instance, if \textit{width} and \textit{height} are both -zero, \GLFW\ will use a window resolution of 640x480. If -\textit{depthbits} is zero, the opened window may not have a depth buffer. - -The \textit{mode} argument is used to specify if the window is to be a -fullscreen window or a regular window. - -If \textit{mode} is GLFW\_FULLSCREEN, the window will cover the entire -screen and no window border or decorations will be visible. If possible, the -video mode will be changed to the mode that closest matches the \textit{width}, -\textit{height}, \textit{redbits}, \textit{greenbits}, \textit{bluebits} and -\textit{alphabits} arguments. Furthermore, the mouse pointer will be hidden, -and screensavers are prohibited. This is usually the best mode for games and -demos. - -If \textit{mode} is GLFW\_WINDOW, the window will be opened as a normal, -decorated window on the desktop. The mouse pointer will not be hidden and -screensavers are allowed to be activated. - -To close the window, you can either use \textbf{glfwTerminate}, as -described earlier, or you can use the more explicit approach by calling -\textbf{glfwCloseWindow}, which has the C syntax: - -\begin{lstlisting} -void glfwCloseWindow(void) -\end{lstlisting} - -Note that you do not need to call \textbf{glfwTerminate} and \textbf{glfwInit} -before opening a new window after having closed the current one using -\textbf{glfwCloseWindow}. - - -%------------------------------------------------------------------------- -\section{Using Keyboard Input} -\GLFW\ provides several means for receiving user input, which will be -discussed in more detail in chapter \ref{par:inputhandling}. One of the -simplest ways of checking for keyboard input is to use the function -\textbf{glfwGetKey}: - -\begin{lstlisting} -int glfwGetKey(int key) -\end{lstlisting} - -It queries the current status of individual keyboard keys. The argument -\textit{key} specifies which key to check, and it must be a valid GLFW key code -(see the \textit{GLFW Reference Manual} for a list of key codes). -\textbf{glfwGetKey} returns GLFW\_PRESS if the key is currently held down, or -GLFW\_RELEASE if the key is not being held down. For example: - -\begin{lstlisting} -A_pressed = glfwGetKey(GLFW_KEY_A); -esc_pressed = glfwGetKey(GLFW_KEY_ESCAPE); -\end{lstlisting} - -In order for \textbf{glfwGetKey} to have any effect, you need to poll for -input events on a regular basis. This can be done in one of two ways: - -\begin{enumerate} -\item Implicitly by calling \textbf{glfwSwapBuffers} often. -\item Explicitly by calling \textbf{glfwPollEvents} often. -\end{enumerate} - -In general you do not have to care about this, since you will normally -call \textbf{glfwSwapBuffers} to swap front and back rendering buffers -every animation frame anyway. If, however, this is not the case, you -should call \textbf{glfwPollEvents} in the order of 10-100 times per -second in order for \GLFW\ to maintain an up to date input state. - - -%------------------------------------------------------------------------- -\section{Putting It Together: A Minimal GLFW Application} -Now that you know how to initialize \GLFW , open a window and poll for -keyboard input, let us exemplify this with a simple \OpenGL\ program: - -\begin{lstlisting} -#include -#include - -int main(void) -{ - int running = GL_TRUE; - - // Initialize GLFW - if (!glfwInit()) - exit(EXIT_FAILURE); - - // Open an OpenGL window - if (!glfwOpenWindow(300,300, 0,0,0,0,0,0, GLFW_WINDOW)) - { - glfwTerminate(); - exit(EXIT_FAILURE); - } - - // Main loop - while (running) - { - // OpenGL rendering goes here... - glClear(GL_COLOR_BUFFER_BIT); - - // Swap front and back rendering buffers - glfwSwapBuffers(); - - // Check if ESC key was pressed or window was closed - running = !glfwGetKey(GLFW_KEY_ESCAPE) && - glfwGetWindowParam(GLFW_OPENED); - } - - // Close window and terminate GLFW - glfwTerminate(); - - // Exit program - exit(EXIT_SUCCESS); -} -\end{lstlisting} - -The program opens a 300x300 window and runs in a loop until the escape key -is pressed, or the window was closed. All the \OpenGL\ ``rendering'' that -is done in this example is to clear the window. - - -%------------------------------------------------------------------------- -% Window Operations -%------------------------------------------------------------------------- -\chapter{Window Operations} -\thispagestyle{fancy} -In this chapter, you will learn more about window related \GLFW\ -functionality, including setting and getting window properties, buffer -swap control and video mode querying. - - -%------------------------------------------------------------------------- -\section{Setting Window Properties} -In the previous chapter the \textbf{glfwOpenWindow} function was -described, which specifies the sizes of the color, alpha, depth and -stencil buffers. It is also possible to request a specific minimum OpenGL -version, multisampling anti-aliasing, an accumulation buffer, stereo -rendering and more by using the \textbf{glfwOpenWindowHint} function: - -\begin{lstlisting} -void glfwOpenWindowHint(int target, int hint) -\end{lstlisting} - -The \textit{target} argument can be one of the constants listed in table~ -\ref{tab:winhints}, and \textit{hint} is the value to assign to the -specified target. - -%------------------------------------------------------------------------- -\begin{table}[p] -\begin{center} -\begin{tabular}{|l|l|p{7.0cm}|} \hline \raggedright -\textbf{Name} & \textbf{Default} & \textbf{Description} \\ \hline -GLFW\_REFRESH\_RATE & 0 & Vertical monitor refresh rate in Hz (only used for fullscreen windows). Zero means system default.\\ \hline -GLFW\_ACCUM\_RED\_BITS & 0 & Number of bits for the red channel of the accumulation buffer.\\ \hline -GLFW\_ACCUM\_GREEN\_BITS & 0 & Number of bits for the green channel of the accumulation buffer.\\ \hline -GLFW\_ACCUM\_BLUE\_BITS & 0 & Number of bits for the blue channel of the accumulation buffer.\\ \hline -GLFW\_ACCUM\_ALPHA\_BITS & 0 & Number of bits for the alpha channel of the accumulation buffer.\\ \hline -GLFW\_AUX\_BUFFERS & 0 & Number of auxiliary buffers.\\ \hline -GLFW\_STEREO & GL\_FALSE & Specify if stereo rendering should be supported (can be GL\_TRUE or GL\_FALSE).\\ \hline -GLFW\_WINDOW\_NO\_RESIZE & GL\_FALSE & Specify whether the window can be resized by the user (not used for fullscreen windows).\\ \hline -GLFW\_FSAA\_SAMPLES & 0 & Number of samples to use for the multisampling buffer. Zero disables multisampling.\\ \hline -GLFW\_OPENGL\_VERSION\_MAJOR & 1 & Major number of the desired minimum OpenGL version.\\ \hline -GLFW\_OPENGL\_VERSION\_MINOR & 1 & Minor number of the desired minimum OpenGL version.\\ \hline -GLFW\_OPENGL\_FORWARD\_COMPAT & GL\_FALSE & Specify whether the OpenGL context should be forward-compatible (i.e. disallow legacy functionality). - This should only be used when requesting OpenGL version 3.0 or above.\\ \hline -GLFW\_OPENGL\_DEBUG\_CONTEXT & GL\_FALSE & Specify whether a debug context should be created.\\ \hline -GLFW\_OPENGL\_PROFILE & 0 & The OpenGL profile the context should implement, or zero to let the system choose. - Available profiles are GLFW\_OPENGL\_CORE\_PROFILE and GLFW\_OPENGL\_COMPAT\_PROFILE.\\ \hline -\end{tabular} -\end{center} -\caption{Targets for \textbf{glfwOpenWindowHint}} -\label{tab:winhints} -\end{table} -%------------------------------------------------------------------------- - -For a hint to have any effect, the \textbf{glfwOpenWindowHint} function -must be called before opening the window with the \textbf{glfwOpenWindow} -function. - -To request an accumulation buffer, set the GLFW\_ACCUM\_x\_BITS targets to -values greater than zero (usually eight or sixteen bits per component). -To request auxiliary buffers, set the GLFW\_AUX\_BUFFERS target to a value -greater than zero. To request a stereo rendering capable window, set the -GLFW\_STEREO target to GL\_TRUE. - -If you want to enable fullscreen antialiasing, set the GLFW\_FSAA\_SAMPLES -target to a value greater than zero. If the windowing system is unable to -fulfil the request, \GLFW\ will degrade gracefully and disable FSAA if necessary. - -The GLFW\_REFRESH\_RATE target should be used with caution, since it may -result in suboptimal operation, or even a blank or damaged screen. - -If you want to create a forward-compatible \OpenGL\ context, set the -GLFW\_OPENGL\_FORWARD\_COMPAT hint to GL\_TRUE. Note that such contexts are -only available for \OpenGL\ version 3.0 and above, so you will need to specify -a valid minimum version using the GLFW\_OPENGL\_VERSION\_MAJOR and -GLFW\_OPENGL\_VERSION\_MINOR hints. - -If you want to create a context using the core profile as available in \OpenGL\ -version 3.2 and above, set the GLFW\_OPENGL\_PROFILE hint accordingly. Note that -as above you have to set a valid minimum version for this to work. - -Also note that at the time of this release, Mac OS X did not support \OpenGL\ -version 3.0 or above; thus GLFW cannot create contexts of versions above 2.1 -on that platform. - -Besides the parameters that are given with the \textbf{glfwOpenWindow} and -\textbf{glfwOpenWindowHint} functions, a few more properties of a window -can be changed after the window has been opened, namely the window title, -window size, and window position. - -To change the window title of an open window, use the -\textbf{glfwSetWindowTitle} function: - -\begin{lstlisting} -void glfwSetWindowTitle(const char* title) -\end{lstlisting} - -\textit{title} is a null terminated ISO~8859-1 (8-bit Latin~1) string that -will be used as the window title. It will also be used as the application -name (for instance in the application list when using \texttt{Alt+Tab} -under Windows, or as the icon name when the window is iconified under -the X Window System). The default window name is ``GLFW Window'', which -will be used unless \textbf{glfwSetWindowTitle} is called after the window -has been opened. - -To change the size of a window, call \textbf{glfwSetWindowSize}: - -\begin{lstlisting} -void glfwSetWindowSize(int width, int height) -\end{lstlisting} - -Where \textit{width} and \textit{height} are the new dimensions of the -window. - -To change the position of a window, call \textbf{glfwSetWindowPos}: - -\begin{lstlisting} -void glfwSetWindowPos(int x, int y) -\end{lstlisting} - -Where \textit{x} and \textit{y} are the new desktop coordinates of the -window. This function does not have any effect when in fullscreen mode. - - -%------------------------------------------------------------------------- -\section{Getting Window Properties} -When opening a window, the opened window will not necessarily have the -requested properties, so you should always check the parameters that your -application relies on (e.g. number of stencil bits) using -\textbf{glfwGetWindowParam}, which has the C syntax: - -\begin{lstlisting} -int glfwGetWindowParam(int param) -\end{lstlisting} - -The argument \textit{param} can be one of the tokens listed in table -\ref{tab:winparams}, and the return value is an integer holding the -requested value. - -%------------------------------------------------------------------------- -\begin{table}[p] -\begin{center} -\begin{tabular}{|l|p{9.5cm}|} \hline \raggedright -\textbf{Name} & \textbf{Description} \\ \hline -GLFW\_OPENED & GL\_TRUE if window is opened, else GL\_FALSE.\\ \hline -GLFW\_ACTIVE & GL\_TRUE if window has focus, else GL\_FALSE.\\ \hline -GLFW\_ICONIFIED & GL\_TRUE if window is iconified, else GL\_FALSE.\\ \hline -GLFW\_ACCELERATED & GL\_TRUE if window is hardware accelerated, else GL\_FALSE.\\ \hline -GLFW\_RED\_BITS & Number of bits for the red color component.\\ \hline -GLFW\_GREEN\_BITS & Number of bits for the green color component.\\ \hline -GLFW\_BLUE\_BITS & Number of bits for the blue color component.\\ \hline -GLFW\_ALPHA\_BITS & Number of bits for the alpha buffer.\\ \hline -GLFW\_DEPTH\_BITS & Number of bits for the depth buffer.\\ \hline -GLFW\_STENCIL\_BITS & Number of bits for the stencil buffer.\\ \hline -GLFW\_REFRESH\_RATE & Vertical monitor refresh rate in Hz. Zero indicates an unknown or a default refresh rate.\\ \hline -GLFW\_ACCUM\_RED\_BITS & Number of bits for the red channel of the accumulation buffer.\\ \hline -GLFW\_ACCUM\_GREEN\_BITS & Number of bits for the green channel of the accumulation buffer.\\ \hline -GLFW\_ACCUM\_BLUE\_BITS & Number of bits for the blue channel of the accumulation buffer.\\ \hline -GLFW\_ACCUM\_ALPHA\_BITS & Number of bits for the alpha channel of the accumulation buffer.\\ \hline -GLFW\_AUX\_BUFFERS & Number of auxiliary buffers.\\ \hline -GLFW\_STEREO & GL\_TRUE if stereo rendering is supported, else GL\_FALSE.\\ \hline -GLFW\_WINDOW\_NO\_RESIZE & GL\_TRUE if the window cannot be resized by the user, else GL\_FALSE.\\ \hline -GLFW\_FSAA\_SAMPLES & Number of multisampling buffer samples. Zero indicated multisampling is disabled.\\ \hline -GLFW\_OPENGL\_VERSION\_MAJOR & Major number of the actual version of the context.\\ \hline -GLFW\_OPENGL\_VERSION\_MINOR & Minor number of the actual version of the context.\\ \hline -GLFW\_OPENGL\_FORWARD\_COMPAT & GL\_TRUE if the context is forward-compatible, else GL\_FALSE.\\ \hline -GLFW\_OPENGL\_DEBUG\_CONTEXT & GL\_TRUE if the context is a debug context.\\ \hline -GLFW\_OPENGL\_PROFILE & The profile implemented by the context, or zero.\\ \hline -\end{tabular} -\end{center} -\caption{Window parameters for \textbf{glfwGetWindowParam}} -\label{tab:winparams} -\end{table} -%------------------------------------------------------------------------- - -Another useful function is \textbf{glfwSetWindowSizeCallback}, which -specifies a user function that will be called every time the window size -has changed. The C syntax is: - -\begin{lstlisting} -void glfwSetWindowSizeCallback(GLFWwindowsizefun cbfun) -\end{lstlisting} - -The user function \textit{fun} should be of the type: - -\begin{lstlisting} -void fun(int width, int height) -\end{lstlisting} - -The first argument passed to the user function is the width of the window, -and the second argument is the height of the window. Here is an example -of how to use a window size callback function: - -\begin{lstlisting} -int windowWidth, windowHeight; - -void WindowResize(int width, int height) -{ - windowWidth = width; - windowHeight = height; -} - -int main(void) -{ - ... - glfwSetWindowSizeCallback(WindowResize); - ... -} -\end{lstlisting} - -Using a callback function for getting the window size is mostly useful for -windowed applications, since the window size may be changed at any time by -the user. It can also be used to determine the actual fullscreen -resolution. - -An alternative to using a callback function for getting the window size, -is to use the function \textbf{glfwGetWindowSize}: - -\begin{lstlisting} -void glfwGetWindowSize(int* width, int* height) -\end{lstlisting} - -The variables pointed to by \textit{width} and \textit{height} are set to the -current window dimensions. Note that either of these may be NULL; that -argument is then ignored. - - -%------------------------------------------------------------------------- -\section{Buffer Swapping} -\GLFW\ windows are always double buffered. That means that you have two -rendering buffers; a front buffer and a back buffer. The front buffer is -the buffer that is being displayed, and the back buffer is not displayed. -\OpenGL\ lets you select which of these two buffers you want to render to -(with the \textbf{glDrawBuffer} command), but the default (and preferred) -rendering buffer is the back buffer. This way you will avoid flickering -and artifacts caused by graphics being only partly drawn at the same time -as the video raster beam is displaying the graphics on the monitor. - -When an entire frame has been rendered to the back buffer, it is time to -swap the back and the front buffers in order to display the rendered -frame, and begin rendering a new frame. This is done with the command -\textbf{glfwSwapBuffers}. The C syntax is: - -\begin{lstlisting} -void glfwSwapBuffers(void) -\end{lstlisting} - -After swapping the front and back rendering buffers, \textbf{glfwSwapBuffers} -by default calls \textbf{glfwPollEvents}\footnote{This behavior can be disabled -by calling \textbf{glfwDisable} with the argument GLFW\_AUTO\_POLL\_EVENTS.}. -This is to ensure frequent polling of events, such as keyboard and mouse input, -and window reshaping events. Even if a given application does not use input -events, without frequent polling of events (at \emph{least} once every few -seconds), most modern window systems will flag the application as unresponsive -and may suggest that the user terminate it. - -Sometimes it can be useful to select when the buffer swap will occur. With -the function \textbf{glfwSwapInterval} it is possible to select the -minimum number of vertical retraces the video raster line should do before -swapping the buffers: - -\begin{lstlisting} -void glfwSwapInterval(int interval) -\end{lstlisting} - -If \textit{interval} is zero, the swap will take place immediately when -\textbf{glfwSwapBuffers} is called, without waiting for a vertical retrace -(also known as ``vsync off''). Otherwise at least \textit{interval} -retraces will pass between each buffer swap (also known as ``vsync on''). -Using a swap interval of zero can be useful for benchmarking purposes, -when it is not desirable to measure the time it takes to wait for the -vertical retrace. However, a swap interval of 1 generally gives better -visual quality. - -It should be noted that not all \OpenGL\ implementations and hardware support -this function, in which case \textbf{glfwSwapInterval} will have no effect. ATI -Radeon cards under Microsoft Windows are especially notorious in this regard. -Sometimes it is only possible to affect the swap interval through driver -settings (e.g. the display settings under Windows, or as an environment -variable setting under Unix). - - -%------------------------------------------------------------------------- -\section{Querying Video Modes} -Although \GLFW\ generally does a good job at selecting a suitable video -mode for you when you open a fullscreen window, it is sometimes useful to -know exactly which modes are available on a certain system. For example, -you may want to present the user with a list of video modes to select -from. To get a list of available video modes, you can use the function -\textbf{glfwGetVideoModes}: - -\begin{lstlisting} -int glfwGetVideoModes(GLFWvidmode* list, int maxcount) -\end{lstlisting} - -The argument \textit{list} is a vector of GLFWvidmode structures, and -\textit{maxcount} is the maximum number of video modes that your vector can -hold. \textbf{glfwGetVideoModes} will return the number of video modes detected -on the system, up to \textit{maxcount}. - -The GLFWvidmode structure looks like this: - -\begin{lstlisting} -typedef struct { - int Width, Height; // Video resolution - int RedBits; // Red bits per pixel - int GreenBits; // Green bits per pixel - int BlueBits; // Blue bits per pixel -} GLFWvidmode; -\end{lstlisting} - -Here is an example of retrieving all available video modes: - -\begin{lstlisting} -int nummodes; -GLFWvidmode list[200]; -nummodes = glfwGetVideoModes(list, 200); -\end{lstlisting} - -The returned list is sorted, first by color depth ($RedBits + GreenBits + -BlueBits$), and then by resolution ($Width\times Height$), with the -lowest resolution, fewest bits per pixel mode first. - -To get the desktop video mode, use the function -\textbf{glfwGetDesktopMode}: - -\begin{lstlisting} -void glfwGetDesktopMode(GLFWvidmode* mode) -\end{lstlisting} - -The function returns the resolution and color depth of the user desktop in -the mode structure. Note that the user desktop mode is independent of the -current video mode if a \GLFW\ fullscreen window has been opened. - - -%------------------------------------------------------------------------- -% Input Handling -%------------------------------------------------------------------------- -\chapter{Input Handling} -\label{par:inputhandling} -\thispagestyle{fancy} -In this chapter you will learn how to use keyboard, mouse and joystick -input, using either polling or callback functions. - - -%------------------------------------------------------------------------- -\section{Event Polling} -The first thing to know about input handling in \GLFW\ is that all -keyboard and mouse input is collected by checking for input events. This -has do be done manually by calling either \textbf{glfwPollEvents} or -\textbf{glfwSwapBuffers} (which implicitly calls \textbf{glfwPollEvents} -for you). Normally this is not a cause for concern, as -\textbf{glfwSwapBuffers} is called every frame, which should be often -enough (about 10-100 times per second for a normal \OpenGL\ application) that -the window will feel responsive. - -One exception is when an application is updating its view only in response to input. -In this case the \textbf{glfwWaitEvents} is useful, as it blocks the calling -thread until an event arrives. The refresh callback, set with -\textbf{glfwSetWindowRefreshCallback}, may also be useful for such -applications, especially on unbuffered window systems. - -If it is not desirable that \textbf{glfwPollEvents is} called implicitly -from \textbf{glfwSwapBuffers}, call \textbf{glfwDisable} with the argument -GLFW\_AUTO\_POLL\_EVENTS. - -Note that event polling is not needed for joystick input, since all -relevant joystick state is gathered every time a joystick function is -called. - - -%------------------------------------------------------------------------- -\section{Keyboard Input} -\GLFW\ provides three mechanisms for getting keyboard input: - -\begin{itemize} -\item Manually polling the state of individual keys. -\item Automatically receive new key state for any key, using a callback - function. -\item Automatically receive characters, using a callback function. -\end{itemize} - -Depending on what the keyboard input will be used for, different methods may be -preferred. The main difference between the two last methods is that while -characters are affected by modifier keys (such as shift), key state is -independent of any modifier keys. Also, special keys (such as function keys, -cursor keys and modifier keys) are not reported to the character callback -function. - -%------------------------------------------------------------------------- -\subsection{Key state} -To check if a key is held down or not at any given moment, use the -function \textbf{glfwGetKey}: - -\begin{lstlisting} -int glfwGetKey(int key) -\end{lstlisting} - -It queries the current status of individual keyboard keys. The argument -\textit{key} specifies which key to check, which must be a valid GLFW key code. -\textbf{glfwGetKey} returns GLFW\_PRESS (or 1) if the key is currently -held down, or GLFW\_RELEASE (or 0) if the key is not being held down. - -In most situations, it may be useful to know if a key has been pressed and -released between two calls to \textbf{glfwGetKey} (especially if the -animation is fairly slow, which may allow the user to press and release a -key between two calls to \textbf{glfwGetKey}). This can be accomplished by -enabling sticky keys, which is done by calling \textbf{glfwEnable} with -the argument GLFW\_STICKY\_KEYS, as in the following example: - -\begin{lstlisting} -glfwEnable(GLFW_STICKY_KEYS); -\end{lstlisting} - -When sticky keys are enabled, a key will not be released until it is -checked with \textbf{glfwGetKey}. To disable sticky keys, call -\textbf{glfwDisable} witht the argument GLFW\_STICKY\_KEYS. Then all keys -that are not currently held down will be released and future key releases -will take place immediately when the user releases the key without -waiting for \textbf{glfwGetKey} to check the key. By default sticky keys -are disabled. - -Sticky keys are often very useful and should be used in most cases where -\textbf{glfwGetKey} is used. There is however a danger involved with -enabling sticky keys, and that is that keys that are pressed by the user -but are not checked with \textbf{glfwGetKey}, may remain ``pressed'' for a -very long time. A typical situation where this may be dangerous is in a -program that consists of two or more sections (e.g. a menu section and a -game section). If the first section enables sticky keys but does not check -for keys which the second section checks for, there is a potential of -recording many key presses in the first section that will be detected in -the second section. To avoid this problem, always disable sticky keys -before leaving a section of a program. - -A usually better alternative to using \textbf{glfwGetKey} is to register a -keyboard input callback function with \textbf{glfwSetKeyCallback}: - -\begin{lstlisting} -void glfwSetKeyCallback(GLFWkeyfun cbfun) -\end{lstlisting} - -The argument \textit{fun} is a pointer to a callback function. The -callback function shall take two integer arguments. The first is the key -identifier, and the second is the new key state, which can be GLFW\_PRESS -or GLFW\_RELEASE. To unregister a callback function, call -\textbf{glfwSetKeyCallback} with \textit{fun} = NULL. - -Using the callback function, you can be sure not to miss any key press or -release events, regardless of how many may have occurred during the last frame. -It also encourages event-based design, where the application responds only to -actual events instead of having to poll for every supported event. - -%------------------------------------------------------------------------- -\subsection{Character input} -If the keyboard is to be used as a text input device (e.g. in a user -dialog) rather than as a set of independent buttons, a character callback -function is more suitable. To register a character callback function, use -\textbf{glfwSetCharCallback}: - -\begin{lstlisting} -void glfwSetCharCallback(GLFWcharfun cbfun) -\end{lstlisting} - -The argument \textit{fun} is a pointer to a callback function. The -callback function shall take two integer arguments. The first is a Unicode -code point, and the second is GLFW\_PRESS if the key that generated -the character was pressed, or GLFW\_RELEASE if it was released. To -unregister a callback function, call \textbf{glfwSetCharCallback} with -\textit{fun} = NULL. - -The Unicode character set is an international standard for encoding -characters. It is much more comprehensive than seven or eight bit -character sets (e.g. US-ASCII and Latin~1), and includes characters for -most written languages in the world. It should be noted that Unicode -character codes 0 to 255 are the same as for ISO~8859-1 (Latin~1), so as -long as a proper range check is performed on the Unicode character code, -it can be used just as an eight bit Latin~1 character code (which can be -useful if full Unicode support is not possible). - - -%------------------------------------------------------------------------- -\subsection{Key repeat} -By default, \GLFW\ does not report key repeats when a key is held down. -To activate key repeat, call \textbf{glfwEnable} with the argument -GLFW\_KEY\_REPEAT: - -\begin{lstlisting} -glfwEnable(GLFW_KEY_REPEAT); -\end{lstlisting} - -This will let a registered key or character callback function receive key -repeat events when a key is held down. - - -%------------------------------------------------------------------------- -\subsection{Special system keys} -On most systems there are some special system keys that are normally not -intercepted by an application. For instance, under Windows it is possible -to switch programs by pressing \texttt{ALT+TAB}, which brings up a list of -running programs to select from. In certain situations it can be desirable -to prevent such special system keys from interfering with the program. -With \GLFW\ it is possible to do by calling \textbf{glfwDisable} with the -argument GLFW\_SYSTEM\_KEYS: - -\begin{lstlisting} -glfwDisable(GLFW_SYSTEM_KEYS); -\end{lstlisting} - -By doing so, most system keys will have no effect and will not interfere -with your program. System keys can be re-enabled by calling -\textbf{glfwEnable} with the argument GLFW\_SYSTEM\_KEYS. By default, -system keys are enabled. - - -%------------------------------------------------------------------------- -\section{Mouse Input} -Just like for keyboard input, mouse input can be realized with either -polling or callback functions. - - -%------------------------------------------------------------------------- -\subsection{Mouse position} -To query the position of the mouse cursor, call \textbf{glfwGetMousePos}: - -\begin{lstlisting} -void glfwGetMousePos(int* x, int* y) -\end{lstlisting} - -The variables pointed to by \textit{x} and \textit{y} will be updated with the -current position of the mouse cursor relative to the upper-left corner of the -client area of the \GLFW\ window. - -An alternative is to use a callback function, which can be set with -\textbf{glfwSetMousePosCallback}: - -\begin{lstlisting} -void glfwSetMousePosCallback(GLFWmouseposfun cbfun) -\end{lstlisting} - -The function that \textit{fun} points to will be called every time the -mouse cursor moves. The first argument to the callback function is -the cursor x-coordinate and the second the cursor y-coordinate, both relative -to the upper-left corner of the client area of the \GLFW\ window. - -Note that while the \textbf{glfwGetMousePos} function only reports the final -position after cursor movement events have been processed, using a callback -function lets the application see each and every such event. - - -%------------------------------------------------------------------------- -\subsection{Mouse buttons} -To query the state of a mouse button, call \textbf{glfwGetMouseButton}: - -\begin{lstlisting} -int glfwGetMouseButton(int button) -\end{lstlisting} - -The argument \textit{button} can be any \GLFW\ mouse button token, i.e. -GLFW\_MOUSE\_BUTTON\_1 through GLFW\_MOUSE\_BUTTON\_8 or one of -GLFW\_MOUSE\_BUTTON\_LEFT, GLFW\_MOUSE\_BUTTON\_RIGHT or -GLFW\_MOUSE\_BUTTON\_MIDDLE. \textbf{glfwGetMouseButton} will return -GLFW\_PRESS (which is a non-zero value) if the corresponding mouse button is -held down, otherwise it will return GLFW\_RELEASE (which is equal to zero). - -Just as it is possible to make keys ``sticky'', it is also possible to make -each mouse button appear as held down until it is checked with -\textbf{glfwGetMouseButton}. To enable sticky mouse buttons, call -\textbf{glfwEnable} with the argument GLFW\_STICKY\_MOUSE\_BUTTONS. - -When sticky mouse buttons are enabled, a mouse button will not be released -until it is checked with \textbf{glfwGetMouseButton}. To disable sticky -mouse buttons, call \textbf{glfwDisable} with the argument -GLFW\_STICKY\_MOUSE\_BUTTONS. Then all mouse buttons that are not -currently held down will be released and future mouse button releases -will take place immediately when the user releases the mouse button -without waiting for \textbf{glfwGetMouseButton} to check for the mouse -button. By default sticky mouse buttons are disabled. - -There is also a callback function for mouse button activities, which can -be set with \textbf{glfwSetMouseButtonCallback}: - -\begin{lstlisting} -void glfwSetMouseButtonCallback(GLFWmousebuttonfun fun) -\end{lstlisting} - -The argument \textit{fun} specifies a function that will be called -whenever a mouse button is pressed or released, or NULL to unregister a -callback function. The first argument to the callback function is a mouse -button identifier, and the second is either GLFW\_PRESS or GLFW\_RELEASE, -depending on the new state of the corresponding mouse button. - - -%------------------------------------------------------------------------- -\subsection{Mouse wheel} -Some mice have a mouse wheel, most commonly used for vertical scrolling. Also, -most modern touchpads allow the user to scroll at least vertically, either by -reserving an area for scrolling or through multi-finger gestures. To get the -position of the mouse wheel, call \textbf{glfwGetMouseWheel}: - -\begin{lstlisting} -int glfwGetMouseWheel(void) -\end{lstlisting} - -The function returns an integer that represents the position of the mouse -wheel. When the user turns the wheel, the wheel position will increase or -decrease. Note that since scrolling hardware has no absolute position, \GLFW\ -simply sets the position to zero when the window is opened. - -It is also possible to register a callback function for mouse wheel events -with the \textbf{glfwSetMouseWheelCallback} function: - -\begin{lstlisting} -void glfwSetMouseWheelCallback(GLFWmousewheelfun fun) -\end{lstlisting} - -The argument \textit{fun} specifies a function that will be called -whenever the mouse wheel is moved, or NULL to unregister a callback -function. The argument to the callback function is the position of the -mouse wheel. - - -%------------------------------------------------------------------------- -\subsection{Hiding the mouse cursor} -It is possible to hide the mouse cursor with the function call: - -\begin{lstlisting} -glfwDisable(GLFW_MOUSE_CURSOR); -\end{lstlisting} - -Hiding the mouse cursor has three effects: - -\begin{enumerate} -\item The cursor becomes invisible. -\item The cursor is guaranteed to be confined to the window. -\item Mouse coordinates are not limited to the window size. -\end{enumerate} - -To show the mouse cursor again, call \textbf{glfwEnable} with the -argument GLFW\_MOUSE\_CURSOR: - -\begin{lstlisting} -glfwEnable(GLFW_MOUSE_CURSOR); -\end{lstlisting} - -By default the mouse cursor is hidden if a window is opened in fullscreen -mode, otherwise it is not hidden. - - -%------------------------------------------------------------------------- -\section{Joystick Input} -\GLFW\ has support for up to sixteen joysticks, and an infinite\footnote{% -There are of course actual limitations posed by the underlying hardware, -drivers and operation system.} number of axes and buttons per joystick. -Unlike keyboard and mouse input, joystick input does not need an opened -window, and \textbf{glfwPollEvents} or \textbf{glfwSwapBuffers} does not -have to be called in order for joystick state to be updated. - - -%------------------------------------------------------------------------- -\subsection{Joystick capabilities} -First, it is often necessary to determine if a joystick is connected and -what its capabilities are. To get this information the function -\textbf{glfwGetJoystickParam} can be used: - -\begin{lstlisting} -int glfwGetJoystickParam(int joy, int param) -\end{lstlisting} - -The \textit{joy} argument specifies which joystick to retrieve the -parameter from, and it should be GLFW\_JOYSTICK\_\textit{n}, where -\textit{n} is in the range 1 to 16. The \textit{param} argument specifies -which parameter to retrieve. To determine if a joystick is connected, -\textit{param} should be GLFW\_PRESENT, which will cause the function to -return GL\_TRUE if the joystick is connected, or GL\_FALSE if it is not. -To determine the number of axes or buttons that are supported by the -joystick, \textit{param} should be GLFW\_AXES or GLFW\_BUTTONS, -respectively. - -Note that \GLFW\ supports both D-pads and POVs, even though they are not -explicitly mentioned in the API. D-pads are exposed as a set of four buttons -and POVs are as two axes. - - -%------------------------------------------------------------------------- -\subsection{Joystick position} -To get the current axis positions of the joystick, the -\textbf{glfwGetJoystickPos} is used: - -\begin{lstlisting} -int glfwGetJoystickPos(int joy, float* pos, int numaxes) -\end{lstlisting} - -As with \textbf{glfwGetJoystickParam}, the \textit{joy} argument -specifies which joystick to retrieve information from. The -\textit{numaxes} argument specifies how many axes to return positions for and the -\textit{pos} argument specifies an array in which they -are stored. The function returns the actual number of axes that were -returned, which could be less than \textit{numaxes} if the joystick does -not support all the requested axes, or if the joystick is not connected. - -For instance, to get the position of the first two axes (the X and Y axes) -of joystick 1, the following code can be used: - -\begin{lstlisting} -float position[2]; - -glfwGetJoystickPos(GLFW_JOYSTICK_1, position, 2); -\end{lstlisting} - -After this call, the first element of the \textit{position} array will -hold the X axis position of the joystick, and the second element will hold -the Y axis position. In this example we do not use the information about -how many axes were really returned. - -The position of an axis can be in the range -1.0 to 1.0, where positive -values represent right, forward or up directions, while negative values -represent left, back or down directions. If a requested axis is not -supported by the joystick, the corresponding array element will be set -to zero. The same goes for the situation when the joystick is not -connected (all axes are treated as unsupported). - - -%------------------------------------------------------------------------- -\subsection{Joystick buttons} -A function similar to the \textbf{glfwGetJoystickPos} function is -available for querying the state of joystick buttons, namely the -\textbf{glfwGetJoystickButtons} function: - -\begin{lstlisting} -int glfwGetJoystickButtons(int joy, unsigned char* buttons, - int numbuttons) -\end{lstlisting} - -The function works just like the \textbf{glfwGetJoystickAxis} function, except -that it returns the state of joystick buttons instead of axis positions. Each -button in the array specified by the \textit{buttons} argument can be either -GLFW\_PRESS or GLFW\_RELEASE, indicating whether the corresponding button is -currently held down or not. Unsupported buttons will have the value -GLFW\_RELEASE. - - -%------------------------------------------------------------------------- -% Timing -%------------------------------------------------------------------------- -\chapter{Timing} -\thispagestyle{fancy} - -%------------------------------------------------------------------------- -\section{High Resolution Timer} -In most applications, it is useful to know exactly how much time has -passed between point $A$ and point $B$ in a program. A typical situation -is in a game, where you need to know how much time has passed between two -rendered frames in order to calculate the correct movement and physics -etc. Another example is when you want to benchmark a certain piece of -code. - -\GLFW\ provides a high-resolution timer, which reports a double precision -floating point value representing the number of seconds that have passed -since \textbf{glfwInit} was called. The timer is accessed with the -function \textbf{glfwGetTime}: - -\begin{lstlisting} -double glfwGetTime(void) -\end{lstlisting} - -The precision of the timer depends on which computer and operating -system you are running, but it is almost guaranteed to be better than -$10~ms$, and in most cases it is much better than $1~ms$ (on a modern PC -you can get resolutions in the order of $1~ns$). - -It is possible to set the value of the high precision timer using the -\textbf{glfwSetTime} function: - -\begin{lstlisting} -void glfwSetTime(double time) -\end{lstlisting} - -The argument \textit{time} is the time, in seconds, that the timer should -be set to. - - -%------------------------------------------------------------------------- -% OpenGL Extension Support -%------------------------------------------------------------------------- -\chapter{OpenGL Extension Support} -\thispagestyle{fancy} -One of the benefits of \OpenGL\ is that it is extensible. Independent -hardware vendors (IHVs) may include functionality in their \OpenGL\ -implementations that exceed that of the \OpenGL\ standard. - -An extension is defined by: - -\begin{enumerate} -\item An extension name (e.g. GL\_ARB\_multitexture). -\item New OpenGL tokens (e.g. GL\_TEXTURE1\_ARB). -\item New OpenGL functions (e.g. \textbf{glActiveTextureARB}). -\end{enumerate} - -A list of official extensions, together with their definitions, can be -found at the \textit{OpenGL Registry} -(\url{http://www.opengl.org/registry/}). - -To use a certain extension, the following steps must be performed: - -\begin{enumerate} -\item A compile time check for the support of the extension. -\item A run time check for the support of the extension. -\item Fetch function pointers for the extended \OpenGL\ functions (done at - run time). -\end{enumerate} - -How this is done using \GLFW\ is described in the following sections. -Please note that this chapter covers some advanced topics, and is quite -specific to the C programming language. - -For a much easier way to get access to \OpenGL\ extensions, you should probably -use a dedicated extension loading library such as GLEW or GLee. This kind of -library greatly reduces the amount of work necessary to use \OpenGL\ -extensions. GLEW in particular has been extensively tested with and works well -with \GLFW . - - -%------------------------------------------------------------------------- -\section{Compile Time Check} -The compile time check is necessary to perform in order to know if the -compiler include files have defined the necessary tokens. It is very easy -to do. The include file \texttt{GL/gl.h} will define a constant with the -same name as the extension, if all the extension tokens are defined. Here -is an example of how to check for the extension GL\_ARB\_multitexture: - -\begin{lstlisting} -#ifdef GL_ARB_multitexture - // Extension is supported by the include files -#else - // Extension is not supported by the include files - // Get a more up-to-date file! -#endif -\end{lstlisting} - - -%------------------------------------------------------------------------- -\section{Runtime Check} -Even if the compiler include files have defined all the necessary tokens, a -given machine may not actually support the extension (it may have a graphics -card with a different \OpenGL\ implementation, or an older driver). That is why -it is necessary to do a run time check for the extension support as well. This -is done with the \GLFW\ function \textbf{glfwExtensionSupported}, which has the -C syntax: - -\begin{lstlisting} -int glfwExtensionSupported(const char* extension) -\end{lstlisting} - -The argument \textit{extension} is a null terminated ASCII string -with the extension name. \textbf{glfwExtensionSupported} returns GL\_TRUE -if the extension is supported, otherwise it returns GL\_FALSE. - -Let us extend the previous example of checking for support of the -extension GL\_ARB\_multitexture. This time we add a run time check, and a -variable which we set to GL\_TRUE if the extension is supported, or -GL\_FALSE if it is not supported. - -\begin{lstlisting} -int multitexture_supported; - -#ifdef GL_ARB_multitexture - // Check if extension is supported at run time - multitexture_supported = glfwExtensionSupported("GL_ARB_multitexture"); -#else - // Extension is not supported by the include files - // Get a more up-to-date file! - multitexture_supported = GL_FALSE; -#endif -\end{lstlisting} - -Now it is easy to check for the extension within the program, simply do: - -\begin{lstlisting} - if (multitexture_supported) - { - // Use multi texturing - } - else - { - // Use some other solution (or fail) - } -\end{lstlisting} - - -%------------------------------------------------------------------------- -\section{Fetching Function Pointers} -Some extensions, though not all, require the use of new \OpenGL\ functions. -These entry points are not necessarily exposed by your link libraries, making -it necessary to find them dynamically at run time. You can retrieve these -entry points using the \textbf{glfwGetProcAddress} function: - -\begin{lstlisting} -void* glfwGetProcAddress(const char* procname) -\end{lstlisting} - -The argument \textit{procname} is a null terminated ASCII string -holding the name of the \OpenGL\ function. \textbf{glfwGetProcAddress} -returns the address to the function if the function is available, -otherwise NULL is returned. - -Obviously, fetching the function pointer is trivial. For instance, if we -want to obtain the pointer to \textbf{glActiveTextureARB}, we simply call: - -\begin{lstlisting} -glActiveTextureARB = glfwGetProcAddress("glActiveTextureARB"); -\end{lstlisting} - -However, there are many possible naming and type definition conflicts -involved with such an operation, which may result in compiler warnings or -errors. My proposed solution is the following: - -\begin{itemize} -\item Do not use the function name for the variable name. Use something - similar, perhaps by adding a prefix or suffix, and then use - \texttt{\#define} to map the function name to your variable. -\item The standard type definition naming convention for function pointers - is \texttt{PFN\textit{xxxx}PROC}, where \texttt{\textit{xxxx}} is - the uppercase version of the function name (e.g. - \texttt{PFNGLACTIVETEXTUREARBPROC}). Either make sure your compiler uses - a compatible \texttt{gl.h} and/or \texttt{glext.h} file and rely on it to - define these types, or use define the types yourself using a different - naming convention (for example \texttt{\textit{xxxx}\_T}) and do the - type definitions yourself. -\end{itemize} - -Here is a slightly longer example of how to use an extension, this time using -our own function pointer type definition): - -\begin{lstlisting} -// Type definition of the function pointer -typedef void (APIENTRY * GLACTIVETEXTUREARB_T) (GLenum texture); - -// Function pointer -GLACTIVETEXTUREARB_T _ActiveTextureARB; -#define glActiveTextureARB _ActiveTextureARB - -// Extension availability flag -int multitexture_supported; - -#ifdef GL_ARB_multitexture - // Check if extension is supported at run time - if (glfwExtensionSupported("GL_ARB_multitexture")) - { - // Get the function pointer - glActiveTextureARB = (GLACTIVETEXTUREARB_T) - glfwGetProcAddress("glActiveTextureARB"); - - multitexture_supported = GL_TRUE; - } - else - { - multitexture_supported = GL_FALSE; - } -#else - // Extension is not supported by the include files - multitexture_supported = GL_FALSE; -#endif -\end{lstlisting} - -Even this example leaves some things to be desired. First of all, the -GL\_ARB\_multitexture extension defines many more functions than the single -function used above. Secondly, checking if an extension is supported using -\textbf{glfwExtensionSupported} is not enough to ensure that the corresponding -functions will be valid. You also need to check that the all function pointers -returned by \textbf{glfwGetProcAddress} are non-NULL. - - -%------------------------------------------------------------------------- -\subsection{Function pointer type definitions} -To make a function pointer type definition, you need to know the function -prototype. This can often be found in the extension definitions (e.g. at -the \textit{OpenGL Registry}). All the entry points that are defined by an -extension are listed with their C prototype definitions under the section -\textit{New Procedures and Functions} in the extension definition. - -For instance, if we look at the definition of the -GL\_ARB\_texture\_compression extension, we find a list of new functions. -One of these is declared like this: - -\begin{lstlisting} -void GetCompressedTexImageARB(enum target, int lod, void* img); -\end{lstlisting} - -Like in most official \OpenGL\ documentation, all the \texttt{GL} and -\texttt{gl} prefixes have been left out. In other words, the real function -prototype would look like this: - -\begin{lstlisting} -void glGetCompressedTexImageARB(GLenum target, GLint lod, void* img); -\end{lstlisting} - -All we have to do to turn this prototype definition into a function -pointer type definition, is to replace the function name with -\texttt{(APIENTRY * \textit{xxxx}\_T)}, where \textit{xxxx} is the -uppercase version of the name (according to the proposed naming -convention). The keyword \texttt{APIENTRY} is needed to be compatible -between different platforms. The \GLFW\ header file \texttt{GL/glfw.h} -ensures that \texttt{APIENTRY} is properly defined on all supported platforms. - -In other words, for the function \textbf{glGetCompressedTexImageARB} we -get: - -\begin{lstlisting} -typedef void (APIENTRY * GLGETCOMPRESSEDTEXIMAGEARB_T) - (GLenum target, GLint level, void* img); -\end{lstlisting} - - -\end{document} diff --git a/docs/readme.txt b/docs/readme.txt deleted file mode 100644 index f34521a2..00000000 --- a/docs/readme.txt +++ /dev/null @@ -1,52 +0,0 @@ -Introduction ------------- - -The GLFW documentation is written in LaTeX. Besides being powerful, LaTeX is -also very attractive since all the necessary tools for dealing with LaTeX -documentation are both free and ported to a wide variety of platforms. Another -advantage is that the LaTeX files are written in plain text, which means that -version control systems such as CVS handle them perfectly without having to -treat the documents as binary files. - - -The documents -------------- - -There are two main documents: - - glfwrm.tex - The GLFW Reference Manual - glfwug.tex - The GLFW Users Guide - -In addition, there is a common LaTeX style file that sets up things -such as page formatting and useful macros: - - glfwdoc.sty - Common GLFW document styles and macros - - -Requirements ------------- - -Of course you need LaTeX installed on your system in order to compile the GLFW -documentation. If you are using a Unix-like operating system, then your -package system most likely has a version of LaTeX adapted for your system. If -not, the easiest way to get a full LaTeX system is to download/get the TeXLive -CD from http://www.tug.org/texlive/. It has all the necessary software for -Windows, Mac OS X and most popular Unix-like operating systems. - -A number of LaTeX packages have to be installed in order to compile the -GLFW documentation successfully: - - color - fancyhdr - hyperref - lastpage - listings - needspace - textcase - times - titling - -These packages are all available on the TeXLive CD. Just make sure that -you have checked all these packages when installing TeXLive, or get them -in some other way if you do not have the TeXLive CD. - From 26fc5cacda36ddc0e25b08c3d1745339ed211880 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 7 May 2012 00:11:51 +0200 Subject: [PATCH 186/226] Formatting. --- src/win32_window.c | 86 +++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 40 deletions(-) diff --git a/src/win32_window.c b/src/win32_window.c index 42b73099..9e535136 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -149,38 +149,44 @@ static int getPixelFormatAttrib(_GLFWwindow* window, int pixelFormat, int attrib static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) { - _GLFWfbconfig* result; + _GLFWfbconfig* fbconfigs; PIXELFORMATDESCRIPTOR pfd; - int i, count; + int i, available; *found = 0; if (window->WGL.ARB_pixel_format) - count = getPixelFormatAttrib(window, 1, WGL_NUMBER_PIXEL_FORMATS_ARB); + { + available = getPixelFormatAttrib(window, + 1, + WGL_NUMBER_PIXEL_FORMATS_ARB); + } else { - count = DescribePixelFormat(window->WGL.DC, - 1, - sizeof(PIXELFORMATDESCRIPTOR), - NULL); + available = DescribePixelFormat(window->WGL.DC, + 1, + sizeof(PIXELFORMATDESCRIPTOR), + NULL); } - if (!count) + if (!available) { _glfwSetError(GLFW_OPENGL_UNAVAILABLE, "Win32/WGL: No pixel formats found"); return NULL; } - result = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * count); - if (!result) + fbconfigs = (_GLFWfbconfig*) malloc(sizeof(_GLFWfbconfig) * available); + if (!fbconfigs) { _glfwSetError(GLFW_OUT_OF_MEMORY, "Win32/WGL: Failed to allocate _GLFWfbconfig array"); return NULL; } - for (i = 1; i <= count; i++) + for (i = 1; i <= available; i++) { + _GLFWfbconfig* fbconfig = fbconfigs + *found; + if (window->WGL.ARB_pixel_format) { // Get pixel format attributes through WGL_ARB_pixel_format @@ -203,41 +209,41 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) continue; } - result[*found].redBits = + fbconfig->redBits = getPixelFormatAttrib(window, i, WGL_RED_BITS_ARB); - result[*found].greenBits = + fbconfig->greenBits = getPixelFormatAttrib(window, i, WGL_GREEN_BITS_ARB); - result[*found].blueBits = + fbconfig->blueBits = getPixelFormatAttrib(window, i, WGL_BLUE_BITS_ARB); - result[*found].alphaBits = + fbconfig->alphaBits = getPixelFormatAttrib(window, i, WGL_ALPHA_BITS_ARB); - result[*found].depthBits = + fbconfig->depthBits = getPixelFormatAttrib(window, i, WGL_DEPTH_BITS_ARB); - result[*found].stencilBits = + fbconfig->stencilBits = getPixelFormatAttrib(window, i, WGL_STENCIL_BITS_ARB); - result[*found].accumRedBits = + fbconfig->accumRedBits = getPixelFormatAttrib(window, i, WGL_ACCUM_RED_BITS_ARB); - result[*found].accumGreenBits = + fbconfig->accumGreenBits = getPixelFormatAttrib(window, i, WGL_ACCUM_GREEN_BITS_ARB); - result[*found].accumBlueBits = + fbconfig->accumBlueBits = getPixelFormatAttrib(window, i, WGL_ACCUM_BLUE_BITS_ARB); - result[*found].accumAlphaBits = + fbconfig->accumAlphaBits = getPixelFormatAttrib(window, i, WGL_ACCUM_ALPHA_BITS_ARB); - result[*found].auxBuffers = + fbconfig->auxBuffers = getPixelFormatAttrib(window, i, WGL_AUX_BUFFERS_ARB); - result[*found].stereo = + fbconfig->stereo = getPixelFormatAttrib(window, i, WGL_STEREO_ARB); if (window->WGL.ARB_multisample) { - result[*found].samples = + fbconfig->samples = getPixelFormatAttrib(window, i, WGL_SAMPLES_ARB); } else - result[*found].samples = 0; + fbconfig->samples = 0; } else { @@ -267,32 +273,32 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) if (pfd.iPixelType != PFD_TYPE_RGBA) continue; - result[*found].redBits = pfd.cRedBits; - result[*found].greenBits = pfd.cGreenBits; - result[*found].blueBits = pfd.cBlueBits; - result[*found].alphaBits = pfd.cAlphaBits; + fbconfig->redBits = pfd.cRedBits; + fbconfig->greenBits = pfd.cGreenBits; + fbconfig->blueBits = pfd.cBlueBits; + fbconfig->alphaBits = pfd.cAlphaBits; - result[*found].depthBits = pfd.cDepthBits; - result[*found].stencilBits = pfd.cStencilBits; + fbconfig->depthBits = pfd.cDepthBits; + fbconfig->stencilBits = pfd.cStencilBits; - result[*found].accumRedBits = pfd.cAccumRedBits; - result[*found].accumGreenBits = pfd.cAccumGreenBits; - result[*found].accumBlueBits = pfd.cAccumBlueBits; - result[*found].accumAlphaBits = pfd.cAccumAlphaBits; + fbconfig->accumRedBits = pfd.cAccumRedBits; + fbconfig->accumGreenBits = pfd.cAccumGreenBits; + fbconfig->accumBlueBits = pfd.cAccumBlueBits; + fbconfig->accumAlphaBits = pfd.cAccumAlphaBits; - result[*found].auxBuffers = pfd.cAuxBuffers; - result[*found].stereo = (pfd.dwFlags & PFD_STEREO) ? GL_TRUE : GL_FALSE; + fbconfig->auxBuffers = pfd.cAuxBuffers; + fbconfig->stereo = (pfd.dwFlags & PFD_STEREO) ? GL_TRUE : GL_FALSE; // PFD pixel formats do not support FSAA - result[*found].samples = 0; + fbconfig->samples = 0; } - result[*found].platformID = i; + fbconfig->platformID = i; (*found)++; } - return result; + return fbconfigs; } From d717c0a5bab57300754c7e0739e2246f0801847a Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 7 May 2012 00:13:38 +0200 Subject: [PATCH 187/226] Added bug fix from 2.7.6. --- readme.html | 1 + src/win32_window.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/readme.html b/readme.html index 413be001..e1b29330 100644 --- a/readme.html +++ b/readme.html @@ -341,6 +341,7 @@ version of GLFW.

  • [Win32] Bugfix: The array for WGL context attributes was too small and could overflow
  • [Win32] Bugfix: Alt+F4 hot key was not translated into WM_CLOSE
  • [Win32] Bugfix: The GLFW_WINDOW_NO_RESIZE window parameter was always zero
  • +
  • [Win32] Bugfix: A test was missing for whether all available pixel formats had been disqualified
  • v2.7

    diff --git a/src/win32_window.c b/src/win32_window.c index 9e535136..47862622 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -298,6 +298,12 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) (*found)++; } + if (*found == 0) + { + free(fbconfigs); + return NULL; + } + return fbconfigs; } From 6ff393610194480c27d6c81d434d430482ed3164 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 7 May 2012 00:20:53 +0200 Subject: [PATCH 188/226] Fixed source file having executable flag set. --- src/win32_joystick.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 src/win32_joystick.c diff --git a/src/win32_joystick.c b/src/win32_joystick.c old mode 100755 new mode 100644 From 3d5a574e3b4e668f3d53625bc5116b71b78c10ee Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 7 May 2012 00:29:36 +0200 Subject: [PATCH 189/226] Made listing the default for modes test. --- tests/modes.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/tests/modes.c b/tests/modes.c index 07407e13..67b579c5 100644 --- a/tests/modes.c +++ b/tests/modes.c @@ -38,15 +38,13 @@ static GLFWwindow window = NULL; enum Mode { - NO_MODE, LIST_MODE, TEST_MODE }; static void usage(void) { - printf("Usage: modes -l\n"); - printf(" modes -t\n"); + printf("Usage: modes [-t]\n"); printf(" modes -h\n"); } @@ -170,19 +168,16 @@ static void test_modes(GLFWvidmode* modes, int count) int main(int argc, char** argv) { - int ch, found, count = 0, mode = NO_MODE; + int ch, found, count = 0, mode = LIST_MODE; GLFWvidmode* modes = NULL; - while ((ch = getopt(argc, argv, "lth")) != -1) + while ((ch = getopt(argc, argv, "th")) != -1) { switch (ch) { case 'h': usage(); exit(EXIT_SUCCESS); - case 'l': - mode = LIST_MODE; - break; case 't': mode = TEST_MODE; break; From dd1a46af43c2f6e61067d1f5b2029ba482e25e34 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 7 May 2012 00:32:03 +0200 Subject: [PATCH 190/226] Added header to more closely match output of older test. --- tests/modes.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/modes.c b/tests/modes.c index 67b579c5..89892dd9 100644 --- a/tests/modes.c +++ b/tests/modes.c @@ -84,6 +84,8 @@ static void list_modes(GLFWvidmode* modes, int count) print_mode(&mode); putchar('\n'); + printf("Available modes:\n"); + for (i = 0; i < count; i++) { printf("%3i: ", i); From 93c3d52716b98288a863d0963d267c4e5bef7a6e Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 7 May 2012 00:33:21 +0200 Subject: [PATCH 191/226] Formatting. --- tests/modes.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/tests/modes.c b/tests/modes.c index 89892dd9..5b083641 100644 --- a/tests/modes.c +++ b/tests/modes.c @@ -103,21 +103,23 @@ static void test_modes(GLFWvidmode* modes, int count) for (i = 0; i < count; i++) { - glfwOpenWindowHint(GLFW_RED_BITS, modes[i].redBits); - glfwOpenWindowHint(GLFW_GREEN_BITS, modes[i].greenBits); - glfwOpenWindowHint(GLFW_BLUE_BITS, modes[i].blueBits); + GLFWvidmode* mode = modes + i; + + glfwOpenWindowHint(GLFW_RED_BITS, mode->redBits); + glfwOpenWindowHint(GLFW_GREEN_BITS, mode->greenBits); + glfwOpenWindowHint(GLFW_BLUE_BITS, mode->blueBits); printf("Opening "); - print_mode(modes + i); + print_mode(mode); printf(" window\n"); - window = glfwOpenWindow(modes[i].width, modes[i].height, + window = glfwOpenWindow(mode->width, mode->height, GLFW_FULLSCREEN, "Video Mode Test", NULL); if (!window) { printf("Failed to enter mode %i: ", i); - print_mode(modes + i); + print_mode(mode); putchar('\n'); continue; } @@ -138,26 +140,26 @@ static void test_modes(GLFWvidmode* modes, int count) } } - if (glfwGetWindowParam(window, GLFW_RED_BITS) != modes[i].redBits || - glfwGetWindowParam(window, GLFW_GREEN_BITS) != modes[i].greenBits || - glfwGetWindowParam(window, GLFW_BLUE_BITS) != modes[i].blueBits) + if (glfwGetWindowParam(window, GLFW_RED_BITS) != mode->redBits || + glfwGetWindowParam(window, GLFW_GREEN_BITS) != mode->greenBits || + glfwGetWindowParam(window, GLFW_BLUE_BITS) != mode->blueBits) { printf("*** Color bit mismatch: (%i %i %i) instead of (%i %i %i)\n", glfwGetWindowParam(window, GLFW_RED_BITS), glfwGetWindowParam(window, GLFW_GREEN_BITS), glfwGetWindowParam(window, GLFW_BLUE_BITS), - modes[i].redBits, - modes[i].greenBits, - modes[i].blueBits); + mode->redBits, + mode->greenBits, + mode->blueBits); } glfwGetWindowSize(window, &width, &height); - if (width != modes[i].width || height != modes[i].height) + if (width != mode->width || height != mode->height) { printf("*** Size mismatch: %ix%i instead of %ix%i\n", width, height, - modes[i].width, modes[i].height); + mode->width, mode->height); } printf("Closing window\n"); From e55b5fc27c04180fe41a8cdbe7ea43eeeadf2d9f Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 7 May 2012 00:34:40 +0200 Subject: [PATCH 192/226] Removed listmodes test. --- tests/CMakeLists.txt | 3 +-- tests/listmodes.c | 47 -------------------------------------------- 2 files changed, 1 insertion(+), 49 deletions(-) delete mode 100644 tests/listmodes.c diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c4db1a57..55862fac 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -21,7 +21,6 @@ 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(modes modes.c getopt.c) add_executable(peter peter.c) add_executable(reopen reopen.c) @@ -43,7 +42,7 @@ set_target_properties(windows PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Windows") set(WINDOWS_BINARIES accuracy sharing tearing title windows) set(CONSOLE_BINARIES clipboard defaults events fsaa fsfocus gamma glfwinfo - iconify joysticks listmodes modes peter reopen) + iconify joysticks modes peter reopen) if (MSVC) # Tell MSVC to use main instead of WinMain for Windows subsystem executables diff --git a/tests/listmodes.c b/tests/listmodes.c deleted file mode 100644 index a4648ef6..00000000 --- a/tests/listmodes.c +++ /dev/null @@ -1,47 +0,0 @@ -//======================================================================== -// This is a small test application for GLFW. -// The program lists all available fullscreen video modes. -//======================================================================== - -#include - -#include -#include - -static void print_mode(GLFWvidmode* mode) -{ - printf("%i x %i x %i (%i %i %i)\n", - mode->width, mode->height, - mode->redBits + mode->greenBits + mode->blueBits, - mode->redBits, mode->greenBits, mode->blueBits); -} - -int main(void) -{ - GLFWvidmode dtmode, modes[400]; - int modecount, i; - - if (!glfwInit()) - { - fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); - exit(EXIT_FAILURE); - } - - // Show desktop video mode - glfwGetDesktopMode(&dtmode); - printf("Desktop mode: "); - print_mode(&dtmode); - - // List available video modes - modecount = glfwGetVideoModes(modes, sizeof(modes) / sizeof(GLFWvidmode)); - printf("Available modes:\n"); - for (i = 0; i < modecount; i++) - { - printf("%3i: ", i); - print_mode(modes + i); - } - - glfwTerminate(); - exit(EXIT_SUCCESS); -} - From eeed6394c0618500a44a7485f0be5a7f964f1e20 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 7 May 2012 00:44:39 +0200 Subject: [PATCH 193/226] Added abort via escape key. --- tests/modes.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/modes.c b/tests/modes.c index 5b083641..f88b06ed 100644 --- a/tests/modes.c +++ b/tests/modes.c @@ -74,6 +74,15 @@ static int window_close_callback(GLFWwindow dummy) return GL_TRUE; } +static void key_callback(GLFWwindow dummy, int key, int action) +{ + if (key == GLFW_KEY_ESCAPE) + { + glfwCloseWindow(window); + window = NULL; + } +} + static void list_modes(GLFWvidmode* modes, int count) { int i; @@ -100,6 +109,7 @@ static void test_modes(GLFWvidmode* modes, int count) glfwSetWindowSizeCallback(window_size_callback); glfwSetWindowCloseCallback(window_close_callback); + glfwSetKeyCallback(key_callback); for (i = 0; i < count; i++) { From d109d8a6d235a66e02ee11e87bc6bd1566e4d956 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 7 May 2012 01:12:08 +0200 Subject: [PATCH 194/226] Restructured modes test for better encapsulation. --- tests/modes.c | 63 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/tests/modes.c b/tests/modes.c index f88b06ed..db442167 100644 --- a/tests/modes.c +++ b/tests/modes.c @@ -83,29 +83,52 @@ static void key_callback(GLFWwindow dummy, int key, int action) } } -static void list_modes(GLFWvidmode* modes, int count) +static GLFWvidmode* get_video_modes(size_t* found) { - int i; - GLFWvidmode mode; + size_t count = 0; + GLFWvidmode* modes = NULL; - glfwGetDesktopMode(&mode); + for (;;) + { + count += 256; + modes = realloc(modes, sizeof(GLFWvidmode) * count); + + *found = glfwGetVideoModes(modes, count); + if (*found < count) + break; + } + + return modes; +} + +static void list_modes(void) +{ + size_t count, i; + GLFWvidmode desktop_mode; + GLFWvidmode* modes = get_video_modes(&count); + + glfwGetDesktopMode(&desktop_mode); printf("Desktop mode: "); - print_mode(&mode); + print_mode(&desktop_mode); putchar('\n'); printf("Available modes:\n"); for (i = 0; i < count; i++) { - printf("%3i: ", i); + printf("%3u: ", (unsigned int) i); print_mode(modes + i); putchar('\n'); } + + free(modes); } -static void test_modes(GLFWvidmode* modes, int count) +static void test_modes(void) { - int i, width, height; + int width, height; + size_t i, count; + GLFWvidmode* modes = get_video_modes(&count); glfwSetWindowSizeCallback(window_size_callback); glfwSetWindowCloseCallback(window_close_callback); @@ -128,7 +151,7 @@ static void test_modes(GLFWvidmode* modes, int count) NULL); if (!window) { - printf("Failed to enter mode %i: ", i); + printf("Failed to enter mode %u: ", (unsigned int) i); print_mode(mode); putchar('\n'); continue; @@ -178,12 +201,13 @@ static void test_modes(GLFWvidmode* modes, int count) glfwPollEvents(); window = NULL; } + + free(modes); } int main(int argc, char** argv) { - int ch, found, count = 0, mode = LIST_MODE; - GLFWvidmode* modes = NULL; + int ch, mode = LIST_MODE; while ((ch = getopt(argc, argv, "th")) != -1) { @@ -209,23 +233,10 @@ int main(int argc, char** argv) if (!glfwInit()) exit(EXIT_FAILURE); - for (;;) - { - count += 256; - modes = realloc(modes, sizeof(GLFWvidmode) * count); - - found = glfwGetVideoModes(modes, count); - if (found < count) - break; - } - if (mode == LIST_MODE) - list_modes(modes, found); + list_modes(); else if (mode == TEST_MODE) - test_modes(modes, found); - - free(modes); - modes = NULL; + test_modes(); exit(EXIT_SUCCESS); } From 5527e52f58ae56146464bfd84f9b2fae69bfe957 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 7 May 2012 01:13:07 +0200 Subject: [PATCH 195/226] Added hilighting of desktop mode. --- tests/modes.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/modes.c b/tests/modes.c index db442167..c4572e0a 100644 --- a/tests/modes.c +++ b/tests/modes.c @@ -30,6 +30,7 @@ #include #include +#include #include #include "getopt.h" @@ -118,6 +119,10 @@ static void list_modes(void) { printf("%3u: ", (unsigned int) i); print_mode(modes + i); + + if (memcmp(&desktop_mode, modes + i, sizeof(GLFWvidmode)) == 0) + printf(" (desktop mode)"); + putchar('\n'); } From 6059523b6dd3d8af2c39121afe3e0ab72c45dfbf Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 7 May 2012 01:30:55 +0200 Subject: [PATCH 196/226] Simplified mode printing. --- tests/modes.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/tests/modes.c b/tests/modes.c index c4572e0a..3a384003 100644 --- a/tests/modes.c +++ b/tests/modes.c @@ -49,12 +49,18 @@ static void usage(void) printf(" modes -h\n"); } -static void print_mode(GLFWvidmode* mode) +static const char* format_mode(GLFWvidmode* mode) { - printf("%i x %i x %i (%i %i %i)", - mode->width, mode->height, - mode->redBits + mode->greenBits + mode->blueBits, - mode->redBits, mode->greenBits, mode->blueBits); + static char buffer[512]; + + snprintf(buffer, sizeof(buffer), + "%i x %i x %i (%i %i %i)", + mode->width, mode->height, + mode->redBits + mode->greenBits + mode->blueBits, + mode->redBits, mode->greenBits, mode->blueBits); + + buffer[sizeof(buffer) - 1] = '\0'; + return buffer; } static void error_callback(int error, const char* description) @@ -109,16 +115,13 @@ static void list_modes(void) GLFWvidmode* modes = get_video_modes(&count); glfwGetDesktopMode(&desktop_mode); - printf("Desktop mode: "); - print_mode(&desktop_mode); - putchar('\n'); + printf("Desktop mode: %s\n", format_mode(&desktop_mode)); printf("Available modes:\n"); for (i = 0; i < count; i++) { - printf("%3u: ", (unsigned int) i); - print_mode(modes + i); + printf("%3u: %s", (unsigned int) i, format_mode(modes + i)); if (memcmp(&desktop_mode, modes + i, sizeof(GLFWvidmode)) == 0) printf(" (desktop mode)"); @@ -147,18 +150,16 @@ static void test_modes(void) glfwOpenWindowHint(GLFW_GREEN_BITS, mode->greenBits); glfwOpenWindowHint(GLFW_BLUE_BITS, mode->blueBits); - printf("Opening "); - print_mode(mode); - printf(" window\n"); + printf("Testing mode %u: %s", (unsigned int) i, format_mode(mode)); window = glfwOpenWindow(mode->width, mode->height, GLFW_FULLSCREEN, "Video Mode Test", NULL); if (!window) { - printf("Failed to enter mode %u: ", (unsigned int) i); - print_mode(mode); - putchar('\n'); + printf("Failed to enter mode %u: %s\n", + (unsigned int) i, + format_mode(mode)); continue; } From 1a3778814303b42782d9acfbd370511169438f2d Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 24 May 2012 11:36:43 +0200 Subject: [PATCH 197/226] Moved X11 gamma ramp init to gamma module. --- src/x11_gamma.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++ src/x11_init.c | 58 +------------------------------------------- src/x11_platform.h | 3 +++ 3 files changed, 64 insertions(+), 57 deletions(-) diff --git a/src/x11_gamma.c b/src/x11_gamma.c index fe02a939..04280a06 100644 --- a/src/x11_gamma.c +++ b/src/x11_gamma.c @@ -31,6 +31,66 @@ #include #include +#include + + +////////////////////////////////////////////////////////////////////////// +////// GLFW internal API ////// +////////////////////////////////////////////////////////////////////////// + +//======================================================================== +// Detect gamma ramp support and save original gamma ramp, if available +//======================================================================== + +void _glfwInitGammaRamp(void) +{ +#ifdef _GLFW_HAS_XRANDR + // RandR gamma support is only available with version 1.2 and above + if (_glfwLibrary.X11.RandR.available && + (_glfwLibrary.X11.RandR.majorVersion > 1 || + (_glfwLibrary.X11.RandR.majorVersion == 1 && + _glfwLibrary.X11.RandR.minorVersion >= 2))) + { + // FIXME: Assumes that all monitors have the same size gamma tables + // This is reasonable as I suspect the that if they did differ, it + // would imply that setting the gamma size to an arbitary size is + // possible as well. + XRRScreenResources* rr = XRRGetScreenResources(_glfwLibrary.X11.display, + _glfwLibrary.X11.root); + + _glfwLibrary.originalRampSize = XRRGetCrtcGammaSize(_glfwLibrary.X11.display, + rr->crtcs[0]); + if (!_glfwLibrary.originalRampSize) + { + // This is probably Nvidia RandR with broken gamma support + // Flag it as useless and try Xf86VidMode below, if available + _glfwLibrary.X11.RandR.gammaBroken = GL_TRUE; + fprintf(stderr, + "Ignoring broken nVidia implementation of RandR 1.2+ gamma\n"); + } + + XRRFreeScreenResources(rr); + } +#endif /*_GLFW_HAS_XRANDR*/ + +#if defined(_GLFW_HAS_XF86VIDMODE) + if (_glfwLibrary.X11.VidMode.available && + !_glfwLibrary.originalRampSize) + { + // Get the gamma size using XF86VidMode + XF86VidModeGetGammaRampSize(_glfwLibrary.X11.display, + _glfwLibrary.X11.screen, + &_glfwLibrary.originalRampSize); + } +#endif /*_GLFW_HAS_XF86VIDMODE*/ + + if (!_glfwLibrary.originalRampSize) + fprintf(stderr, "No supported gamma ramp API found\n"); + + // Save the original gamma ramp + _glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp); + _glfwLibrary.currentRamp = _glfwLibrary.originalRamp; +} ////////////////////////////////////////////////////////////////////////// diff --git a/src/x11_init.c b/src/x11_init.c index d59fbcc6..6ea80351 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -30,7 +30,6 @@ #include "internal.h" -#include #include #include #include @@ -621,61 +620,6 @@ static GLboolean initDisplay(void) } -//======================================================================== -// Detect gamma ramp support and save original gamma ramp, if available -//======================================================================== - -static void initGammaRamp(void) -{ -#ifdef _GLFW_HAS_XRANDR - // RandR gamma support is only available with version 1.2 and above - if (_glfwLibrary.X11.RandR.available && - (_glfwLibrary.X11.RandR.majorVersion > 1 || - (_glfwLibrary.X11.RandR.majorVersion == 1 && - _glfwLibrary.X11.RandR.minorVersion >= 2))) - { - // FIXME: Assumes that all monitors have the same size gamma tables - // This is reasonable as I suspect the that if they did differ, it - // would imply that setting the gamma size to an arbitary size is - // possible as well. - XRRScreenResources* rr = XRRGetScreenResources(_glfwLibrary.X11.display, - _glfwLibrary.X11.root); - - _glfwLibrary.originalRampSize = XRRGetCrtcGammaSize(_glfwLibrary.X11.display, - rr->crtcs[0]); - if (!_glfwLibrary.originalRampSize) - { - // This is probably Nvidia RandR with broken gamma support - // Flag it as useless and try Xf86VidMode below, if available - _glfwLibrary.X11.RandR.gammaBroken = GL_TRUE; - fprintf(stderr, - "Ignoring broken nVidia implementation of RandR 1.2+ gamma\n"); - } - - XRRFreeScreenResources(rr); - } -#endif /*_GLFW_HAS_XRANDR*/ - -#if defined(_GLFW_HAS_XF86VIDMODE) - if (_glfwLibrary.X11.VidMode.available && - !_glfwLibrary.originalRampSize) - { - // Get the gamma size using XF86VidMode - XF86VidModeGetGammaRampSize(_glfwLibrary.X11.display, - _glfwLibrary.X11.screen, - &_glfwLibrary.originalRampSize); - } -#endif /*_GLFW_HAS_XF86VIDMODE*/ - - if (!_glfwLibrary.originalRampSize) - fprintf(stderr, "No supported gamma ramp API found\n"); - - // Save the original gamma ramp - _glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp); - _glfwLibrary.currentRamp = _glfwLibrary.originalRamp; -} - - //======================================================================== // Create a blank cursor (for locked mouse mode) //======================================================================== @@ -739,7 +683,7 @@ int _glfwPlatformInit(void) if (!initDisplay()) return GL_FALSE; - initGammaRamp(); + _glfwInitGammaRamp(); initEWMH(); diff --git a/src/x11_platform.h b/src/x11_platform.h index 013ca4e0..e4fbfe08 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -283,6 +283,9 @@ GLFWGLOBAL struct { // Time void _glfwInitTimer(void); +// Gamma +void _glfwInitGammaRamp(void); + // Fullscreen support int _glfwGetClosestVideoMode(int* width, int* height, int* rate); void _glfwSetVideoModeMODE(int mode, int rate); From f5eb79ed28c09afa69366f191ca0d5cf315e5c67 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 24 May 2012 11:39:16 +0200 Subject: [PATCH 198/226] Removed gamma API warning prints. --- src/x11_gamma.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/x11_gamma.c b/src/x11_gamma.c index 04280a06..c3791afc 100644 --- a/src/x11_gamma.c +++ b/src/x11_gamma.c @@ -31,7 +31,6 @@ #include #include -#include ////////////////////////////////////////////////////////////////////////// @@ -65,8 +64,6 @@ void _glfwInitGammaRamp(void) // This is probably Nvidia RandR with broken gamma support // Flag it as useless and try Xf86VidMode below, if available _glfwLibrary.X11.RandR.gammaBroken = GL_TRUE; - fprintf(stderr, - "Ignoring broken nVidia implementation of RandR 1.2+ gamma\n"); } XRRFreeScreenResources(rr); @@ -84,12 +81,12 @@ void _glfwInitGammaRamp(void) } #endif /*_GLFW_HAS_XF86VIDMODE*/ - if (!_glfwLibrary.originalRampSize) - fprintf(stderr, "No supported gamma ramp API found\n"); - - // Save the original gamma ramp - _glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp); - _glfwLibrary.currentRamp = _glfwLibrary.originalRamp; + if (_glfwLibrary.originalRampSize) + { + // Save the original gamma ramp + _glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp); + _glfwLibrary.currentRamp = _glfwLibrary.originalRamp; + } } From 79bef6851156e710df564cc7607698b4e30152a7 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 24 May 2012 11:46:51 +0200 Subject: [PATCH 199/226] Only restore gamma ramp if it has been changed. --- src/cocoa_init.m | 3 ++- src/gamma.c | 1 + src/internal.h | 1 + src/win32_init.c | 3 ++- src/x11_init.c | 2 +- 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cocoa_init.m b/src/cocoa_init.m index 329bcfa4..7c208b90 100644 --- a/src/cocoa_init.m +++ b/src/cocoa_init.m @@ -129,7 +129,8 @@ int _glfwPlatformTerminate(void) } // Restore the original gamma ramp - _glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp); + if (_glfwLibrary.rampChanged) + _glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp); CGDisplayModeRelease(_glfwLibrary.NS.desktopMode); diff --git a/src/gamma.c b/src/gamma.c index 34cb22f5..21940b0e 100644 --- a/src/gamma.c +++ b/src/gamma.c @@ -112,5 +112,6 @@ GLFWAPI void glfwSetGammaRamp(const GLFWgammaramp* ramp) _glfwPlatformSetGammaRamp(ramp); _glfwLibrary.currentRamp = *ramp; + _glfwLibrary.rampChanged = GL_TRUE; } diff --git a/src/internal.h b/src/internal.h index 6398bdc5..681df74d 100644 --- a/src/internal.h +++ b/src/internal.h @@ -245,6 +245,7 @@ struct _GLFWlibrary GLFWgammaramp currentRamp; GLFWgammaramp originalRamp; int originalRampSize; + GLboolean rampChanged; // This is defined in the current port's platform.h _GLFW_PLATFORM_LIBRARY_WINDOW_STATE; diff --git a/src/win32_init.c b/src/win32_init.c index 2422dd4b..194ff6c4 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -190,7 +190,8 @@ int _glfwPlatformInit(void) int _glfwPlatformTerminate(void) { // Restore the original gamma ramp - _glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp); + if (_glfwLibrary.rampChanged) + _glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp); if (_glfwLibrary.Win32.classAtom) { diff --git a/src/x11_init.c b/src/x11_init.c index 6ea80351..3543c9f5 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -659,7 +659,7 @@ static Cursor createNULLCursor(void) static void terminateDisplay(void) { - if (_glfwLibrary.originalRampSize) + if (_glfwLibrary.originalRampSize && _glfwLibrary.rampChanged) _glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp); if (_glfwLibrary.X11.display) From 20fccd4aa340ef2548395edbf4a265ad4be75902 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 24 May 2012 11:48:50 +0200 Subject: [PATCH 200/226] Removed unsupported target. --- src/win32_init.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/win32_init.c b/src/win32_init.c index 194ff6c4..5bcbb310 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -221,8 +221,6 @@ const char* _glfwPlatformGetVersionString(void) const char* version = _GLFW_VERSION_FULL #if defined(__MINGW32__) " MinGW" -#elif defined(__CYGWIN__) - " Cygwin" #elif defined(_MSC_VER) " Visual C++ " #elif defined(__BORLANDC__) From 322407ae9febde08d5e796b40ea94cc8c76e09fa Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 31 May 2012 01:34:21 +0200 Subject: [PATCH 201/226] Moved X11 gamma ramp termination to gamma module. --- src/x11_gamma.c | 11 +++++++++++ src/x11_init.c | 5 ++--- src/x11_platform.h | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/x11_gamma.c b/src/x11_gamma.c index c3791afc..1ca0a8c1 100644 --- a/src/x11_gamma.c +++ b/src/x11_gamma.c @@ -90,6 +90,17 @@ void _glfwInitGammaRamp(void) } +//======================================================================== +// Restore original gamma ramp if necessary +//======================================================================== + +void _glfwTerminateGammaRamp(void) +{ + if (_glfwLibrary.originalRampSize && _glfwLibrary.rampChanged) + _glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp); +} + + ////////////////////////////////////////////////////////////////////////// ////// GLFW platform API ////// ////////////////////////////////////////////////////////////////////////// diff --git a/src/x11_init.c b/src/x11_init.c index 3543c9f5..3cb94e54 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -659,9 +659,6 @@ static Cursor createNULLCursor(void) static void terminateDisplay(void) { - if (_glfwLibrary.originalRampSize && _glfwLibrary.rampChanged) - _glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp); - if (_glfwLibrary.X11.display) { XCloseDisplay(_glfwLibrary.X11.display); @@ -713,6 +710,8 @@ int _glfwPlatformTerminate(void) _glfwLibrary.X11.cursor = (Cursor) 0; } + _glfwTerminateGammaRamp(); + terminateDisplay(); _glfwTerminateJoysticks(); diff --git a/src/x11_platform.h b/src/x11_platform.h index e4fbfe08..4cb20668 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -285,6 +285,7 @@ void _glfwInitTimer(void); // Gamma void _glfwInitGammaRamp(void); +void _glfwTerminateGammaRamp(void); // Fullscreen support int _glfwGetClosestVideoMode(int* width, int* height, int* rate); From 2558da0b591d0334771286506f45fb9f394e4d8d Mon Sep 17 00:00:00 2001 From: Braden Pellett Date: Thu, 31 May 2012 17:01:24 -0700 Subject: [PATCH 202/226] Ignore gamma ramp get/set capabilities if size is not GLFW_GAMMA_RAMP_SIZE, similar to what happens currently for the Cocoa implementation. --- src/x11_gamma.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/x11_gamma.c b/src/x11_gamma.c index 1ca0a8c1..edd71846 100644 --- a/src/x11_gamma.c +++ b/src/x11_gamma.c @@ -111,6 +111,10 @@ void _glfwTerminateGammaRamp(void) void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp) { + // For now, don't support anything that is not GLFW_GAMMA_RAMP_SIZE + if (_glfwLibrary.originalRampSize != GLFW_GAMMA_RAMP_SIZE) + return; + if (_glfwLibrary.X11.RandR.available && !_glfwLibrary.X11.RandR.gammaBroken) { @@ -153,6 +157,10 @@ void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp) void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp) { + // For now, don't support anything that is not GLFW_GAMMA_RAMP_SIZE + if (_glfwLibrary.originalRampSize != GLFW_GAMMA_RAMP_SIZE) + return; + if (_glfwLibrary.X11.RandR.available && !_glfwLibrary.X11.RandR.gammaBroken) { From 6cb89175a7790dbcaa39d54ca863e1d28e4f84db Mon Sep 17 00:00:00 2001 From: Braden Pellett Date: Fri, 1 Jun 2012 00:08:34 -0700 Subject: [PATCH 203/226] Emit an error when gamma ramp cannot be get/set due to size not being GLFW_GAMMA_RAMP_SIZE. --- src/x11_gamma.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/x11_gamma.c b/src/x11_gamma.c index edd71846..44cd1139 100644 --- a/src/x11_gamma.c +++ b/src/x11_gamma.c @@ -113,7 +113,12 @@ void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp) { // For now, don't support anything that is not GLFW_GAMMA_RAMP_SIZE if (_glfwLibrary.originalRampSize != GLFW_GAMMA_RAMP_SIZE) - return; + { + _glfwSetError(GLFW_PLATFORM_ERROR, + "X11/GLX: Failed to get gamma ramp due to size " + "incompatibility"); + return; + } if (_glfwLibrary.X11.RandR.available && !_glfwLibrary.X11.RandR.gammaBroken) @@ -159,7 +164,12 @@ void _glfwPlatformSetGammaRamp(const GLFWgammaramp* ramp) { // For now, don't support anything that is not GLFW_GAMMA_RAMP_SIZE if (_glfwLibrary.originalRampSize != GLFW_GAMMA_RAMP_SIZE) - return; + { + _glfwSetError(GLFW_PLATFORM_ERROR, + "X11/GLX: Failed to set gamma ramp due to size " + "incompatibility"); + return; + } if (_glfwLibrary.X11.RandR.available && !_glfwLibrary.X11.RandR.gammaBroken) From fc07e1d7ebff49dd1e3a20f587c7b2fcc4877aac Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 3 Jun 2012 16:09:13 +0200 Subject: [PATCH 204/226] Added workaround for missing window bit in VB GL. --- src/x11_window.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/x11_window.c b/src/x11_window.c index ccd99a60..a12e07b0 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -128,6 +128,8 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) GLXFBConfig* fbconfigs; _GLFWfbconfig* result; int i, count = 0; + const char* vendor; + GLboolean trustWindowBit = GL_TRUE; *found = 0; @@ -141,6 +143,11 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) } } + vendor = glXGetClientString(_glfwLibrary.X11.display, GLX_VENDOR); + + if (strcmp(vendor, "Chromium") == 0) + trustWindowBit = GL_FALSE; + if (window->GLX.SGIX_fbconfig) { fbconfigs = window->GLX.ChooseFBConfigSGIX(_glfwLibrary.X11.display, @@ -192,10 +199,15 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) continue; } - if (!(getFBConfigAttrib(window, fbconfigs[i], GLX_DRAWABLE_TYPE) & GLX_WINDOW_BIT)) + if (!(getFBConfigAttrib(window, + fbconfigs[i], + GLX_DRAWABLE_TYPE) & GLX_WINDOW_BIT)) { - // Only consider window GLXFBConfigs - continue; + if (trustWindowBit) + { + // Only consider window GLXFBConfigs + continue; + } } result[*found].redBits = getFBConfigAttrib(window, fbconfigs[i], GLX_RED_SIZE); From 7b4f9f02cacdb211d0c9bdee75a404f0a98746e8 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 3 Jun 2012 16:12:35 +0200 Subject: [PATCH 205/226] Commented workaround. --- src/x11_window.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/x11_window.c b/src/x11_window.c index a12e07b0..c6e1fa74 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -146,7 +146,11 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) vendor = glXGetClientString(_glfwLibrary.X11.display, GLX_VENDOR); if (strcmp(vendor, "Chromium") == 0) - trustWindowBit = GL_FALSE; + { + // This is a (hopefully temporary) workaround for Chromium (VirtualBox + // GL) not setting the window bit on any GLXFBConfigs + trustWindowBit = GL_FALSE; + } if (window->GLX.SGIX_fbconfig) { From 19744bc5de46625c6ecbbe57c427fb4254d79fc9 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 3 Jun 2012 16:33:48 +0200 Subject: [PATCH 206/226] Added needed include. --- src/x11_opengl.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/x11_opengl.c b/src/x11_opengl.c index 582fbe20..8fb11d60 100644 --- a/src/x11_opengl.c +++ b/src/x11_opengl.c @@ -30,6 +30,7 @@ #include "internal.h" +#include #include From ae2c63b580fa4887a82bada294e8423769009185 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 3 Jun 2012 16:40:54 +0200 Subject: [PATCH 207/226] Made fbconfig conversion more readable. --- src/x11_opengl.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/x11_opengl.c b/src/x11_opengl.c index 8fb11d60..ac1974f1 100644 --- a/src/x11_opengl.c +++ b/src/x11_opengl.c @@ -128,6 +128,8 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) for (i = 0; i < count; i++) { + _GLFWfbconfig* f = result + *found; + if (!getFBConfigAttrib(window, fbconfigs[i], GLX_DOUBLEBUFFER) || !getFBConfigAttrib(window, fbconfigs[i], GLX_VISUAL_ID)) { @@ -152,28 +154,28 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) } } - result[*found].redBits = getFBConfigAttrib(window, fbconfigs[i], GLX_RED_SIZE); - result[*found].greenBits = getFBConfigAttrib(window, fbconfigs[i], GLX_GREEN_SIZE); - result[*found].blueBits = getFBConfigAttrib(window, fbconfigs[i], GLX_BLUE_SIZE); + f->redBits = getFBConfigAttrib(window, fbconfigs[i], GLX_RED_SIZE); + f->greenBits = getFBConfigAttrib(window, fbconfigs[i], GLX_GREEN_SIZE); + f->blueBits = getFBConfigAttrib(window, fbconfigs[i], GLX_BLUE_SIZE); - result[*found].alphaBits = getFBConfigAttrib(window, fbconfigs[i], GLX_ALPHA_SIZE); - result[*found].depthBits = getFBConfigAttrib(window, fbconfigs[i], GLX_DEPTH_SIZE); - result[*found].stencilBits = getFBConfigAttrib(window, fbconfigs[i], GLX_STENCIL_SIZE); + f->alphaBits = getFBConfigAttrib(window, fbconfigs[i], GLX_ALPHA_SIZE); + f->depthBits = getFBConfigAttrib(window, fbconfigs[i], GLX_DEPTH_SIZE); + f->stencilBits = getFBConfigAttrib(window, fbconfigs[i], GLX_STENCIL_SIZE); - result[*found].accumRedBits = getFBConfigAttrib(window, fbconfigs[i], GLX_ACCUM_RED_SIZE); - result[*found].accumGreenBits = getFBConfigAttrib(window, fbconfigs[i], GLX_ACCUM_GREEN_SIZE); - result[*found].accumBlueBits = getFBConfigAttrib(window, fbconfigs[i], GLX_ACCUM_BLUE_SIZE); - result[*found].accumAlphaBits = getFBConfigAttrib(window, fbconfigs[i], GLX_ACCUM_ALPHA_SIZE); + f->accumRedBits = getFBConfigAttrib(window, fbconfigs[i], GLX_ACCUM_RED_SIZE); + f->accumGreenBits = getFBConfigAttrib(window, fbconfigs[i], GLX_ACCUM_GREEN_SIZE); + f->accumBlueBits = getFBConfigAttrib(window, fbconfigs[i], GLX_ACCUM_BLUE_SIZE); + f->accumAlphaBits = getFBConfigAttrib(window, fbconfigs[i], GLX_ACCUM_ALPHA_SIZE); - result[*found].auxBuffers = getFBConfigAttrib(window, fbconfigs[i], GLX_AUX_BUFFERS); - result[*found].stereo = getFBConfigAttrib(window, fbconfigs[i], GLX_STEREO); + f->auxBuffers = getFBConfigAttrib(window, fbconfigs[i], GLX_AUX_BUFFERS); + f->stereo = getFBConfigAttrib(window, fbconfigs[i], GLX_STEREO); if (_glfwLibrary.GLX.ARB_multisample) - result[*found].samples = getFBConfigAttrib(window, fbconfigs[i], GLX_SAMPLES); + f->samples = getFBConfigAttrib(window, fbconfigs[i], GLX_SAMPLES); else - result[*found].samples = 0; + f->samples = 0; - result[*found].platformID = (GLFWintptr) getFBConfigAttrib(window, fbconfigs[i], GLX_FBCONFIG_ID); + f->platformID = (GLFWintptr) getFBConfigAttrib(window, fbconfigs[i], GLX_FBCONFIG_ID); (*found)++; } From 7f7634a0c9e28bd44839fed3549daffb4d6792d6 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 3 Jun 2012 16:51:12 +0200 Subject: [PATCH 208/226] Added CMake toolchain file for Debian MinGW-w64. --- CMake/linux-i686-w64-mingw32.cmake | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 CMake/linux-i686-w64-mingw32.cmake diff --git a/CMake/linux-i686-w64-mingw32.cmake b/CMake/linux-i686-w64-mingw32.cmake new file mode 100644 index 00000000..9bd60936 --- /dev/null +++ b/CMake/linux-i686-w64-mingw32.cmake @@ -0,0 +1,13 @@ +# Define the environment for cross compiling from Linux to Win32 +SET(CMAKE_SYSTEM_NAME Windows) # Target system name +SET(CMAKE_SYSTEM_VERSION 1) +SET(CMAKE_C_COMPILER "i686-w64-mingw32-gcc") +SET(CMAKE_CXX_COMPILER "i686-w64-mingw32-g++") +SET(CMAKE_RC_COMPILER "i686-w64-mingw32-windres") +SET(CMAKE_RANLIB "i686-w64-mingw32-ranlib") + +# Configure the behaviour of the find commands +SET(CMAKE_FIND_ROOT_PATH "/usr/i686-w64-mingw32") +SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) From 01551e332d10287bd186bf81b270948df588c87d Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 3 Jun 2012 16:53:51 +0200 Subject: [PATCH 209/226] CMake toolchain file fixes. --- CMake/linux-amd64-mingw32msvc.cmake | 12 +++++------- CMake/linux-i586-mingw32msvc.cmake | 12 +++++------- CMake/linux-i686-pc-mingw32.cmake | 4 ++-- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/CMake/linux-amd64-mingw32msvc.cmake b/CMake/linux-amd64-mingw32msvc.cmake index 5b68540e..705e251d 100644 --- a/CMake/linux-amd64-mingw32msvc.cmake +++ b/CMake/linux-amd64-mingw32msvc.cmake @@ -1,14 +1,12 @@ -# Define the cross compilation environment for cross compiling from linux -# to Win64 it is to be used when Debian cross compilation toolchain is -# available. -SET(CMAKE_SYSTEM_NAME Windows) # Target system name -SET(CMAKE_SYSTEM_VERSION 1) # Not really used. +# Define the environment for cross compiling from Linux to Win64 +SET(CMAKE_SYSTEM_NAME Windows) +SET(CMAKE_SYSTEM_VERSION 1) SET(CMAKE_C_COMPILER "amd64-mingw32msvc-gcc") SET(CMAKE_CXX_COMPILER "amd64-mingw32msvc-g++") +SET(CMAKE_RC_COMPILER "amd64-mingw32msvc-windres") SET(CMAKE_RANLIB "amd64-mingw32msvc-ranlib") - -#Configure the behaviour of the find commands +# Configure the behaviour of the find commands SET(CMAKE_FIND_ROOT_PATH "/usr/amd64-mingw32msvc") SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) diff --git a/CMake/linux-i586-mingw32msvc.cmake b/CMake/linux-i586-mingw32msvc.cmake index 4131bc92..393ddbda 100644 --- a/CMake/linux-i586-mingw32msvc.cmake +++ b/CMake/linux-i586-mingw32msvc.cmake @@ -1,14 +1,12 @@ -# Define the cross compilation environment for cross compiling from linux -# to win32 it is to be used when debian cross compilation toolchain is -# available. -SET(CMAKE_SYSTEM_NAME Windows) # Target system name -SET(CMAKE_SYSTEM_VERSION 1) # Not really used. +# Define the environment for cross compiling from Linux to Win32 +SET(CMAKE_SYSTEM_NAME Windows) +SET(CMAKE_SYSTEM_VERSION 1) SET(CMAKE_C_COMPILER "i586-mingw32msvc-gcc") SET(CMAKE_CXX_COMPILER "i586-mingw32msvc-g++") +SET(CMAKE_RC_COMPILER "i586-mingw32msvc-windres") SET(CMAKE_RANLIB "i586-mingw32msvc-ranlib") - -#Configure the behaviour of the find commands +# Configure the behaviour of the find commands SET(CMAKE_FIND_ROOT_PATH "/usr/i586-mingw32msvc") SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) diff --git a/CMake/linux-i686-pc-mingw32.cmake b/CMake/linux-i686-pc-mingw32.cmake index 62dc8675..9a46aef7 100644 --- a/CMake/linux-i686-pc-mingw32.cmake +++ b/CMake/linux-i686-pc-mingw32.cmake @@ -1,9 +1,9 @@ -# Define the cross compilation environment for cross compiling from linux -# to win32 +# Define the environment for cross compiling from Linux to Win32 SET(CMAKE_SYSTEM_NAME Windows) # Target system name SET(CMAKE_SYSTEM_VERSION 1) SET(CMAKE_C_COMPILER "i686-pc-mingw32-gcc") SET(CMAKE_CXX_COMPILER "i686-pc-mingw32-g++") +SET(CMAKE_RC_COMPILER "i686-pc-mingw32-windres") SET(CMAKE_RANLIB "i686-pc-mingw32-ranlib") #Configure the behaviour of the find commands From bc8860dc6a0b0baf9478648590ab85e790e2c23e Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 3 Jun 2012 16:54:06 +0200 Subject: [PATCH 210/226] Made fbconfig conversion more readable. --- src/win32_window.c | 73 ++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 44 deletions(-) diff --git a/src/win32_window.c b/src/win32_window.c index 47862622..6b28cb1e 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -185,7 +185,7 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) for (i = 1; i <= available; i++) { - _GLFWfbconfig* fbconfig = fbconfigs + *found; + _GLFWfbconfig* f = fbconfigs + *found; if (window->WGL.ARB_pixel_format) { @@ -209,41 +209,26 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) continue; } - fbconfig->redBits = - getPixelFormatAttrib(window, i, WGL_RED_BITS_ARB); - fbconfig->greenBits = - getPixelFormatAttrib(window, i, WGL_GREEN_BITS_ARB); - fbconfig->blueBits = - getPixelFormatAttrib(window, i, WGL_BLUE_BITS_ARB); - fbconfig->alphaBits = - getPixelFormatAttrib(window, i, WGL_ALPHA_BITS_ARB); + f->redBits = getPixelFormatAttrib(window, i, WGL_RED_BITS_ARB); + f->greenBits = getPixelFormatAttrib(window, i, WGL_GREEN_BITS_ARB); + f->blueBits = getPixelFormatAttrib(window, i, WGL_BLUE_BITS_ARB); + f->alphaBits = getPixelFormatAttrib(window, i, WGL_ALPHA_BITS_ARB); - fbconfig->depthBits = - getPixelFormatAttrib(window, i, WGL_DEPTH_BITS_ARB); - fbconfig->stencilBits = - getPixelFormatAttrib(window, i, WGL_STENCIL_BITS_ARB); + f->depthBits = getPixelFormatAttrib(window, i, WGL_DEPTH_BITS_ARB); + f->stencilBits = getPixelFormatAttrib(window, i, WGL_STENCIL_BITS_ARB); - fbconfig->accumRedBits = - getPixelFormatAttrib(window, i, WGL_ACCUM_RED_BITS_ARB); - fbconfig->accumGreenBits = - getPixelFormatAttrib(window, i, WGL_ACCUM_GREEN_BITS_ARB); - fbconfig->accumBlueBits = - getPixelFormatAttrib(window, i, WGL_ACCUM_BLUE_BITS_ARB); - fbconfig->accumAlphaBits = - getPixelFormatAttrib(window, i, WGL_ACCUM_ALPHA_BITS_ARB); + f->accumRedBits = getPixelFormatAttrib(window, i, WGL_ACCUM_RED_BITS_ARB); + f->accumGreenBits = getPixelFormatAttrib(window, i, WGL_ACCUM_GREEN_BITS_ARB); + f->accumBlueBits = getPixelFormatAttrib(window, i, WGL_ACCUM_BLUE_BITS_ARB); + f->accumAlphaBits = getPixelFormatAttrib(window, i, WGL_ACCUM_ALPHA_BITS_ARB); - fbconfig->auxBuffers = - getPixelFormatAttrib(window, i, WGL_AUX_BUFFERS_ARB); - fbconfig->stereo = - getPixelFormatAttrib(window, i, WGL_STEREO_ARB); + f->auxBuffers = getPixelFormatAttrib(window, i, WGL_AUX_BUFFERS_ARB); + f->stereo = getPixelFormatAttrib(window, i, WGL_STEREO_ARB); if (window->WGL.ARB_multisample) - { - fbconfig->samples = - getPixelFormatAttrib(window, i, WGL_SAMPLES_ARB); - } + f->samples = getPixelFormatAttrib(window, i, WGL_SAMPLES_ARB); else - fbconfig->samples = 0; + f->samples = 0; } else { @@ -273,27 +258,27 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found) if (pfd.iPixelType != PFD_TYPE_RGBA) continue; - fbconfig->redBits = pfd.cRedBits; - fbconfig->greenBits = pfd.cGreenBits; - fbconfig->blueBits = pfd.cBlueBits; - fbconfig->alphaBits = pfd.cAlphaBits; + f->redBits = pfd.cRedBits; + f->greenBits = pfd.cGreenBits; + f->blueBits = pfd.cBlueBits; + f->alphaBits = pfd.cAlphaBits; - fbconfig->depthBits = pfd.cDepthBits; - fbconfig->stencilBits = pfd.cStencilBits; + f->depthBits = pfd.cDepthBits; + f->stencilBits = pfd.cStencilBits; - fbconfig->accumRedBits = pfd.cAccumRedBits; - fbconfig->accumGreenBits = pfd.cAccumGreenBits; - fbconfig->accumBlueBits = pfd.cAccumBlueBits; - fbconfig->accumAlphaBits = pfd.cAccumAlphaBits; + f->accumRedBits = pfd.cAccumRedBits; + f->accumGreenBits = pfd.cAccumGreenBits; + f->accumBlueBits = pfd.cAccumBlueBits; + f->accumAlphaBits = pfd.cAccumAlphaBits; - fbconfig->auxBuffers = pfd.cAuxBuffers; - fbconfig->stereo = (pfd.dwFlags & PFD_STEREO) ? GL_TRUE : GL_FALSE; + f->auxBuffers = pfd.cAuxBuffers; + f->stereo = (pfd.dwFlags & PFD_STEREO) ? GL_TRUE : GL_FALSE; // PFD pixel formats do not support FSAA - fbconfig->samples = 0; + f->samples = 0; } - fbconfig->platformID = i; + f->platformID = i; (*found)++; } From bf42c3cfbc0b405d7c746b60740377ec2d836437 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 5 Jun 2012 00:16:40 +0200 Subject: [PATCH 211/226] Made glfwGetProcAddress return a function pointer. --- include/GL/glfw3.h | 5 ++++- readme.html | 1 + src/cocoa_opengl.m | 6 +++--- src/internal.h | 2 +- src/opengl.c | 2 +- src/win32_opengl.c | 4 ++-- src/x11_opengl.c | 4 ++-- 7 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 6fd41cae..d3d48a33 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -470,6 +470,9 @@ extern "C" { * Typedefs *************************************************************************/ +/* OpenGL function pointer type */ +typedef void (*GLFWglproc)(void); + /* Window handle type */ typedef void* GLFWwindow; @@ -589,7 +592,7 @@ GLFWAPI GLFWwindow glfwGetCurrentContext(void); GLFWAPI void glfwSwapBuffers(void); GLFWAPI void glfwSwapInterval(int interval); GLFWAPI int glfwExtensionSupported(const char* extension); -GLFWAPI void* glfwGetProcAddress(const char* procname); +GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname); GLFWAPI void glfwCopyContext(GLFWwindow src, GLFWwindow dst, unsigned long mask); diff --git a/readme.html b/readme.html index e1b29330..fbc3e9d7 100644 --- a/readme.html +++ b/readme.html @@ -292,6 +292,7 @@ version of GLFW.

  • Added glfwSetGamma, glfwSetGammaRamp and glfwGetGammaRamp functions and GLFWgammaramp type for monitor gamma ramp control
  • Changed buffer bit depth parameters of glfwOpenWindow to window hints
  • Changed glfwOpenWindow and glfwSetWindowTitle to use UTF-8 encoded strings
  • +
  • Changed glfwGetProcAddress to return a (generic) function pointer
  • Renamed glfw.h to glfw3.h to avoid conflicts with 2.x series
  • Renamed GLFW_WINDOW token to GLFW_WINDOWED
  • Renamed GLFW_WINDOW_NO_RESIZE to GLFW_WINDOW_RESIZABLE
  • diff --git a/src/cocoa_opengl.m b/src/cocoa_opengl.m index 33bf4ab5..b04efaee 100644 --- a/src/cocoa_opengl.m +++ b/src/cocoa_opengl.m @@ -88,14 +88,14 @@ int _glfwPlatformExtensionSupported(const char* extension) // Get the function pointer to an OpenGL function //======================================================================== -void* _glfwPlatformGetProcAddress(const char* procname) +GLFWglproc _glfwPlatformGetProcAddress(const char* procname) { CFStringRef symbolName = CFStringCreateWithCString(kCFAllocatorDefault, procname, kCFStringEncodingASCII); - void* symbol = CFBundleGetFunctionPointerForName(_glfwLibrary.NSGL.framework, - symbolName); + GLFWglproc symbol = CFBundleGetFunctionPointerForName(_glfwLibrary.NSGL.framework, + symbolName); CFRelease(symbolName); diff --git a/src/internal.h b/src/internal.h index 5293caf4..ec2bab10 100644 --- a/src/internal.h +++ b/src/internal.h @@ -327,7 +327,7 @@ void _glfwPlatformSwapBuffers(void); void _glfwPlatformSwapInterval(int interval); void _glfwPlatformRefreshWindowParams(void); int _glfwPlatformExtensionSupported(const char* extension); -void* _glfwPlatformGetProcAddress(const char* procname); +GLFWglproc _glfwPlatformGetProcAddress(const char* procname); void _glfwPlatformCopyContext(_GLFWwindow* src, _GLFWwindow* dst, unsigned long mask); diff --git a/src/opengl.c b/src/opengl.c index b35f8694..67b5e728 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -613,7 +613,7 @@ GLFWAPI int glfwExtensionSupported(const char* extension) // This function can be used to get access to extended OpenGL functions. //======================================================================== -GLFWAPI void* glfwGetProcAddress(const char* procname) +GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname) { if (!_glfwInitialized) { diff --git a/src/win32_opengl.c b/src/win32_opengl.c index 2262c222..f6275782 100644 --- a/src/win32_opengl.c +++ b/src/win32_opengl.c @@ -111,9 +111,9 @@ int _glfwPlatformExtensionSupported(const char* extension) // Get the function pointer to an OpenGL function //======================================================================== -void* _glfwPlatformGetProcAddress(const char* procname) +GLFWglproc _glfwPlatformGetProcAddress(const char* procname) { - return (void*) wglGetProcAddress(procname); + return wglGetProcAddress(procname); } diff --git a/src/x11_opengl.c b/src/x11_opengl.c index ac1974f1..dc2788c8 100644 --- a/src/x11_opengl.c +++ b/src/x11_opengl.c @@ -752,9 +752,9 @@ int _glfwPlatformExtensionSupported(const char* extension) // Get the function pointer to an OpenGL function //======================================================================== -void* _glfwPlatformGetProcAddress(const char* procname) +GLFWglproc _glfwPlatformGetProcAddress(const char* procname) { - return (void*) _glfw_glXGetProcAddress((const GLubyte*) procname); + return _glfw_glXGetProcAddress((const GLubyte*) procname); } From 22134508406c8cd6f3974aed326e7c667e6fa625 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 5 Jun 2012 23:55:10 +0200 Subject: [PATCH 212/226] Renamed GLFW_NO_GLU to GLFW_INCLUDE_GLU. --- examples/boing.c | 2 ++ examples/splitview.c | 2 ++ examples/triangle.c | 1 + examples/wave.c | 2 ++ include/GL/glfw3.h | 10 +++------- readme.html | 1 + tests/accuracy.c | 1 + tests/fsaa.c | 1 + tests/sharing.c | 1 + 9 files changed, 14 insertions(+), 7 deletions(-) diff --git a/examples/boing.c b/examples/boing.c index 33696e46..49d602ca 100644 --- a/examples/boing.c +++ b/examples/boing.c @@ -30,6 +30,8 @@ #include #include #include + +#define GLFW_INCLUDE_GLU #include diff --git a/examples/splitview.c b/examples/splitview.c index 2cd43fdf..0f27d32e 100644 --- a/examples/splitview.c +++ b/examples/splitview.c @@ -10,7 +10,9 @@ // because I am not a friend of orthogonal projections) //======================================================================== +#define GLFW_INCLUDE_GLU #include + #include #include #include diff --git a/examples/triangle.c b/examples/triangle.c index e61ea9ab..0f6631d0 100644 --- a/examples/triangle.c +++ b/examples/triangle.c @@ -7,6 +7,7 @@ #include #include +#define GLFW_INCLUDE_GLU #include int main(void) diff --git a/examples/wave.c b/examples/wave.c index 8ecee51f..44bae584 100644 --- a/examples/wave.c +++ b/examples/wave.c @@ -11,6 +11,8 @@ #include #include #include + +#define GLFW_INCLUDE_GLU #include #ifndef M_PI diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index d3d48a33..c77561b1 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -146,11 +146,7 @@ extern "C" { /* -------------------- END SYSTEM/COMPILER SPECIFIC --------------------- */ -/* Include standard OpenGL headers: GLFW uses GL_FALSE/GL_TRUE, and it is - * convenient for the user to only have to include . This also - * solves the problem with Windows and needing some - * special defines which normally requires the user to include - * (which is not a nice solution for portable programs). +/* Include the chosen OpenGL header and, optionally, the GLU header. */ #if defined(__APPLE_CC__) #if defined(GLFW_INCLUDE_GL3) @@ -159,7 +155,7 @@ extern "C" { #define GL_GLEXT_LEGACY #include #endif - #ifndef GLFW_NO_GLU + #if defined(GLFW_INCLUDE_GLU) #include #endif #else @@ -168,7 +164,7 @@ extern "C" { #else #include #endif - #ifndef GLFW_NO_GLU + #if defined(GLFW_INCLUDE_GLU) #include #endif #endif diff --git a/readme.html b/readme.html index fbc3e9d7..020e0802 100644 --- a/readme.html +++ b/readme.html @@ -298,6 +298,7 @@ version of GLFW.

  • Renamed GLFW_WINDOW_NO_RESIZE to GLFW_WINDOW_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
  • 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, floating point scrolling interface
  • diff --git a/tests/accuracy.c b/tests/accuracy.c index f235cf75..ae572987 100644 --- a/tests/accuracy.c +++ b/tests/accuracy.c @@ -29,6 +29,7 @@ // //======================================================================== +#define GLFW_INCLUDE_GLU #include #include diff --git a/tests/fsaa.c b/tests/fsaa.c index 6cdb77e0..9c45ddcc 100644 --- a/tests/fsaa.c +++ b/tests/fsaa.c @@ -29,6 +29,7 @@ // //======================================================================== +#define GLFW_INCLUDE_GLU #include #include diff --git a/tests/sharing.c b/tests/sharing.c index 7d774151..6f1df980 100644 --- a/tests/sharing.c +++ b/tests/sharing.c @@ -27,6 +27,7 @@ // //======================================================================== +#define GLFW_INCLUDE_GLU #include #include From 9cc0abffc56a0cfd18535660008d0ae999b85701 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 6 Jun 2012 02:04:15 +0200 Subject: [PATCH 213/226] Rewrote joystick test. --- readme.html | 1 + tests/joysticks.c | 260 +++++++++++++++++++++++++++++----------------- 2 files changed, 168 insertions(+), 93 deletions(-) diff --git a/readme.html b/readme.html index 020e0802..58324228 100644 --- a/readme.html +++ b/readme.html @@ -303,6 +303,7 @@ version of GLFW.

  • Replaced layout-dependent key codes with single, platform-independent set based on US layout
  • Replaced mouse wheel interface with two-dimensional, floating point scrolling interface
  • Replaced glfwEnable and glfwDisable with glfwGetInputMode and glfwSetInputMode
  • +
  • Replaced joystick test with graphical version
  • Made Unicode character input unaffected by GLFW_KEY_REPEAT
  • Removed event auto-polling and the GLFW_AUTO_POLL_EVENTS window enable
  • Removed the Win32 port .def files
  • diff --git a/tests/joysticks.c b/tests/joysticks.c index 23ac88a3..2f208d2b 100644 --- a/tests/joysticks.c +++ b/tests/joysticks.c @@ -1,142 +1,216 @@ -/*======================================================================== - * This is a small test application for GLFW. - * joystick input test. - *========================================================================*/ +//======================================================================== +// Joystick input test +// Copyright (c) Camilla Berglund +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would +// be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not +// be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source +// distribution. +// +//======================================================================== +// +// This test displays the state of every button and axis of every connected +// joystick and/or gamepad +// +//======================================================================== #include #include +#include #include -#include -#define MAX_AXES 10 -#define MAX_BUTTONS 30 - -struct JoystickState +typedef struct Joystick { - int present; - int num_axes; - int num_buttons; - float axes[MAX_AXES]; - unsigned char buttons[MAX_BUTTONS]; -}; + GLboolean present; + float* axes; + unsigned char* buttons; + int axis_count; + int button_count; +} Joystick; -static struct JoystickState states[GLFW_JOYSTICK_LAST + 1]; +static Joystick joysticks[GLFW_JOYSTICK_LAST - GLFW_JOYSTICK_1 + 1]; -int running; -int keyrepeat = 0; -int systemkeys = 1; +static int joystick_count = 0; - -/*======================================================================== - * Retrieve joystick states - *========================================================================*/ -static void updateJoysticksState(void) +static void window_size_callback(GLFWwindow window, int width, int height) { - int joy; + glViewport(0, 0, width, height); +} - for (joy = GLFW_JOYSTICK_1; joy < GLFW_JOYSTICK_LAST + 1; joy++) +static void draw_joystick(Joystick* j, int x, int y, int width, int height) +{ + int i; + int axis_width, axis_height; + int button_width, button_height; + + axis_width = width / j->axis_count; + axis_height = 3 * height / 4; + + button_width = width / j->button_count; + button_height = height / 4; + + for (i = 0; i < j->axis_count; i++) { - printf("Updating information for joystick %d\n", joy); - states[joy].present = glfwGetJoystickParam(joy, GLFW_PRESENT); - if (states[joy].present == GL_TRUE) + float value = j->axes[i] / 2.f + 0.5f; + + glColor3f(0.3f, 0.3f, 0.3f); + glRecti(x + i * axis_width, + y, + x + (i + 1) * axis_width, + y + axis_height); + + glColor3f(1.f, 1.f, 1.f); + glRecti(x + i * axis_width, + y + (int) (value * (axis_height - 5)), + x + (i + 1) * axis_width, + y + 5 + (int) (value * (axis_height - 5))); + } + + for (i = 0; i < j->button_count; i++) + { + if (j->buttons[i]) + glColor3f(1.f, 1.f, 1.f); + else + glColor3f(0.3f, 0.3f, 0.3f); + + glRecti(x + i * button_width, + y + axis_height, + x + (i + 1) * button_width, + y + axis_height + button_height); + } +} + +static void draw_joysticks(void) +{ + int i, width, height; + + glfwGetWindowSize(glfwGetCurrentContext(), &width, &height); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0.f, width, height, 0.f, 1.f, -1.f); + glMatrixMode(GL_MODELVIEW); + + for (i = 0; i < sizeof(joysticks) / sizeof(Joystick); i++) + { + Joystick* j = joysticks + i; + + if (j->present) { - states[joy].num_axes = glfwGetJoystickPos(joy, states[joy].axes, MAX_AXES); - states[joy].num_buttons = glfwGetJoystickButtons(joy, states[joy].buttons, MAX_BUTTONS); + draw_joystick(j, + 0, i * height / joystick_count, + width, height / joystick_count); } } } -/*======================================================================== - * Print out the state of all joysticks on the standard output - *========================================================================*/ -static void displayJoysticksState(void) +static void refresh_joysticks(void) { - int joy; int i; - for (joy = GLFW_JOYSTICK_1; joy < GLFW_JOYSTICK_LAST + 1; joy++) + for (i = 0; i < sizeof(joysticks) / sizeof(Joystick); i++) { - printf("Joystick %d: %s\n", joy, (states[joy].present == GL_TRUE ? "present" : "not connected")); + Joystick* j = joysticks + i; - if (states[joy].present == GL_TRUE) + if (glfwGetJoystickParam(GLFW_JOYSTICK_1 + i, GLFW_PRESENT)) { - if (states[joy].num_axes > 0) + int axis_count, button_count; + + axis_count = glfwGetJoystickParam(GLFW_JOYSTICK_1 + i, GLFW_AXES); + if (axis_count != j->axis_count) { - printf(" axes: %.3f", states[joy].axes[0]); - for (i = 1; i < states[joy].num_axes; i++) - printf(", %.3f", states[joy].axes[i]); - - printf("\n"); + j->axis_count = axis_count; + j->axes = realloc(j->axes, j->axis_count * sizeof(float)); } - else - printf(" axes: none\n"); - if (states[joy].num_buttons > 0) + glfwGetJoystickPos(GLFW_JOYSTICK_1 + i, j->axes, j->axis_count); + + button_count = glfwGetJoystickParam(GLFW_JOYSTICK_1 + i, GLFW_BUTTONS); + if (button_count != j->button_count) { - printf(" buttons: 00 => %c", ((states[joy].buttons[0] == GLFW_PRESS) ? 'P' : 'R')); - - for (i = 1; i < states[joy].num_buttons; i++) - printf(", %02d => %c", i, ((states[joy].buttons[i] == GLFW_PRESS) ? 'P' : 'R')); - - printf("\n"); + j->button_count = button_count; + j->buttons = realloc(j->buttons, j->button_count); + } + + glfwGetJoystickButtons(GLFW_JOYSTICK_1 + i, j->buttons, j->button_count); + + if (!j->present) + { + printf("Found joystick %i with %i axes, %i buttons\n", + i + 1, j->axis_count, j->button_count); + + joystick_count++; + } + + j->present = GL_TRUE; + } + else + { + if (j->present) + { + free(j->axes); + free(j->buttons); + memset(j, 0, sizeof(Joystick)); + + printf("Lost joystick %i\n", i + 1); + + joystick_count--; } - else - printf(" buttons: none\n"); } } } int main(void) { - double start; - double t; - double update; + GLFWwindow window; + + memset(joysticks, 0, sizeof(joysticks)); - /* Initialise GLFW */ if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW: %s\n", glfwErrorString(glfwGetError())); exit(EXIT_FAILURE); } - printf("The program will work for 20 seconds and display every seconds the state of the joysticks\n"); - printf("Your computer is going to be very slow as the program is doing an active loop .....\n"); - - start = glfwGetTime(); - update = start; - - /* print the initial state of all joysticks */ - updateJoysticksState(); - printf("\n"); - displayJoysticksState(); - - running = GL_TRUE; - - /* Main loop */ - while (running) + window = glfwOpenWindow(0, 0, GLFW_WINDOWED, "Joystick Test", NULL); + if (!window) { - /* Get time */ - t = glfwGetTime(); + glfwTerminate(); - /* Display the state of all connected joysticks every secons */ - if ((t - update) > 1.0) - { - update = t; - printf("\n"); - updateJoysticksState(); - printf("\n"); - displayJoysticksState(); - } - - /* Check if the window was closed */ - if ((t - start) > 20.0) - running = GL_FALSE; + fprintf(stderr, "Failed to open GLFW window: %s\n", glfwErrorString(glfwGetError())); + exit(EXIT_FAILURE); } - /* Close OpenGL window and terminate GLFW */ - glfwTerminate(); + glfwSetWindowSizeCallback(window_size_callback); + glfwSwapInterval(1); - return 0; + while (glfwIsWindow(window)) + { + glClear(GL_COLOR_BUFFER_BIT); + + refresh_joysticks(); + draw_joysticks(); + + glfwSwapBuffers(); + glfwPollEvents(); + } + + glfwTerminate(); + exit(EXIT_SUCCESS); } From fb2dbd6a5392a325d0071bdab7f91333f164440d Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 8 Jun 2012 01:53:41 +0200 Subject: [PATCH 214/226] Fixed Win32 warning. --- src/win32_opengl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/win32_opengl.c b/src/win32_opengl.c index f6275782..5e94d7da 100644 --- a/src/win32_opengl.c +++ b/src/win32_opengl.c @@ -113,7 +113,7 @@ int _glfwPlatformExtensionSupported(const char* extension) GLFWglproc _glfwPlatformGetProcAddress(const char* procname) { - return wglGetProcAddress(procname); + return (GLFWglproc) wglGetProcAddress(procname); } From ed9890f1105a299c369abb50c2ef53f3b5c6a291 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 11 Jun 2012 13:47:06 +0200 Subject: [PATCH 215/226] Fixed typecast warning. --- src/win32_opengl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/win32_opengl.c b/src/win32_opengl.c index f6275782..5e94d7da 100644 --- a/src/win32_opengl.c +++ b/src/win32_opengl.c @@ -113,7 +113,7 @@ int _glfwPlatformExtensionSupported(const char* extension) GLFWglproc _glfwPlatformGetProcAddress(const char* procname) { - return wglGetProcAddress(procname); + return (GLFWglproc) wglGetProcAddress(procname); } From 31b06a0ae0a1b31a671762477fbb1daacc9de0c4 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 11 Jun 2012 14:02:25 +0200 Subject: [PATCH 216/226] Win32 window position work. --- src/win32_window.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/win32_window.c b/src/win32_window.c index 6b28cb1e..6a29c86f 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1047,6 +1047,11 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, case WM_MOVE: { + RECT rect; + + GetClientRect(window->Win32.handle, &rect); + AdjustWindowRectEx(&rect, window->Win32.dwStyle, FALSE, window->Win32.dwExStyle); + // If window is in cursor capture mode, update clipping rect if (window->cursorMode == GLFW_CURSOR_CAPTURED) { @@ -1055,7 +1060,9 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, ClipCursor(&ClipWindowRect); } - _glfwInputWindowPos(window, LOWORD(lParam), HIWORD(lParam)); + _glfwInputWindowPos(window, + LOWORD(lParam) - rect.left, + HIWORD(lParam) - rect.top); return 0; } @@ -1632,7 +1639,13 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y) { - SetWindowPos(window->Win32.handle, HWND_TOP, x, y, 0, 0, + RECT rect; + + GetClientRect(window->Win32.handle, &rect); + AdjustWindowRectEx(&rect, window->Win32.dwStyle, FALSE, window->Win32.dwExStyle); + + SetWindowPos(window->Win32.handle, HWND_TOP, + x + rect.left, y + rect.top, 0, 0, SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER); } From 0c49e9ec872eaada03b2abd8e2a39d56e19e695d Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 11 Jun 2012 14:13:05 +0200 Subject: [PATCH 217/226] Fixed function pointer casting. --- examples/heightmap.c | 52 ++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/examples/heightmap.c b/examples/heightmap.c index f4bec28c..75a694e9 100644 --- a/examples/heightmap.c +++ b/examples/heightmap.c @@ -84,7 +84,7 @@ static PFNGLVERTEXATTRIBPOINTERPROC pglVertexAttribPointer = NULL; #define RESOLVE_GL_FCN(type, var, name) \ if (status == GL_TRUE) \ {\ - var = glfwGetProcAddress((name));\ + var = (type) glfwGetProcAddress((name));\ if ((var) == NULL)\ {\ status = GL_FALSE;\ @@ -95,31 +95,31 @@ static PFNGLVERTEXATTRIBPOINTERPROC pglVertexAttribPointer = NULL; static GLboolean init_opengl(void) { GLboolean status = GL_TRUE; - RESOLVE_GL_FCN(PFN_glCreateShader, pglCreateShader, "glCreateShader"); - RESOLVE_GL_FCN(PFN_glShaderSource, pglShaderSource, "glShaderSource"); - RESOLVE_GL_FCN(PFN_glCompileShader, pglCompileShader, "glCompileShader"); - RESOLVE_GL_FCN(PFN_glGetShaderiv, pglGetShaderiv, "glGetShaderiv"); - RESOLVE_GL_FCN(PFN_glGetShaderInfoLog, pglGetShaderInfoLog, "glGetShaderInfoLog"); - RESOLVE_GL_FCN(PFN_glDeleteShader, pglDeleteShader, "glDeleteShader"); - RESOLVE_GL_FCN(PFN_glCreateProgram, pglCreateProgram, "glCreateProgram"); - RESOLVE_GL_FCN(PFN_glAttachShader, pglAttachShader, "glAttachShader"); - RESOLVE_GL_FCN(PFN_glLinkProgram, pglLinkProgram, "glLinkProgram"); - RESOLVE_GL_FCN(PFN_glUseProgram, pglUseProgram, "glUseProgram"); - RESOLVE_GL_FCN(PFN_glGetProgramiv, pglGetProgramiv, "glGetProgramiv"); - RESOLVE_GL_FCN(PFN_glGetProgramInfoLog, pglGetProgramInfoLog, "glGetProgramInfoLog"); - RESOLVE_GL_FCN(PFN_glDeleteProgram, pglDeleteProgram, "glDeleteProgram"); - RESOLVE_GL_FCN(PFN_glGetUniformLocation, pglGetUniformLocation, "glGetUniformLocation"); - RESOLVE_GL_FCN(PFN_glUniformMatrix4fv, pglUniformMatrix4fv, "glUniformMatrix4fv"); - RESOLVE_GL_FCN(PFN_glGetAttribLocation, pglGetAttribLocation, "glGetAttribLocation"); - RESOLVE_GL_FCN(PFN_glGenVertexArrays, pglGenVertexArrays, "glGenVertexArrays"); - RESOLVE_GL_FCN(PFN_glDeleteVertexArrays, pglDeleteVertexArrays, "glDeleteVertexArrays"); - RESOLVE_GL_FCN(PFN_glBindVertexArray, pglBindVertexArray, "glBindVertexArray"); - RESOLVE_GL_FCN(PFN_glGenBuffers, pglGenBuffers, "glGenBuffers"); - RESOLVE_GL_FCN(PFN_glBindBuffer, pglBindBuffer, "glBindBuffer"); - RESOLVE_GL_FCN(PFN_glBufferData, pglBufferData, "glBufferData"); - RESOLVE_GL_FCN(PFN_glBufferSubData, pglBufferSubData, "glBufferSubData"); - RESOLVE_GL_FCN(PFN_glEnableVertexAttribArray, pglEnableVertexAttribArray, "glEnableVertexAttribArray"); - RESOLVE_GL_FCN(PFN_glVertexAttribPointer, pglVertexAttribPointer, "glVertexAttribPointer"); + RESOLVE_GL_FCN(PFNGLCREATESHADERPROC, pglCreateShader, "glCreateShader"); + RESOLVE_GL_FCN(PFNGLSHADERSOURCEPROC, pglShaderSource, "glShaderSource"); + RESOLVE_GL_FCN(PFNGLCOMPILESHADERPROC, pglCompileShader, "glCompileShader"); + RESOLVE_GL_FCN(PFNGLGETSHADERIVPROC, pglGetShaderiv, "glGetShaderiv"); + RESOLVE_GL_FCN(PFNGLGETSHADERINFOLOGPROC, pglGetShaderInfoLog, "glGetShaderInfoLog"); + RESOLVE_GL_FCN(PFNGLDELETESHADERPROC, pglDeleteShader, "glDeleteShader"); + RESOLVE_GL_FCN(PFNGLCREATEPROGRAMPROC, pglCreateProgram, "glCreateProgram"); + RESOLVE_GL_FCN(PFNGLATTACHSHADERPROC, pglAttachShader, "glAttachShader"); + RESOLVE_GL_FCN(PFNGLLINKPROGRAMPROC, pglLinkProgram, "glLinkProgram"); + RESOLVE_GL_FCN(PFNGLUSEPROGRAMPROC, pglUseProgram, "glUseProgram"); + RESOLVE_GL_FCN(PFNGLGETPROGRAMIVPROC, pglGetProgramiv, "glGetProgramiv"); + RESOLVE_GL_FCN(PFNGLGETPROGRAMINFOLOGPROC, pglGetProgramInfoLog, "glGetProgramInfoLog"); + RESOLVE_GL_FCN(PFNGLDELETEPROGRAMPROC, pglDeleteProgram, "glDeleteProgram"); + RESOLVE_GL_FCN(PFNGLGETUNIFORMLOCATIONPROC, pglGetUniformLocation, "glGetUniformLocation"); + RESOLVE_GL_FCN(PFNGLUNIFORMMATRIX4FVPROC, pglUniformMatrix4fv, "glUniformMatrix4fv"); + RESOLVE_GL_FCN(PFNGLGETATTRIBLOCATIONPROC, pglGetAttribLocation, "glGetAttribLocation"); + RESOLVE_GL_FCN(PFNGLGENVERTEXARRAYSPROC, pglGenVertexArrays, "glGenVertexArrays"); + RESOLVE_GL_FCN(PFNGLDELETEVERTEXARRAYSPROC, pglDeleteVertexArrays, "glDeleteVertexArrays"); + RESOLVE_GL_FCN(PFNGLBINDVERTEXARRAYPROC, pglBindVertexArray, "glBindVertexArray"); + RESOLVE_GL_FCN(PFNGLGENBUFFERSPROC, pglGenBuffers, "glGenBuffers"); + RESOLVE_GL_FCN(PFNGLBINDBUFFERPROC, pglBindBuffer, "glBindBuffer"); + RESOLVE_GL_FCN(PFNGLBUFFERDATAPROC, pglBufferData, "glBufferData"); + RESOLVE_GL_FCN(PFNGLBUFFERSUBDATAPROC, pglBufferSubData, "glBufferSubData"); + RESOLVE_GL_FCN(PFNGLENABLEVERTEXATTRIBARRAYPROC, pglEnableVertexAttribArray, "glEnableVertexAttribArray"); + RESOLVE_GL_FCN(PFNGLVERTEXATTRIBPOINTERPROC, pglVertexAttribPointer, "glVertexAttribPointer"); return status; } /********************************************************************** From 9871b5dc79d0c181630e8f888acb55caf22e2246 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 11 Jun 2012 14:14:00 +0200 Subject: [PATCH 218/226] Removed deprecated macro. --- examples/heightmap.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/heightmap.c b/examples/heightmap.c index 75a694e9..e926581a 100644 --- a/examples/heightmap.c +++ b/examples/heightmap.c @@ -32,8 +32,6 @@ #include #include "getopt.h" - -#define GLFW_NO_GLU 1 #include #include From 41be34eadf6fcbc1bb1a69b94c1262cae847faf8 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 12 Jun 2012 02:29:18 +0200 Subject: [PATCH 219/226] Fixed window position on Win32. --- src/win32_window.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) mode change 100644 => 100755 src/win32_window.c diff --git a/src/win32_window.c b/src/win32_window.c old mode 100644 new mode 100755 index 6a29c86f..4990be45 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1047,11 +1047,6 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, case WM_MOVE: { - RECT rect; - - GetClientRect(window->Win32.handle, &rect); - AdjustWindowRectEx(&rect, window->Win32.dwStyle, FALSE, window->Win32.dwExStyle); - // If window is in cursor capture mode, update clipping rect if (window->cursorMode == GLFW_CURSOR_CAPTURED) { @@ -1060,9 +1055,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, ClipCursor(&ClipWindowRect); } - _glfwInputWindowPos(window, - LOWORD(lParam) - rect.left, - HIWORD(lParam) - rect.top); + _glfwInputWindowPos(window, LOWORD(lParam), HIWORD(lParam)); return 0; } From 14bcc51f3b8a1a5264467a087151f1c13336ee6d Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 12 Jun 2012 03:00:16 +0200 Subject: [PATCH 220/226] Removed config macro values. --- src/config.h.in | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/config.h.in b/src/config.h.in index a5b3172d..01d541a2 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -43,28 +43,28 @@ #cmakedefine _GLFW_COCOA_NSGL // Define this to 1 if building as a shared library / dynamic library / DLL -#cmakedefine _GLFW_BUILD_DLL 1 +#cmakedefine _GLFW_BUILD_DLL // Define this to 1 to disable dynamic loading of winmm -#cmakedefine _GLFW_NO_DLOAD_WINMM 1 +#cmakedefine _GLFW_NO_DLOAD_WINMM // Define this to 1 if XRandR is available -#cmakedefine _GLFW_HAS_XRANDR 1 +#cmakedefine _GLFW_HAS_XRANDR // Define this to 1 if Xf86VidMode is available -#cmakedefine _GLFW_HAS_XF86VIDMODE 1 +#cmakedefine _GLFW_HAS_XF86VIDMODE // Define this to 1 if Xkb is available -#cmakedefine _GLFW_HAS_XKB 1 +#cmakedefine _GLFW_HAS_XKB // Define this to 1 if glXGetProcAddress is available -#cmakedefine _GLFW_HAS_GLXGETPROCADDRESS 1 +#cmakedefine _GLFW_HAS_GLXGETPROCADDRESS // Define this to 1 if glXGetProcAddressARB is available -#cmakedefine _GLFW_HAS_GLXGETPROCADDRESSARB 1 +#cmakedefine _GLFW_HAS_GLXGETPROCADDRESSARB // Define this to 1 if glXGetProcAddressEXT is available -#cmakedefine _GLFW_HAS_GLXGETPROCADDRESSEXT 1 +#cmakedefine _GLFW_HAS_GLXGETPROCADDRESSEXT // Define this to 1 if the Linux joystick API is available -#cmakedefine _GLFW_USE_LINUX_JOYSTICKS 1 +#cmakedefine _GLFW_USE_LINUX_JOYSTICKS // The GLFW version as used by glfwGetVersionString #define _GLFW_VERSION_FULL "@GLFW_VERSION_FULL@" From acdda3ef4fa170146da0f5d2f73b8419a2cd70f7 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 17 Jun 2012 16:35:48 +0200 Subject: [PATCH 221/226] Added toolchain files for MinGW-w64 on Cygwin. --- ...-mingw32.cmake => cygwin-i686-w64-mingw32.cmake} | 0 CMake/cygwin-x86_64-w64-mingw32.cmake | 13 +++++++++++++ 2 files changed, 13 insertions(+) rename CMake/{linux-i686-w64-mingw32.cmake => cygwin-i686-w64-mingw32.cmake} (100%) create mode 100644 CMake/cygwin-x86_64-w64-mingw32.cmake diff --git a/CMake/linux-i686-w64-mingw32.cmake b/CMake/cygwin-i686-w64-mingw32.cmake similarity index 100% rename from CMake/linux-i686-w64-mingw32.cmake rename to CMake/cygwin-i686-w64-mingw32.cmake diff --git a/CMake/cygwin-x86_64-w64-mingw32.cmake b/CMake/cygwin-x86_64-w64-mingw32.cmake new file mode 100644 index 00000000..84b2c701 --- /dev/null +++ b/CMake/cygwin-x86_64-w64-mingw32.cmake @@ -0,0 +1,13 @@ +# Define the environment for cross compiling from Linux to Win32 +SET(CMAKE_SYSTEM_NAME Windows) # Target system name +SET(CMAKE_SYSTEM_VERSION 1) +SET(CMAKE_C_COMPILER "x86_64-w64-mingw32-gcc") +SET(CMAKE_CXX_COMPILER "x86_64-w64-mingw32-g++") +SET(CMAKE_RC_COMPILER "x86_64-w64-mingw32-windres") +SET(CMAKE_RANLIB "x86_64-w64-mingw32-ranlib") + +# Configure the behaviour of the find commands +SET(CMAKE_FIND_ROOT_PATH "/usr/x86_64-w64-mingw32") +SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) From cea0e304992afb84bc381b13d09f140157c29a68 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Thu, 21 Jun 2012 13:35:35 +0200 Subject: [PATCH 222/226] Fixed cursor centering using wrong mode. --- readme.html | 1 + src/input.c | 28 ++++++++++++---------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/readme.html b/readme.html index 58324228..086f18f5 100644 --- a/readme.html +++ b/readme.html @@ -319,6 +319,7 @@ version of GLFW.

  • 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
  • +
  • Bugfix: Cursor centering upon leaving captured cursor mode was reported before the mode was changed to non-captured
  • [Cocoa] Added support for OpenGL 3.2 core profile in 10.7 Lion and above
  • [Cocoa] Added support for joysticks
  • [Cocoa] Postponed menu creation to first window creation
  • diff --git a/src/input.c b/src/input.c index ac37af0d..90ada563 100644 --- a/src/input.c +++ b/src/input.c @@ -35,37 +35,33 @@ // Sets the cursor mode for the specified window //======================================================================== -static void setCursorMode(_GLFWwindow* window, int mode) +static void setCursorMode(_GLFWwindow* window, int newMode) { - int centerPosX, centerPosY; + int oldMode, centerPosX, centerPosY; - if (mode != GLFW_CURSOR_NORMAL && - mode != GLFW_CURSOR_HIDDEN && - mode != GLFW_CURSOR_CAPTURED) + if (newMode != GLFW_CURSOR_NORMAL && + newMode != GLFW_CURSOR_HIDDEN && + newMode != GLFW_CURSOR_CAPTURED) { _glfwSetError(GLFW_INVALID_ENUM, NULL); return; } - if (window->cursorMode == mode) + oldMode = window->cursorMode; + if (oldMode == newMode) return; centerPosX = window->width / 2; centerPosY = window->height / 2; - if (mode == GLFW_CURSOR_CAPTURED) + if (oldMode == GLFW_CURSOR_CAPTURED || newMode == GLFW_CURSOR_CAPTURED) _glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY); - else if (window->cursorMode == GLFW_CURSOR_CAPTURED) - { - _glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY); - _glfwInputCursorMotion(window, - centerPosX - window->cursorPosX, - centerPosY - window->cursorPosY); - } - _glfwPlatformSetCursorMode(window, mode); + _glfwPlatformSetCursorMode(window, newMode); + window->cursorMode = newMode; - window->cursorMode = mode; + if (oldMode == GLFW_CURSOR_CAPTURED) + _glfwInputCursorMotion(window, window->cursorPosX, window->cursorPosY); } From cef9dea1d236100b1a4b0d41b698dcb2359175cc Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Fri, 22 Jun 2012 13:53:02 +0200 Subject: [PATCH 223/226] Unified nomenclature for cursor positions. --- examples/splitview.c | 6 ++--- examples/triangle.c | 2 +- examples/wave.c | 6 ++--- include/GL/glfw3.h | 8 +++--- readme.html | 1 + src/cocoa_window.m | 6 ++--- src/input.c | 26 +++++++++--------- src/internal.h | 4 +-- src/win32_platform.h | 2 +- src/win32_window.c | 64 ++++++++++++++++++++++---------------------- src/x11_window.c | 52 +++++++++++++++++------------------ tests/accuracy.c | 4 +-- tests/events.c | 6 ++--- tests/peter.c | 16 +++++------ 14 files changed, 102 insertions(+), 101 deletions(-) diff --git a/examples/splitview.c b/examples/splitview.c index 0f27d32e..c584f9af 100644 --- a/examples/splitview.c +++ b/examples/splitview.c @@ -379,7 +379,7 @@ static void windowRefreshFun(GLFWwindow window) // Mouse position callback function //======================================================================== -static void mousePosFun(GLFWwindow window, int x, int y) +static void cursorPosFun(GLFWwindow window, int x, int y) { // Depending on which view was selected, rotate around different axes switch (active_view) @@ -404,7 +404,7 @@ static void mousePosFun(GLFWwindow window, int x, int y) break; } - // Remember mouse position + // Remember cursor position xpos = x; ypos = y; } @@ -472,7 +472,7 @@ int main(void) // Set callback functions glfwSetWindowSizeCallback(windowSizeFun); glfwSetWindowRefreshCallback(windowRefreshFun); - glfwSetMousePosCallback(mousePosFun); + glfwSetCursorPosCallback(cursorPosFun); glfwSetMouseButtonCallback(mouseButtonFun); // Main loop diff --git a/examples/triangle.c b/examples/triangle.c index 0f6631d0..ee340496 100644 --- a/examples/triangle.c +++ b/examples/triangle.c @@ -39,7 +39,7 @@ int main(void) do { double t = glfwGetTime(); - glfwGetMousePos(window, &x, NULL); + glfwGetCursorPos(window, &x, NULL); // Get window size (may be different than the requested size) glfwGetWindowSize(window, &width, &height); diff --git a/examples/wave.c b/examples/wave.c index 44bae584..54574839 100644 --- a/examples/wave.c +++ b/examples/wave.c @@ -323,10 +323,10 @@ void mouse_button_callback(GLFWwindow window, int button, int action) //======================================================================== -// Callback function for mouse motion events +// Callback function for cursor motion events //======================================================================== -void mouse_position_callback(GLFWwindow window, int x, int y) +void cursor_position_callback(GLFWwindow window, int x, int y) { if (locked) { @@ -403,7 +403,7 @@ int main(int argc, char* argv[]) // Window resize handler glfwSetWindowSizeCallback(window_resize_callback); glfwSetMouseButtonCallback(mouse_button_callback); - glfwSetMousePosCallback(mouse_position_callback); + glfwSetCursorPosCallback(cursor_position_callback); glfwSetScrollCallback(scroll_callback); // Initialize OpenGL diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index c77561b1..28e38bd1 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -480,7 +480,7 @@ typedef void (* GLFWwindowrefreshfun)(GLFWwindow); typedef void (* GLFWwindowfocusfun)(GLFWwindow,int); typedef void (* GLFWwindowiconifyfun)(GLFWwindow,int); typedef void (* GLFWmousebuttonfun)(GLFWwindow,int,int); -typedef void (* GLFWmouseposfun)(GLFWwindow,int,int); +typedef void (* GLFWcursorposfun)(GLFWwindow,int,int); typedef void (* GLFWcursorenterfun)(GLFWwindow,int); typedef void (* GLFWscrollfun)(GLFWwindow,double,double); typedef void (* GLFWkeyfun)(GLFWwindow,int,int); @@ -559,13 +559,13 @@ GLFWAPI int glfwGetInputMode(GLFWwindow window, int mode); GLFWAPI void glfwSetInputMode(GLFWwindow window, int mode, int value); GLFWAPI int glfwGetKey(GLFWwindow window, int key); GLFWAPI int glfwGetMouseButton(GLFWwindow window, int button); -GLFWAPI void glfwGetMousePos(GLFWwindow window, int* xpos, int* ypos); -GLFWAPI void glfwSetMousePos(GLFWwindow window, int xpos, int ypos); +GLFWAPI void glfwGetCursorPos(GLFWwindow window, int* xpos, int* ypos); +GLFWAPI void glfwSetCursorPos(GLFWwindow window, int xpos, int ypos); GLFWAPI void glfwGetScrollOffset(GLFWwindow window, double* xoffset, double* yoffset); GLFWAPI void glfwSetKeyCallback(GLFWkeyfun cbfun); GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun); GLFWAPI void glfwSetMouseButtonCallback(GLFWmousebuttonfun cbfun); -GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun); +GLFWAPI void glfwSetCursorPosCallback(GLFWcursorposfun cbfun); GLFWAPI void glfwSetCursorEnterCallback(GLFWcursorenterfun cbfun); GLFWAPI void glfwSetScrollCallback(GLFWscrollfun cbfun); diff --git a/readme.html b/readme.html index 086f18f5..8982eaeb 100644 --- a/readme.html +++ b/readme.html @@ -299,6 +299,7 @@ version of GLFW.

  • 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
  • +
  • Renamed mouse position functions to cursor position equivalents
  • 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, floating point scrolling interface
  • diff --git a/src/cocoa_window.m b/src/cocoa_window.m index b5231ec9..2c7b8425 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -1152,12 +1152,12 @@ void _glfwPlatformWaitEvents( void ) //======================================================================== -// Set physical mouse cursor position +// Set physical cursor position //======================================================================== -void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y) +void _glfwPlatformSetCursorPos(_GLFWwindow* window, int x, int y) { - // The library seems to assume that after calling this the mouse won't move, + // The library seems to assume that after calling this the cursor won't move, // but obviously it will, and escape the app's window, and activate other apps, // and other badness in pain. I think the API's just silly, but maybe I'm // misunderstanding it... diff --git a/src/input.c b/src/input.c index 90ada563..37da571a 100644 --- a/src/input.c +++ b/src/input.c @@ -55,7 +55,7 @@ static void setCursorMode(_GLFWwindow* window, int newMode) centerPosY = window->height / 2; if (oldMode == GLFW_CURSOR_CAPTURED || newMode == GLFW_CURSOR_CAPTURED) - _glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY); + _glfwPlatformSetCursorPos(window, centerPosX, centerPosY); _glfwPlatformSetCursorMode(window, newMode); window->cursorMode = newMode; @@ -249,11 +249,11 @@ void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y) window->cursorPosY = y; } - if (_glfwLibrary.mousePosCallback) + if (_glfwLibrary.cursorPosCallback) { - _glfwLibrary.mousePosCallback(window, - window->cursorPosX, - window->cursorPosY); + _glfwLibrary.cursorPosCallback(window, + window->cursorPosX, + window->cursorPosY); } } @@ -412,7 +412,7 @@ GLFWAPI int glfwGetMouseButton(GLFWwindow handle, int button) // Returns the last reported cursor position for the specified window //======================================================================== -GLFWAPI void glfwGetMousePos(GLFWwindow handle, int* xpos, int* ypos) +GLFWAPI void glfwGetCursorPos(GLFWwindow handle, int* xpos, int* ypos) { _GLFWwindow* window = (_GLFWwindow*) handle; @@ -435,7 +435,7 @@ GLFWAPI void glfwGetMousePos(GLFWwindow handle, int* xpos, int* ypos) // the specified window //======================================================================== -GLFWAPI void glfwSetMousePos(GLFWwindow handle, int xpos, int ypos) +GLFWAPI void glfwSetCursorPos(GLFWwindow handle, int xpos, int ypos) { _GLFWwindow* window = (_GLFWwindow*) handle; @@ -451,11 +451,11 @@ GLFWAPI void glfwSetMousePos(GLFWwindow handle, int xpos, int ypos) return; } - // Don't do anything if the mouse position did not change + // Don't do anything if the cursor position did not change if (xpos == window->cursorPosX && ypos == window->cursorPosY) return; - // Set GLFW mouse position + // Set GLFW cursor position window->cursorPosX = xpos; window->cursorPosY = ypos; @@ -464,7 +464,7 @@ GLFWAPI void glfwSetMousePos(GLFWwindow handle, int xpos, int ypos) return; // Update physical cursor position - _glfwPlatformSetMouseCursorPos(window, xpos, ypos); + _glfwPlatformSetCursorPos(window, xpos, ypos); } @@ -542,7 +542,7 @@ GLFWAPI void glfwSetMouseButtonCallback(GLFWmousebuttonfun cbfun) // Set callback function for mouse moves //======================================================================== -GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun) +GLFWAPI void glfwSetCursorPosCallback(GLFWcursorposfun cbfun) { if (!_glfwInitialized) { @@ -550,10 +550,10 @@ GLFWAPI void glfwSetMousePosCallback(GLFWmouseposfun cbfun) return; } - _glfwLibrary.mousePosCallback = cbfun; + _glfwLibrary.cursorPosCallback = cbfun; // Call the callback function to let the application know the current - // mouse position + // cursor position if (cbfun) { _GLFWwindow* window; diff --git a/src/internal.h b/src/internal.h index ec2bab10..700b6c06 100644 --- a/src/internal.h +++ b/src/internal.h @@ -241,7 +241,7 @@ struct _GLFWlibrary GLFWwindowfocusfun windowFocusCallback; GLFWwindowiconifyfun windowIconifyCallback; GLFWmousebuttonfun mouseButtonCallback; - GLFWmouseposfun mousePosCallback; + GLFWcursorposfun cursorPosCallback; GLFWcursorenterfun cursorEnterCallback; GLFWscrollfun scrollCallback; GLFWkeyfun keyCallback; @@ -284,7 +284,7 @@ const char* _glfwPlatformGetVersionString(void); // Input void _glfwPlatformEnableSystemKeys(_GLFWwindow* window); void _glfwPlatformDisableSystemKeys(_GLFWwindow* window); -void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y); +void _glfwPlatformSetCursorPos(_GLFWwindow* window, int x, int y); void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode); // Fullscreen diff --git a/src/win32_platform.h b/src/win32_platform.h index e7b7b165..eeadbf22 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -165,7 +165,7 @@ typedef struct _GLFWwindowWin32 int desiredRefreshRate; // Desired vertical monitor refresh rate GLboolean cursorCentered; GLboolean cursorInside; - int oldMouseX, oldMouseY; + int oldCursorX, oldCursorY; } _GLFWwindowWin32; diff --git a/src/win32_window.c b/src/win32_window.c index 4990be45..935767ce 100755 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -449,7 +449,7 @@ static GLboolean createContext(_GLFWwindow* window, // Hide mouse cursor //======================================================================== -static void hideMouseCursor(_GLFWwindow* window) +static void hideCursor(_GLFWwindow* window) { } @@ -458,7 +458,7 @@ static void hideMouseCursor(_GLFWwindow* window) // Capture mouse cursor //======================================================================== -static void captureMouseCursor(_GLFWwindow* window) +static void captureCursor(_GLFWwindow* window) { RECT ClipWindowRect; @@ -477,7 +477,7 @@ static void captureMouseCursor(_GLFWwindow* window) // Show mouse cursor //======================================================================== -static void showMouseCursor(_GLFWwindow* window) +static void showCursor(_GLFWwindow* window) { // Un-capture cursor ReleaseCapture(); @@ -784,7 +784,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, // The window was deactivated (or iconified, see above) if (window->cursorMode == GLFW_CURSOR_CAPTURED) - showMouseCursor(window); + showCursor(window); if (window->mode == GLFW_FULLSCREEN) { @@ -807,7 +807,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, // The window was activated if (window->cursorMode == GLFW_CURSOR_CAPTURED) - captureMouseCursor(window); + captureCursor(window); if (window->mode == GLFW_FULLSCREEN) { @@ -962,14 +962,14 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, case WM_MOUSEMOVE: { - int newMouseX, newMouseY; + int newCursorX, newCursorY; - // Get signed (!) mouse position - newMouseX = (int)((short)LOWORD(lParam)); - newMouseY = (int)((short)HIWORD(lParam)); + // Get signed (!) cursor position + newCursorX = (int)((short)LOWORD(lParam)); + newCursorY = (int)((short)HIWORD(lParam)); - if (newMouseX != window->Win32.oldMouseX || - newMouseY != window->Win32.oldMouseY) + if (newCursorX != window->Win32.oldCursorX || + newCursorY != window->Win32.oldCursorY) { int x, y; @@ -978,17 +978,17 @@ 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 = newCursorX - window->Win32.oldCursorX; + y = newCursorY - window->Win32.oldCursorY; } else { - x = newMouseX; - y = newMouseY; + x = newCursorX; + y = newCursorY; } - window->Win32.oldMouseX = newMouseX; - window->Win32.oldMouseY = newMouseY; + window->Win32.oldCursorX = newCursorX; + window->Win32.oldCursorY = newCursorY; window->Win32.cursorCentered = GL_FALSE; _glfwInputCursorMotion(window, x, y); @@ -1372,11 +1372,11 @@ static int createWindow(_GLFWwindow* window, initWGLExtensions(window); - // Initialize mouse position data + // Initialize cursor position data GetCursorPos(&pos); ScreenToClient(window->Win32.handle, &pos); - window->Win32.oldMouseX = window->cursorPosX = pos.x; - window->Win32.oldMouseY = window->cursorPosY = pos.y; + window->Win32.oldCursorX = window->cursorPosX = pos.x; + window->Win32.oldCursorY = window->cursorPosY = pos.y; return GL_TRUE; } @@ -1782,13 +1782,13 @@ void _glfwPlatformPollEvents(void) if (window) { window->Win32.cursorCentered = GL_FALSE; - window->Win32.oldMouseX = window->width / 2; - window->Win32.oldMouseY = window->height / 2; + window->Win32.oldCursorX = window->width / 2; + window->Win32.oldCursorY = window->height / 2; } else { - //window->Win32.oldMouseX = window->cursorPosX; - //window->Win32.oldMouseY = window->cursorPosY; + //window->Win32.oldCursorX = window->cursorPosX; + //window->Win32.oldCursorY = window->cursorPosY; } while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) @@ -1845,9 +1845,9 @@ void _glfwPlatformPollEvents(void) if (window->cursorMode == GLFW_CURSOR_CAPTURED && !window->Win32.cursorCentered) { - _glfwPlatformSetMouseCursorPos(window, - window->width / 2, - window->height / 2); + _glfwPlatformSetCursorPos(window, + window->width / 2, + window->height / 2); window->Win32.cursorCentered = GL_TRUE; } } @@ -1867,10 +1867,10 @@ void _glfwPlatformWaitEvents(void) //======================================================================== -// Set physical mouse cursor position +// Set physical cursor position //======================================================================== -void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y) +void _glfwPlatformSetCursorPos(_GLFWwindow* window, int x, int y) { POINT pos; @@ -1892,13 +1892,13 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode) switch (mode) { case GLFW_CURSOR_NORMAL: - showMouseCursor(window); + showCursor(window); break; case GLFW_CURSOR_HIDDEN: - hideMouseCursor(window); + hideCursor(window); break; case GLFW_CURSOR_CAPTURED: - captureMouseCursor(window); + captureCursor(window); break; } } diff --git a/src/x11_window.c b/src/x11_window.c index 9ec54493..84b6f7d6 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -251,10 +251,10 @@ static GLboolean createWindow(_GLFWwindow* window, //======================================================================== -// Hide mouse cursor +// Hide cursor //======================================================================== -static void hideMouseCursor(_GLFWwindow* window) +static void hideCursor(_GLFWwindow* window) { if (!window->X11.cursorHidden) { @@ -267,12 +267,12 @@ static void hideMouseCursor(_GLFWwindow* window) //======================================================================== -// Capture mouse cursor +// Capture cursor //======================================================================== -static void captureMouseCursor(_GLFWwindow* window) +static void captureCursor(_GLFWwindow* window) { - hideMouseCursor(window); + hideCursor(window); if (!window->X11.cursorGrabbed) { @@ -290,13 +290,13 @@ static void captureMouseCursor(_GLFWwindow* window) //======================================================================== -// Show mouse cursor +// Show cursor //======================================================================== -static void showMouseCursor(_GLFWwindow* window) +static void showCursor(_GLFWwindow* window) { // Un-grab cursor (only in windowed mode: in fullscreen mode we still - // want the mouse grabbed in order to confine the cursor to the window + // want the cursor grabbed in order to confine the cursor to the window // area) if (window->X11.cursorGrabbed) { @@ -401,7 +401,7 @@ static void enterFullscreenMode(_GLFWwindow* window) } // HACK: Try to get window inside viewport (for virtual displays) by moving - // the mouse cursor to the upper left corner (and then to the center) + // the cursor to the upper left corner (and then to the center) // This hack should be harmless on saner systems as well XWarpPointer(_glfwLibrary.X11.display, None, window->X11.handle, 0,0,0,0, 0,0); XWarpPointer(_glfwLibrary.X11.display, None, window->X11.handle, 0,0,0,0, @@ -615,7 +615,7 @@ static void processSingleEvent(void) case EnterNotify: { - // The mouse cursor enters the Window + // The cursor entered the window window = findWindow(event.xcrossing.window); if (window == NULL) { @@ -624,7 +624,7 @@ static void processSingleEvent(void) } if (window->cursorMode == GLFW_CURSOR_HIDDEN) - hideMouseCursor(window); + hideCursor(window); _glfwInputCursorEnter(window, GL_TRUE); break; @@ -632,7 +632,7 @@ static void processSingleEvent(void) case LeaveNotify: { - // The mouse cursor leave the Window + // The cursor left the window window = findWindow(event.xcrossing.window); if (window == NULL) { @@ -641,7 +641,7 @@ static void processSingleEvent(void) } if (window->cursorMode == GLFW_CURSOR_HIDDEN) - showMouseCursor(window); + showCursor(window); _glfwInputCursorEnter(window, GL_FALSE); break; @@ -649,7 +649,7 @@ static void processSingleEvent(void) case MotionNotify: { - // The mouse cursor was moved + // The cursor was moved window = findWindow(event.xmotion.window); if (window == NULL) { @@ -660,7 +660,7 @@ static void processSingleEvent(void) if (event.xmotion.x != window->X11.cursorPosX || event.xmotion.y != window->X11.cursorPosY) { - // The mouse cursor was moved and we didn't do it + // The cursor was moved and we didn't do it int x, y; if (window->cursorMode == GLFW_CURSOR_CAPTURED) @@ -783,7 +783,7 @@ static void processSingleEvent(void) _glfwInputWindowFocus(window, GL_TRUE); if (window->cursorMode == GLFW_CURSOR_CAPTURED) - captureMouseCursor(window); + captureCursor(window); break; } @@ -801,7 +801,7 @@ static void processSingleEvent(void) _glfwInputWindowFocus(window, GL_FALSE); if (window->cursorMode == GLFW_CURSOR_CAPTURED) - showMouseCursor(window); + showCursor(window); break; } @@ -1197,9 +1197,9 @@ void _glfwPlatformPollEvents(void) if (window->cursorMode == GLFW_CURSOR_CAPTURED && !window->X11.cursorCentered) { - _glfwPlatformSetMouseCursorPos(window, - window->width / 2, - window->height / 2); + _glfwPlatformSetCursorPos(window, + window->width / 2, + window->height / 2); window->X11.cursorCentered = GL_TRUE; // NOTE: This is a temporary fix. It works as long as you use @@ -1228,10 +1228,10 @@ void _glfwPlatformWaitEvents(void) //======================================================================== -// Set physical mouse cursor position +// Set physical cursor position //======================================================================== -void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y) +void _glfwPlatformSetCursorPos(_GLFWwindow* window, int x, int y) { // Store the new position so we can recognise it later window->X11.cursorPosX = x; @@ -1242,7 +1242,7 @@ void _glfwPlatformSetMouseCursorPos(_GLFWwindow* window, int x, int y) //======================================================================== -// Set physical mouse cursor mode +// Set physical cursor mode //======================================================================== void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode) @@ -1250,13 +1250,13 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode) switch (mode) { case GLFW_CURSOR_NORMAL: - showMouseCursor(window); + showCursor(window); break; case GLFW_CURSOR_HIDDEN: - hideMouseCursor(window); + hideCursor(window); break; case GLFW_CURSOR_CAPTURED: - captureMouseCursor(window); + captureCursor(window); break; } } diff --git a/tests/accuracy.c b/tests/accuracy.c index ae572987..cfb70271 100644 --- a/tests/accuracy.c +++ b/tests/accuracy.c @@ -50,7 +50,7 @@ static void window_size_callback(GLFWwindow window, int width, int height) gluOrtho2D(0.f, window_width, 0.f, window_height); } -static void mouse_position_callback(GLFWwindow window, int x, int y) +static void cursor_position_callback(GLFWwindow window, int x, int y) { cursor_x = x; cursor_y = y; @@ -75,7 +75,7 @@ int main(void) exit(EXIT_FAILURE); } - glfwSetMousePosCallback(mouse_position_callback); + glfwSetCursorPosCallback(cursor_position_callback); glfwSetWindowSizeCallback(window_size_callback); glfwSwapInterval(1); diff --git a/tests/events.c b/tests/events.c index cc79da62..8ab54266 100644 --- a/tests/events.c +++ b/tests/events.c @@ -270,9 +270,9 @@ static void mouse_button_callback(GLFWwindow window, int button, int action) printf(" was %s\n", get_action_name(action)); } -static void mouse_position_callback(GLFWwindow window, int x, int y) +static void cursor_position_callback(GLFWwindow window, int x, int y) { - printf("%08x at %0.3f: Mouse position: %i %i\n", counter++, glfwGetTime(), x, y); + printf("%08x at %0.3f: Cursor position: %i %i\n", counter++, glfwGetTime(), x, y); } static void cursor_enter_callback(GLFWwindow window, int entered) @@ -361,7 +361,7 @@ int main(void) glfwSetWindowFocusCallback(window_focus_callback); glfwSetWindowIconifyCallback(window_iconify_callback); glfwSetMouseButtonCallback(mouse_button_callback); - glfwSetMousePosCallback(mouse_position_callback); + glfwSetCursorPosCallback(cursor_position_callback); glfwSetCursorEnterCallback(cursor_enter_callback); glfwSetScrollCallback(scroll_callback); glfwSetKeyCallback(key_callback); diff --git a/tests/peter.c b/tests/peter.c index 5ae7ba5d..b9f21f22 100644 --- a/tests/peter.c +++ b/tests/peter.c @@ -1,5 +1,5 @@ //======================================================================== -// Mouse cursor bug test +// Cursor input bug test // Copyright (c) Camilla Berglund // // This software is provided 'as-is', without any express or implied @@ -41,7 +41,7 @@ static int cursor_y; static GLboolean open_window(void); -static void toggle_mouse_cursor(GLFWwindow window) +static void toggle_cursor(GLFWwindow window) { if (glfwGetInputMode(window, GLFW_CURSOR_MODE) == GLFW_CURSOR_CAPTURED) { @@ -55,9 +55,9 @@ static void toggle_mouse_cursor(GLFWwindow window) } } -static void mouse_position_callback(GLFWwindow window, int x, int y) +static void cursor_position_callback(GLFWwindow window, int x, int y) { - printf("Mouse moved to: %i %i (%i %i)\n", x, y, x - cursor_x, y - cursor_y); + printf("Cursor moved to: %i %i (%i %i)\n", x, y, x - cursor_x, y - cursor_y); cursor_x = x; cursor_y = y; } @@ -69,7 +69,7 @@ static void key_callback(GLFWwindow window, int key, int action) case GLFW_KEY_SPACE: { if (action == GLFW_PRESS) - toggle_mouse_cursor(window); + toggle_cursor(window); break; } @@ -98,11 +98,11 @@ static GLboolean open_window(void) if (!window_handle) return GL_FALSE; - glfwGetMousePos(window_handle, &cursor_x, &cursor_y); - printf("Mouse position: %i %i\n", cursor_x, cursor_y); + glfwGetCursorPos(window_handle, &cursor_x, &cursor_y); + printf("Cursor position: %i %i\n", cursor_x, cursor_y); glfwSetWindowSizeCallback(window_size_callback); - glfwSetMousePosCallback(mouse_position_callback); + glfwSetCursorPosCallback(cursor_position_callback); glfwSetKeyCallback(key_callback); glfwSwapInterval(1); From ee66e5fa10a36063320f76bb7be20779c0f2fc32 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 2 Jul 2012 00:36:20 +0200 Subject: [PATCH 224/226] Merged fix for bug #3528964. --- readme.html | 2 +- src/cocoa_window.m | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/readme.html b/readme.html index 8982eaeb..97a314dd 100644 --- a/readme.html +++ b/readme.html @@ -917,7 +917,7 @@ their skills. Special thanks go out to:

  • Steve Sexton, for reporting an input bug in the Carbon port
  • -
  • Dmitri Shuralyov, for support, bug reports and testing
  • +
  • Dmitri Shuralyov, for support, bug reports, bug fixes and testing
  • Daniel Skorupski, for reporting a bug in the Win32 DEF file
  • diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 2c7b8425..781bfd32 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -357,12 +357,13 @@ static int convertMacKeyCode(unsigned int macKeyCode) _glfwInputCursorMotion(window, [event deltaX], [event deltaY]); else { - NSPoint p = [event locationInWindow]; + const NSPoint p = [event locationInWindow]; // Cocoa coordinate system has origin at lower left - p.y = [[window->NS.object contentView] bounds].size.height - p.y; + const int x = lround(floor(p.x)); + const int y = window->height - lround(ceil(p.y)); - _glfwInputCursorMotion(window, p.x, p.y); + _glfwInputCursorMotion(window, x, y); } } @@ -1168,7 +1169,7 @@ void _glfwPlatformSetCursorPos(_GLFWwindow* window, int x, int y) // calculating the maximum y coordinate of all screens, since Cocoa's // "global coordinates" are upside down from CG's... - NSPoint localPoint = NSMakePoint(x, window->height - y); + NSPoint localPoint = NSMakePoint(x, window->height - y - 1); NSPoint globalPoint = [window->NS.object convertBaseToScreen:localPoint]; CGPoint mainScreenOrigin = CGDisplayBounds(CGMainDisplayID()).origin; double mainScreenHeight = CGDisplayBounds(CGMainDisplayID()).size.height; From e7c4e772141804fd45d922430be5b4f1b32695e9 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 2 Jul 2012 15:23:36 +0200 Subject: [PATCH 225/226] Fixed cursor positioning in fullscreen on Cocoa. --- readme.html | 2 ++ src/cocoa_window.m | 35 ++++++++++++++++------------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/readme.html b/readme.html index 97a314dd..63334b67 100644 --- a/readme.html +++ b/readme.html @@ -332,6 +332,8 @@ version of GLFW.

  • [Cocoa] Bugfix: The OpenGL framework was not retrieved, making glfwGetProcAddress crash
  • [Cocoa] Bugfix: glfwInit changed the current directory for unbundled executables
  • [Cocoa] Bugfix: The GLFW_WINDOW_NO_RESIZE window parameter was always zero
  • +
  • [Cocoa] Bugfix: The cursor position incorrectly rounded during conversion
  • +
  • [Cocoa] Bugfix: Cursor positioning led to nonsensical results for fullscreen windows
  • [X11] Added support for the GLX_EXT_swap_control extension as an alternative to GLX_SGI_swap_control
  • [X11] Added the POSIX CLOCK_MONOTONIC time source as the preferred method
  • [X11] Added dependency on libm, where present
  • diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 781bfd32..233075a9 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -1158,25 +1158,22 @@ void _glfwPlatformWaitEvents( void ) void _glfwPlatformSetCursorPos(_GLFWwindow* window, int x, int y) { - // The library seems to assume that after calling this the cursor won't move, - // but obviously it will, and escape the app's window, and activate other apps, - // and other badness in pain. I think the API's just silly, but maybe I'm - // misunderstanding it... - - // Also, (x, y) are window coords... - - // Also, it doesn't seem possible to write this robustly without - // calculating the maximum y coordinate of all screens, since Cocoa's - // "global coordinates" are upside down from CG's... - - NSPoint localPoint = NSMakePoint(x, window->height - y - 1); - NSPoint globalPoint = [window->NS.object convertBaseToScreen:localPoint]; - CGPoint mainScreenOrigin = CGDisplayBounds(CGMainDisplayID()).origin; - double mainScreenHeight = CGDisplayBounds(CGMainDisplayID()).size.height; - CGPoint targetPoint = CGPointMake(globalPoint.x - mainScreenOrigin.x, - mainScreenHeight - globalPoint.y - - mainScreenOrigin.y); - CGDisplayMoveCursorToPoint(CGMainDisplayID(), targetPoint); + if (window->mode == GLFW_FULLSCREEN) + { + NSPoint globalPoint = NSMakePoint(x, y); + CGDisplayMoveCursorToPoint(CGMainDisplayID(), globalPoint); + } + else + { + NSPoint localPoint = NSMakePoint(x, window->height - y - 1); + NSPoint globalPoint = [window->NS.object convertBaseToScreen:localPoint]; + CGPoint mainScreenOrigin = CGDisplayBounds(CGMainDisplayID()).origin; + double mainScreenHeight = CGDisplayBounds(CGMainDisplayID()).size.height; + CGPoint targetPoint = CGPointMake(globalPoint.x - mainScreenOrigin.x, + mainScreenHeight - globalPoint.y - + mainScreenOrigin.y); + CGDisplayMoveCursorToPoint(CGMainDisplayID(), targetPoint); + } } From 34c93a5124b29671d9729e7102f6215535abf8f8 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 2 Jul 2012 15:24:02 +0200 Subject: [PATCH 226/226] Disabled window restoration on Cocoa. --- readme.html | 4 ++++ src/cocoa_window.m | 3 +++ 2 files changed, 7 insertions(+) diff --git a/readme.html b/readme.html index 63334b67..faf6a52e 100644 --- a/readme.html +++ b/readme.html @@ -334,6 +334,7 @@ version of GLFW.

  • [Cocoa] Bugfix: The GLFW_WINDOW_NO_RESIZE window parameter was always zero
  • [Cocoa] Bugfix: The cursor position incorrectly rounded during conversion
  • [Cocoa] Bugfix: Cursor positioning led to nonsensical results for fullscreen windows
  • +
  • [Cocoa] Bugfix: The GLFW window was flagged as restorable
  • [X11] Added support for the GLX_EXT_swap_control extension as an alternative to GLX_SGI_swap_control
  • [X11] Added the POSIX CLOCK_MONOTONIC time source as the preferred method
  • [X11] Added dependency on libm, where present
  • @@ -895,6 +896,9 @@ their skills. Special thanks go out to:

  • Glenn Lewis, for helping out with support for the D programming language
  • +
  • Shane Liesegang, for providing a bug fix relating to Cocoa window + restoration
  • +
  • Tristam MacDonald, for his bug reports and feedback on the Cocoa port
  • Hans 'Hanmac' Mackowiak, for the initial implementation of cursor diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 233075a9..3523806a 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -693,6 +693,9 @@ static GLboolean createWindow(_GLFWwindow* window, [window->NS.object setAcceptsMouseMovedEvents:YES]; [window->NS.object center]; + if ([window->NS.object respondsToSelector:@selector(setRestorable)]) + [window->NS.object setRestorable:NO]; + return GL_TRUE; }