Window Titles

Styling SDL Titles

Is it possible to style the window title (e.g., bold text)?

Abstract art representing computer programming

Unfortunately, SDL does not support styling window titles. The title displayed in a window's border is entirely controlled by the operating system’s window manager. This means you cannot apply styles like bold, italic, or color changes.

Workarounds for Styled Titles

If you need styled text, consider displaying it inside the window itself, rather than relying on the title bar. Use SDL rendering or a library like SDL_ttf for custom text rendering.

#include <SDL.h>
#include <SDL_ttf.h>
#include <string>

int main() {
  SDL_Init(SDL_INIT_VIDEO);
  TTF_Init();

  SDL_Window* window = SDL_CreateWindow(
    "Styled Title Example",
    SDL_WINDOWPOS_CENTERED,
    SDL_WINDOWPOS_CENTERED,
    800,
    600,
    SDL_WINDOW_SHOWN
  );

  SDL_Renderer* renderer = SDL_CreateRenderer(
    window, -1, SDL_RENDERER_ACCELERATED);
  TTF_Font* font =
    TTF_OpenFont("Arial.ttf", 24);
    
  // White text
  SDL_Color color = {255, 255, 255, 255};
  
  SDL_Surface* surface = TTF_RenderText_Blended(
    font, "Bold Title Inside Window", color);
    
  SDL_Texture* texture =
    SDL_CreateTextureFromSurface(
      renderer, surface);

  SDL_Rect dst = {
    200, 250, surface->w, surface->h};
  SDL_FreeSurface(surface);

  SDL_RenderClear(renderer);
  SDL_RenderCopy(renderer, texture, nullptr,
                 &dst);
  SDL_RenderPresent(renderer);

  SDL_Delay(3000);
  SDL_DestroyTexture(texture);
  TTF_CloseFont(font);
  SDL_DestroyRenderer(renderer);
  SDL_DestroyWindow(window);

  TTF_Quit();
  SDL_Quit();
}
Displays "Bold Title Inside Window" rendered in the window.

For styling, always work within your window’s content area.

This Question is from the Lesson:

Window Titles

Learn how to set, get, and update window titles dynamically

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

This Question is from the Lesson:

Window Titles

Learn how to set, get, and update window titles dynamically

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