From 1a3d47d06daa2004a4df629fdcf7676ca1a4e27a Mon Sep 17 00:00:00 2001
From: Camilla Berglund
Date: Fri, 30 Nov 2012 13:56:42 +0100
Subject: [PATCH 1/4] Added window position callback.
---
include/GL/glfw3.h | 18 ++++++++++++++++++
readme.html | 3 ++-
src/internal.h | 1 +
src/window.c | 24 ++++++++++++++++++++++++
tests/events.c | 10 ++++++++++
5 files changed, 55 insertions(+), 1 deletion(-)
diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h
index 8759ea79..e9cea004 100644
--- a/include/GL/glfw3.h
+++ b/include/GL/glfw3.h
@@ -706,6 +706,16 @@ typedef void* GLFWwindow;
*/
typedef void (* GLFWerrorfun)(int,const char*);
+/*! @brief The function signature for window position callbacks.
+ * @param[in] window The window that the user moved.
+ * @param[in] x The new x-coordinate, in pixels, of the upper-left corner of
+ * the client area of the window.
+ * @param[in] y The new y-coordinate, in pixels, of the upper-left corner of
+ * the client area of the window.
+ * @ingroup window
+ */
+typedef void (* GLFWwindowposfun)(GLFWwindow,int,int);
+
/*! @brief The function signature for window resize callbacks.
* @param[in] window The window that the user resized.
* @param[in] width The new width, in pixels, of the window.
@@ -1274,6 +1284,14 @@ GLFWAPI void glfwSetWindowUserPointer(GLFWwindow window, void* pointer);
*/
GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow window);
+/*! @brief Sets the position callback for the specified window.
+ * @param[in] window The window whose callback to set.
+ * @param[in] cbfun The new callback, or @c NULL to remove the currently set
+ * callback.
+ * @ingroup window
+ */
+GLFWAPI void glfwSetWindowPosCallback(GLFWwindow window, GLFWwindowposfun cbfun);
+
/*! @brief Sets the size callback for the specified window.
* @param[in] window The window whose callback to set.
* @param[in] cbfun The new callback, or @c NULL to remove the currently set
diff --git a/readme.html b/readme.html
index 81100df6..1e629456 100644
--- a/readme.html
+++ b/readme.html
@@ -274,7 +274,7 @@ version of GLFW.
Added glfwSetErrorCallback
function and GLFWerrorfun
type for receiving more specific and/or nested errors
Added glfwSetWindowUserPointer
and glfwGetWindowUserPointer
functions for per-window user pointers
Added glfwGetVersionString
function for determining which code paths were enabled at compile time
- Added glfwGetWindowPos
function for querying the position of the specified window
+ Added glfwSetWindowPosCallback
function and GLFWwindowposfun
type for reciving window position events
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
@@ -284,6 +284,7 @@ version of GLFW.
Added GLFW_OPENGL_REVISION
window parameter to make up for removal of glfwGetGLVersion
Added GLFW_INCLUDE_GLCOREARB
macro for including glcorearb.h
instead of gl.h
Added GLFW_VISIBLE
window hint and parameter for controlling and polling window visibility
+ Added GLFW_POSITION_X
and GLFW_POSITION_Y
window hints and parameter for controlling and polling window position
Added windows
simple multi-window test program
Added sharing
simple OpenGL object sharing test program
Added modes
video mode enumeration and setting test program
diff --git a/src/internal.h b/src/internal.h
index c5a40af3..2ef8f10c 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -199,6 +199,7 @@ struct _GLFWwindow
int glRobustness;
PFNGLGETSTRINGIPROC GetStringi;
+ GLFWwindowposfun windowPosCallback;
GLFWwindowsizefun windowSizeCallback;
GLFWwindowclosefun windowCloseCallback;
GLFWwindowrefreshfun windowRefreshCallback;
diff --git a/src/window.c b/src/window.c
index 908a2a7c..ac0fd02f 100644
--- a/src/window.c
+++ b/src/window.c
@@ -119,8 +119,14 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean focused)
void _glfwInputWindowPos(_GLFWwindow* window, int x, int y)
{
+ if (window->positionX == x && window->positionY == y)
+ return;
+
window->positionX = x;
window->positionY = y;
+
+ if (window->windowPosCallback)
+ window->windowPosCallback(window, x, y);
}
@@ -764,6 +770,24 @@ GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow handle)
}
+//========================================================================
+// Set callback function for window position changes
+//========================================================================
+
+GLFWAPI void glfwSetWindowPosCallback(GLFWwindow handle, GLFWwindowposfun cbfun)
+{
+ _GLFWwindow* window = (_GLFWwindow*) handle;
+
+ if (!_glfwInitialized)
+ {
+ _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
+ return;
+ }
+
+ window->windowPosCallback = cbfun;
+}
+
+
//========================================================================
// Set callback function for window size changes
//========================================================================
diff --git a/tests/events.c b/tests/events.c
index 3150a82e..46bde2ab 100644
--- a/tests/events.c
+++ b/tests/events.c
@@ -218,6 +218,15 @@ static const char* get_character_string(int character)
return result;
}
+static void window_pos_callback(GLFWwindow window, int x, int y)
+{
+ printf("%08x at %0.3f: Window position: %i %i\n",
+ counter++,
+ glfwGetTime(),
+ x,
+ y);
+}
+
static void window_size_callback(GLFWwindow window, int width, int height)
{
printf("%08x at %0.3f: Window size: %i %i\n",
@@ -354,6 +363,7 @@ int main(void)
printf("Window opened\n");
+ glfwSetWindowPosCallback(window, window_pos_callback);
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSetWindowCloseCallback(window, window_close_callback);
glfwSetWindowRefreshCallback(window, window_refresh_callback);
From a3ff29af36753272406e852f82dbe45df5c5584c Mon Sep 17 00:00:00 2001
From: Camilla Berglund
Date: Sun, 2 Dec 2012 15:47:10 +0100
Subject: [PATCH 2/4] Documentation updates.
---
include/GL/glfw3.h | 43 +++++++++++++++++++++++++++++++++++++------
1 file changed, 37 insertions(+), 6 deletions(-)
diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h
index e9cea004..b5735a96 100644
--- a/include/GL/glfw3.h
+++ b/include/GL/glfw3.h
@@ -954,7 +954,7 @@ GLFWAPI void glfwGetDesktopMode(GLFWvidmode* mode);
/*! @brief Sets the system gamma ramp to one generated from the specified
* exponent.
- * @param[in] The desired exponent.
+ * @param[in] gamma The desired exponent.
* @ingroup gamma
*/
GLFWAPI void glfwSetGamma(float gamma);
@@ -1048,7 +1048,8 @@ GLFWAPI void glfwDefaultWindowHints(void);
* used by the OpenGL context.
*
* The @ref GLFW_RESIZABLE hint specifies whether the window will be resizable
- * by the user. This hint is ignored for fullscreen windows.
+ * by the user. The window will still be resizable using the @ref
+ * glfwSetWindowSize function. This hint is ignored for fullscreen windows.
*
* The @ref GLFW_VISIBLE hint specifies whether the window will be initially
* visible. This hint is ignored for fullscreen windows.
@@ -1059,7 +1060,9 @@ GLFWAPI void glfwDefaultWindowHints(void);
* Some window hints are hard constraints. These must match the available
* capabilities @em exactly for window and context creation to succeed. Hints
* that are not hard constraints are matched as closely as possible, but the
- * resulting window and context may differ from what these hints requested.
+ * resulting window and context may differ from what these hints requested. To
+ * find out the actual properties of the created window and context, use the
+ * @ref glfwGetWindowParam function.
*
* The following window hints are hard constraints:
* @arg @ref GLFW_STEREO
@@ -1297,6 +1300,8 @@ GLFWAPI void glfwSetWindowPosCallback(GLFWwindow window, GLFWwindowposfun cbfun)
* @param[in] cbfun The new callback, or @c NULL to remove the currently set
* callback.
* @ingroup window
+ *
+ * This callback is called when the window is resized.
*/
GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow window, GLFWwindowsizefun cbfun);
@@ -1305,6 +1310,14 @@ GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow window, GLFWwindowsizefun cbfu
* @param[in] cbfun The new callback, or @c NULL to remove the currently set
* callback.
* @ingroup window
+ *
+ * This callback is called when the user attempts to close the window, i.e.
+ * clicks the window's close widget or, on Mac OS X, selects @b Quit from the
+ * application menu. Calling @ref glfwDestroyWindow does not cause this
+ * callback to be called.
+ *
+ * The return value of the close callback becomes the new value of the @ref
+ * GLFW_CLOSE_REQUESTED window parameter.
*/
GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow window, GLFWwindowclosefun cbfun);
@@ -1313,6 +1326,13 @@ GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow window, GLFWwindowclosefun cb
* @param[in] cbfun The new callback, or @c NULL to remove the currently set
* callback.
* @ingroup window
+ *
+ * This callback is called when the client area of the window needs to be
+ * redrawn, for example if the window has been exposed after having been
+ * covered by another window.
+ *
+ * @note On compositing window systems such as Mac OS X, where the window
+ * contents are saved off-screen, this callback may never be called.
*/
GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow window, GLFWwindowrefreshfun cbfun);
@@ -1321,6 +1341,8 @@ GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow window, GLFWwindowrefreshfu
* @param[in] cbfun The new callback, or @c NULL to remove the currently set
* callback.
* @ingroup window
+ *
+ * This callback is called when the window gains or loses focus.
*/
GLFWAPI void glfwSetWindowFocusCallback(GLFWwindow window, GLFWwindowfocusfun cbfun);
@@ -1329,6 +1351,8 @@ GLFWAPI void glfwSetWindowFocusCallback(GLFWwindow window, GLFWwindowfocusfun cb
* @param[in] cbfun The new callback, or @c NULL to remove the currently set
* callback.
* @ingroup window
+ *
+ * This callback is called when the window is iconified or restored.
*/
GLFWAPI void glfwSetWindowIconifyCallback(GLFWwindow window, GLFWwindowiconifyfun cbfun);
@@ -1427,7 +1451,7 @@ GLFWAPI void glfwGetScrollOffset(GLFWwindow window, double* xoffset, double* yof
* set callback.
* @ingroup input
*
- * @note The key callback deals with physical keys, with @link keys tokens
+ * @remarks The key callback deals with physical keys, with @link keys tokens
* @endlink named after their use on the standard US keyboard layout. If you
* want to input text, use the Unicode character callback instead.
*/
@@ -1438,8 +1462,8 @@ GLFWAPI void glfwSetKeyCallback(GLFWwindow window, GLFWkeyfun cbfun);
* the currently set callback.
* @ingroup input
*
- * @note The Unicode character callback is for text input. If you want to know
- * whether a specific key was pressed or released, use the key callback.
+ * @remarks The Unicode character callback is for text input. If you want to
+ * know whether a specific key was pressed or released, use the key callback.
*/
GLFWAPI void glfwSetCharCallback(GLFWwindow window, GLFWcharfun cbfun);
@@ -1454,6 +1478,9 @@ GLFWAPI void glfwSetMouseButtonCallback(GLFWwindow window, GLFWmousebuttonfun cb
* @param[in] cbfun The new cursor position callback, or @c NULL to remove the
* currently set callback.
* @ingroup input
+ *
+ * @remarks The position is relative to the upper-left corner of the client
+ * area of the window.
*/
GLFWAPI void glfwSetCursorPosCallback(GLFWwindow window, GLFWcursorposfun cbfun);
@@ -1506,6 +1533,8 @@ GLFWAPI int glfwGetJoystickButtons(int joy, unsigned char* buttons, int numbutto
* @param[in] string A UTF-8 encoded string.
* @ingroup clipboard
*
+ * @note This function may only be called from the main thread.
+ *
* @sa glfwGetClipboardString
*/
GLFWAPI void glfwSetClipboardString(GLFWwindow window, const char* string);
@@ -1516,6 +1545,8 @@ GLFWAPI void glfwSetClipboardString(GLFWwindow window, const char* string);
* if that format was unavailable.
* @ingroup clipboard
*
+ * @note This function may only be called from the main thread.
+ *
* @note The returned string is valid only until the next call to @ref
* glfwGetClipboardString or @ref glfwSetClipboardString.
*
From 69a900592e0ce28278ee3c8224838b7e499af698 Mon Sep 17 00:00:00 2001
From: Camilla Berglund
Date: Sun, 2 Dec 2012 16:10:00 +0100
Subject: [PATCH 3/4] Added explicit support for sRGB framebuffers.
---
include/GL/glfw3.h | 7 +++++++
src/cocoa_window.m | 3 +++
src/internal.h | 2 ++
src/opengl.c | 6 ++++++
src/win32_opengl.c | 12 ++++++++++++
src/win32_platform.h | 1 +
src/window.c | 4 ++++
src/x11_opengl.c | 8 ++++++++
src/x11_platform.h | 1 +
9 files changed, 44 insertions(+)
diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h
index b5735a96..1954a0c1 100644
--- a/include/GL/glfw3.h
+++ b/include/GL/glfw3.h
@@ -518,6 +518,10 @@ extern "C" {
/*! @brief The number of samples used for default framebuffer multisampling.
*/
#define GLFW_FSAA_SAMPLES 0x0002100E
+/*! @brief @c GL_TRUE if the framebuffer should be sRGB capable, or @c GL_FALSE
+ * otherwise.
+ */
+#define GLFW_SRGB_CAPABLE 0x0002100F
/*! @brief The @link clients client API @endlink to create a context for.
*/
@@ -1020,6 +1024,9 @@ GLFWAPI void glfwDefaultWindowHints(void);
* The @ref GLFW_FSAA_SAMPLES hint specifies the desired number of samples to
* use for multisampling.
*
+ * The @ref GLFW_SRGB_CAPABLE hint specifies whether the framebuffer should be
+ * sRGB capable.
+ *
* The @ref GLFW_CLIENT_API hint specifies which client API to create the
* context for. Possible values are @ref GLFW_OPENGL_API and @ref
* GLFW_OPENGL_ES_API.
diff --git a/src/cocoa_window.m b/src/cocoa_window.m
index 24ba6628..040277a7 100644
--- a/src/cocoa_window.m
+++ b/src/cocoa_window.m
@@ -835,6 +835,9 @@ static GLboolean createContext(_GLFWwindow* window,
ADD_ATTR2(NSOpenGLPFASamples, fbconfig->samples);
}
+ // NOTE: All NSOpenGLPixelFormats on the relevant cards support sRGB
+ // frambuffer, so there's no need (and no way) to request it
+
ADD_ATTR(0);
#undef ADD_ATTR
diff --git a/src/internal.h b/src/internal.h
index 2ef8f10c..d3084ee9 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -100,6 +100,7 @@ struct _GLFWhints
GLboolean resizable;
GLboolean visible;
int samples;
+ GLboolean sRGB;
int clientAPI;
int glMajor;
int glMinor;
@@ -160,6 +161,7 @@ struct _GLFWfbconfig
int auxBuffers;
GLboolean stereo;
int samples;
+ GLboolean sRGB;
GLFWintptr platformID;
};
diff --git a/src/opengl.c b/src/opengl.c
index 538bcdfb..931296ce 100644
--- a/src/opengl.c
+++ b/src/opengl.c
@@ -217,6 +217,12 @@ const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired,
extraDiff += (desired->samples - current->samples) *
(desired->samples - current->samples);
}
+
+ if (desired->sRGB)
+ {
+ if (!current->sRGB)
+ extraDiff++;
+ }
}
// Figure out if the current one is better than the best one found so far
diff --git a/src/win32_opengl.c b/src/win32_opengl.c
index f1e911f3..80d7470e 100644
--- a/src/win32_opengl.c
+++ b/src/win32_opengl.c
@@ -72,6 +72,7 @@ static void initWGLExtensions(_GLFWwindow* window)
// This needs to include every extension used below except for
// WGL_ARB_extensions_string and WGL_EXT_extensions_string
window->WGL.ARB_multisample = GL_FALSE;
+ window->WGL.ARB_framebuffer_sRGB = GL_FALSE;
window->WGL.ARB_create_context = GL_FALSE;
window->WGL.ARB_create_context_profile = GL_FALSE;
window->WGL.EXT_create_context_es2_profile = GL_FALSE;
@@ -92,6 +93,9 @@ static void initWGLExtensions(_GLFWwindow* window)
if (_glfwPlatformExtensionSupported("WGL_ARB_multisample"))
window->WGL.ARB_multisample = GL_TRUE;
+ if (_glfwPlatformExtensionSupported("WGL_ARB_framebuffer_sRGB"))
+ window->WGL.ARB_framebuffer_sRGB = GL_TRUE;
+
if (_glfwPlatformExtensionSupported("WGL_ARB_create_context"))
{
window->WGL.CreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)
@@ -246,6 +250,11 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
f->samples = getPixelFormatAttrib(window, i, WGL_SAMPLES_ARB);
else
f->samples = 0;
+
+ if (window->WGL.ARB_framebuffer_sRGB)
+ f->sRGB = getPixelFormatAttrib(window, i, WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB);
+ else
+ f->sRGB = GL_FALSE;
}
else
{
@@ -293,6 +302,9 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
// PFD pixel formats do not support FSAA
f->samples = 0;
+
+ // PFD pixel formats do not support sRGB
+ f->sRGB = GL_FALSE;
}
f->platformID = i;
diff --git a/src/win32_platform.h b/src/win32_platform.h
index 217fc2cf..ccabf595 100644
--- a/src/win32_platform.h
+++ b/src/win32_platform.h
@@ -144,6 +144,7 @@ typedef struct _GLFWcontextWGL
GLboolean EXT_swap_control;
GLboolean ARB_multisample;
GLboolean ARB_pixel_format;
+ GLboolean ARB_framebuffer_sRGB;
GLboolean ARB_create_context;
GLboolean ARB_create_context_profile;
GLboolean EXT_create_context_es2_profile;
diff --git a/src/window.c b/src/window.c
index ac0fd02f..d4026465 100644
--- a/src/window.c
+++ b/src/window.c
@@ -237,6 +237,7 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
fbconfig.auxBuffers = Max(_glfwLibrary.hints.auxBuffers, 0);
fbconfig.stereo = _glfwLibrary.hints.stereo ? GL_TRUE : GL_FALSE;
fbconfig.samples = Max(_glfwLibrary.hints.samples, 0);
+ fbconfig.sRGB = _glfwLibrary.hints.sRGB ? GL_TRUE : GL_FALSE;
// Set up desired window config
wndconfig.mode = mode;
@@ -446,6 +447,9 @@ GLFWAPI void glfwWindowHint(int target, int hint)
case GLFW_FSAA_SAMPLES:
_glfwLibrary.hints.samples = hint;
break;
+ case GLFW_SRGB_CAPABLE:
+ _glfwLibrary.hints.sRGB = hint;
+ break;
case GLFW_CLIENT_API:
_glfwLibrary.hints.clientAPI = hint;
break;
diff --git a/src/x11_opengl.c b/src/x11_opengl.c
index ad77805a..845a1980 100644
--- a/src/x11_opengl.c
+++ b/src/x11_opengl.c
@@ -190,6 +190,11 @@ static _GLFWfbconfig* getFBConfigs(_GLFWwindow* window, unsigned int* found)
else
f->samples = 0;
+ if (_glfwLibrary.GLX.ARB_framebuffer_sRGB)
+ f->sRGB = getFBConfigAttrib(window, fbconfigs[i], GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB);
+ else
+ f->sRGB = GL_FALSE;
+
f->platformID = (GLFWintptr) getFBConfigAttrib(window, fbconfigs[i], GLX_FBCONFIG_ID);
(*found)++;
@@ -527,6 +532,9 @@ int _glfwInitOpenGL(void)
if (_glfwPlatformExtensionSupported("GLX_ARB_multisample"))
_glfwLibrary.GLX.ARB_multisample = GL_TRUE;
+ if (_glfwPlatformExtensionSupported("GLX_ARB_framebuffer_sRGB"))
+ _glfwLibrary.GLX.ARB_framebuffer_sRGB = GL_TRUE;
+
if (_glfwPlatformExtensionSupported("GLX_ARB_create_context"))
{
_glfwLibrary.GLX.CreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)
diff --git a/src/x11_platform.h b/src/x11_platform.h
index e577c22f..84a2aa85 100644
--- a/src/x11_platform.h
+++ b/src/x11_platform.h
@@ -272,6 +272,7 @@ typedef struct _GLFWlibraryGLX
GLboolean EXT_swap_control;
GLboolean MESA_swap_control;
GLboolean ARB_multisample;
+ GLboolean ARB_framebuffer_sRGB;
GLboolean ARB_create_context;
GLboolean ARB_create_context_profile;
GLboolean ARB_create_context_robustness;
From 8e5b2239d3d8c04ba0f00ae0adcc499ac658e5ed Mon Sep 17 00:00:00 2001
From: Camilla Berglund
Date: Sun, 2 Dec 2012 16:14:49 +0100
Subject: [PATCH 4/4] Updated changelog.
---
readme.html | 1 +
1 file changed, 1 insertion(+)
diff --git a/readme.html b/readme.html
index 1e629456..3ad596c9 100644
--- a/readme.html
+++ b/readme.html
@@ -279,6 +279,7 @@ version of GLFW.
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 GLFW_SRGB_CAPABLE
for requesting sRGB capable framebuffers
Added GLFW_CLIENT_API
, GLFW_OPENGL_API
and GLFW_OPENGL_ES_API
for selecting client API
Added GLFW_OPENGL_ROBUSTNESS
window hint and associated strategy tokens for GL_ARB_robustness
support
Added GLFW_OPENGL_REVISION
window parameter to make up for removal of glfwGetGLVersion