diff --git a/docs/window.dox b/docs/window.dox index d9a837f6..17fa3002 100644 --- a/docs/window.dox +++ b/docs/window.dox @@ -287,6 +287,10 @@ __GLFW_DOUBLEBUFFER__ specifies whether the framebuffer should be double buffered. You nearly always want to use double buffering. This is a hard constraint. Possible values are `GLFW_TRUE` and `GLFW_FALSE`. +@anchor GLFW_TRANSPARENT_hint +__GLFW_TRANSPARENT__ specifies whether the framebuffer will support transparency +in the background. Possible values are `GLFW_TRUE` and `GLFW_FALSE`. + @subsubsection window_hints_mtr Monitor related hints diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 58b7d7b9..5e9eac6f 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -787,7 +787,6 @@ extern "C" { * Cursor centering [window hint](@ref GLFW_CENTER_CURSOR_hint). */ #define GLFW_CENTER_CURSOR 0x00020009 -#define GLFW_TRANSPARENT 0x0002000A /*! @brief Framebuffer bit depth hint. * @@ -869,6 +868,12 @@ extern "C" { * Framebuffer double buffering [hint](@ref GLFW_DOUBLEBUFFER). */ #define GLFW_DOUBLEBUFFER 0x00021010 +/*! @brief Framebuffer transparency hint. + * + * Framebuffer transparency [hint](@ref GLFW_TRANSPARENT_hint). + */ +#define GLFW_TRANSPARENT 0x00021011 + /*! @brief Context client API hint and attribute. * * Context client API [hint](@ref GLFW_CLIENT_API_hint) and diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 4b5cd3c1..5b2736b4 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -1085,7 +1085,7 @@ static GLFWbool createNativeWindow(_GLFWwindow* window, if (wndconfig->ns.retina) [window->ns.view setWantsBestResolutionOpenGLSurface:YES]; - if (window->transparent) + if (_glfw.hints.framebuffer.transparent) { [window->ns.object setOpaque:NO]; [window->ns.object setBackgroundColor:[NSColor clearColor]]; diff --git a/src/egl_context.c b/src/egl_context.c index e5435468..bba1efb7 100644 --- a/src/egl_context.c +++ b/src/egl_context.c @@ -493,7 +493,7 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window, if (ctxconfig->share) share = ctxconfig->share->context.egl.handle; - if (!chooseEGLConfig(ctxconfig, fbconfig, &config, window->transparent)) + if (!chooseEGLConfig(ctxconfig, fbconfig, &config, fbconfig->transparent)) { _glfwInputError(GLFW_FORMAT_UNAVAILABLE, "EGL: Failed to find a suitable EGLConfig"); @@ -738,7 +738,7 @@ GLFWbool _glfwChooseVisualEGL(const _GLFWwndconfig* wndconfig, EGLint visualID = 0, count = 0; const long vimask = VisualScreenMask | VisualIDMask; - if (!chooseEGLConfig(ctxconfig, fbconfig, &native, wndconfig->transparent)) + if (!chooseEGLConfig(ctxconfig, fbconfig, &native, fbconfig->transparent)) { _glfwInputError(GLFW_FORMAT_UNAVAILABLE, "EGL: Failed to find a suitable EGLConfig"); diff --git a/src/glx_context.c b/src/glx_context.c index 9d02a6fa..712e8c78 100644 --- a/src/glx_context.c +++ b/src/glx_context.c @@ -477,7 +477,7 @@ GLFWbool _glfwCreateContextGLX(_GLFWwindow* window, if (ctxconfig->share) share = ctxconfig->share->context.glx.handle; - if (!chooseGLXFBConfig(fbconfig, &native, window->transparent)) + if (!chooseGLXFBConfig(fbconfig, &native, fbconfig->transparent)) { _glfwInputError(GLFW_FORMAT_UNAVAILABLE, "GLX: Failed to find a suitable GLXFBConfig"); @@ -665,7 +665,7 @@ GLFWbool _glfwChooseVisualGLX(const _GLFWwndconfig* wndconfig, GLXFBConfig native; XVisualInfo* result; - if (!chooseGLXFBConfig(fbconfig, &native, wndconfig->transparent)) + if (!chooseGLXFBConfig(fbconfig, &native, fbconfig->transparent)) { _glfwInputError(GLFW_FORMAT_UNAVAILABLE, "GLX: Failed to find a suitable GLXFBConfig"); diff --git a/src/internal.h b/src/internal.h index 01517ec1..2e4e0150 100644 --- a/src/internal.h +++ b/src/internal.h @@ -299,7 +299,6 @@ struct _GLFWwndconfig GLFWbool resizable; GLFWbool visible; GLFWbool decorated; - GLFWbool transparent; GLFWbool focused; GLFWbool autoIconify; GLFWbool floating; @@ -360,6 +359,7 @@ struct _GLFWfbconfig int samples; GLFWbool sRGB; GLFWbool doublebuffer; + GLFWbool transparent; uintptr_t handle; }; @@ -403,7 +403,6 @@ struct _GLFWwindow // Window settings and state GLFWbool resizable; GLFWbool decorated; - GLFWbool transparent; GLFWbool autoIconify; GLFWbool floating; GLFWbool shouldClose; diff --git a/src/nsgl_context.m b/src/nsgl_context.m index ef247ca7..a7cbf00f 100644 --- a/src/nsgl_context.m +++ b/src/nsgl_context.m @@ -296,7 +296,7 @@ GLFWbool _glfwCreateContextNSGL(_GLFWwindow* window, return GLFW_FALSE; } - if (window->transparent) + if (fbconfig->transparent) { GLint opaque = 0; [window->context.nsgl.object setValues:&opaque forParameter:NSOpenGLCPSurfaceOpacity]; diff --git a/src/wgl_context.c b/src/wgl_context.c index 990eb299..0834e0a8 100644 --- a/src/wgl_context.c +++ b/src/wgl_context.c @@ -85,7 +85,7 @@ static int choosePixelFormat(_GLFWwindow* window, _GLFWfbconfig* u = usableConfigs + usableCount; PIXELFORMATDESCRIPTOR pfd; - if (window->transparent) { + if (fbconfig->transparent) { if (!DescribePixelFormat(window->context.wgl.dc, n, sizeof(PIXELFORMATDESCRIPTOR), @@ -168,7 +168,7 @@ static int choosePixelFormat(_GLFWwindow* window, { // Get pixel format attributes through legacy PFDs - if (!window->transparent && DescribePixelFormat(window->context.wgl.dc, + if (!fbconfig->transparent && DescribePixelFormat(window->context.wgl.dc, n, sizeof(PIXELFORMATDESCRIPTOR), &pfd)) @@ -217,8 +217,7 @@ static int choosePixelFormat(_GLFWwindow* window, } // Reiterate the selection loop without looking for transparency supporting // formats if no matching pixelformat for a transparent window were found. - if (window->transparent && !usableCount) { - window->transparent = GLFW_FALSE; + if (fbconfig->transparent && !usableCount) { free(usableConfigs); _glfwInputError(GLFW_PLATFORM_ERROR, "WGL: No pixel format found for transparent window. Ignoring transparency."); @@ -803,10 +802,12 @@ GLFWbool _glfwCreateContextWGL(_GLFWwindow* window, } } - if (window->transparent) + if (fbconfig->transparent) { if (!setupTransparentWindow(window)) - window->transparent = GLFW_FALSE; + _glfwInputErrorWin32(GLFW_PLATFORM_ERROR, + "WGL: Failed to setup window as transparent as requested"); + } window->context.makeCurrent = makeContextCurrentWGL; diff --git a/src/window.c b/src/window.c index e8a68b61..863f0ed2 100644 --- a/src/window.c +++ b/src/window.c @@ -147,6 +147,7 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, fbconfig = _glfw.hints.framebuffer; ctxconfig = _glfw.hints.context; wndconfig = _glfw.hints.window; + fbconfig.transparent = _glfw.hints.framebuffer.transparent ? GLFW_TRUE : GLFW_FALSE; wndconfig.width = width; wndconfig.height = height; @@ -180,7 +181,6 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, window->monitor = (_GLFWmonitor*) monitor; window->resizable = wndconfig.resizable; window->decorated = wndconfig.decorated; - window->transparent = wndconfig.transparent; window->autoIconify = wndconfig.autoIconify; window->floating = wndconfig.floating; window->cursorMode = GLFW_CURSOR_NORMAL; @@ -250,7 +250,6 @@ void glfwDefaultWindowHints(void) _glfw.hints.window.resizable = GLFW_TRUE; _glfw.hints.window.visible = GLFW_TRUE; _glfw.hints.window.decorated = GLFW_TRUE; - _glfw.hints.window.transparent = GLFW_FALSE; _glfw.hints.window.focused = GLFW_TRUE; _glfw.hints.window.autoIconify = GLFW_TRUE; @@ -317,6 +316,9 @@ GLFWAPI void glfwWindowHint(int hint, int value) case GLFW_DOUBLEBUFFER: _glfw.hints.framebuffer.doublebuffer = value ? GLFW_TRUE : GLFW_FALSE; return; + case GLFW_TRANSPARENT: + _glfw.hints.framebuffer.transparent = value ? GLFW_TRUE : GLFW_FALSE; + return; case GLFW_SAMPLES: _glfw.hints.framebuffer.samples = value; return; @@ -329,9 +331,6 @@ GLFWAPI void glfwWindowHint(int hint, int value) case GLFW_DECORATED: _glfw.hints.window.decorated = value ? GLFW_TRUE : GLFW_FALSE; return; - case GLFW_TRANSPARENT: - _glfw.hints.window.transparent = value ? GLFW_TRUE : GLFW_FALSE; - return; case GLFW_FOCUSED: _glfw.hints.window.focused = value ? GLFW_TRUE : GLFW_FALSE; return; @@ -733,8 +732,6 @@ GLFWAPI int glfwGetWindowAttrib(GLFWwindow* handle, int attrib) return window->resizable; case GLFW_DECORATED: return window->decorated; - case GLFW_TRANSPARENT: - return window->transparent; case GLFW_FLOATING: return window->floating; case GLFW_AUTO_ICONIFY: