When a window is in fullscreen mode, opacity handling depends on the platform and the graphics driver. Many platforms do not support transparency in true fullscreen mode because the window is rendered directly to the screen, bypassing the compositor responsible for blending transparent surfaces.
SDL_WINDOW_FULLSCREEN
): Transparency is typically ignored, and the window appears fully opaque. This is because the application takes over the entire screen, and there’s no compositor to blend with the background.SDL_WINDOW_FULLSCREEN_DESKTOP
): Transparency might work because the window is treated as a borderless window covering the screen, allowing the compositor to manage blending.SDL_WINDOW_FULLSCREEN_DESKTOP
.Below, we attempt to set the transparency of a fullscreen window:
#include <SDL.h>
#include <iostream>
int main() {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cerr << "SDL Init Error: "
<< SDL_GetError() << "\n";
return -1;
}
SDL_Window* window = SDL_CreateWindow(
"Fullscreen Opacity Test",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
800, 600,
SDL_WINDOW_SHOWN
);
// Set transparency
SDL_SetWindowOpacity(window, 0.5f);
SDL_SetWindowFullscreen(window,
SDL_WINDOW_FULLSCREEN_DESKTOP);
SDL_Delay(3000);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
In fullscreen desktop mode, transparency works if supported by the platform.
Test fullscreen opacity behavior on your target platform to avoid unexpected results.
Answers to questions are automatically generated and may not have been reviewed.
Discover how to use SDL2 functions for controlling and retrieving window transparency settings.