Window Opacity

Opacity and Fullscreen Windows

How does opacity interact with fullscreen windows?

Abstract art representing computer programming

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.

Behavior in Fullscreen Modes

  1. True Fullscreen (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.
  2. Fullscreen Desktop (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.

Practical Notes

  • If you need transparency in fullscreen, prefer SDL_WINDOW_FULLSCREEN_DESKTOP.
  • Keep in mind that performance might differ between true fullscreen and fullscreen desktop, especially for games or graphics-intensive applications.

Example: Testing Opacity in Fullscreen

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.

This Question is from the Lesson:

Window Opacity

Discover how to use SDL2 functions for controlling and retrieving window transparency settings.

Answers to questions are automatically generated and may not have been reviewed.

This Question is from the Lesson:

Window Opacity

Discover how to use SDL2 functions for controlling and retrieving window transparency settings.

sdl2-promo.jpg
Part of the course:

Game Dev with SDL2

Learn C++ and SDL development by creating hands on, practical projects inspired by classic retro games

Free, unlimited access

This course includes:

  • 67 Lessons
  • 100+ Code Samples
  • 91% Positive Reviews
  • Regularly Updated
  • Help and FAQ
Free, Unlimited Access

Professional C++

Comprehensive course covering advanced concepts, and how to use them on large-scale projects.

Screenshot from Warhammer: Total War
Screenshot from Tomb Raider
Screenshot from Jedi: Fallen Order
Contact|Privacy Policy|Terms of Use
Copyright © 2024 - All Rights Reserved