Window Decorations and Borders

Can SDL customize border colors?

Can I change the color of the border or title bar in SDL2?

Abstract art representing computer programming

SDL2 does not provide built-in functions to customize the color, style, or appearance of the border or title bar. The reason for this limitation lies in SDL’s design philosophy: it abstracts away platform-specific details to provide a consistent API.

On most systems, window decorations (borders, title bars) are controlled by the operating system.

If you need a custom border or title bar, you must disable the system decorations using the SDL_WINDOW_BORDERLESS flag and draw your own window frame within the application:

#include <SDL.h>

int main() {
  SDL_Init(SDL_INIT_VIDEO);

  SDL_Window* Window{SDL_CreateWindow(
    "Custom Border",
    SDL_WINDOWPOS_CENTERED,
    SDL_WINDOWPOS_CENTERED,
    800, 600,
    SDL_WINDOW_BORDERLESS 
  )};

  SDL_Renderer* Renderer{SDL_CreateRenderer(
    Window, -1, 0)};

  // Render a custom border
  SDL_SetRenderDrawColor(Renderer,
    255, 0, 0, 255); // Red
  SDL_Rect Border{0, 0, 800, 600};
  SDL_RenderFillRect(Renderer, &Border);

  SDL_SetRenderDrawColor(Renderer,
    0, 0, 0, 255); // Black client area
  SDL_Rect ClientArea{10, 10, 780, 580}; 
  SDL_RenderFillRect(Renderer, &ClientArea);

  SDL_RenderPresent(Renderer);
  SDL_Delay(3000);

  SDL_DestroyRenderer(Renderer);
  SDL_DestroyWindow(Window);
  SDL_Quit();
}
Renders a red border with a black client area.

For advanced UI frameworks, you may need to integrate with libraries like Dear ImGui or build custom styles using OpenGL or Vulkan.

This Question is from the Lesson:

Window Decorations and Borders

An introduction to managing SDL2 window decorations, borders, and client areas.

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

This Question is from the Lesson:

Window Decorations and Borders

An introduction to managing SDL2 window decorations, borders, and client areas.

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