Creating a Window

Using Multiple Windows in SDL

Can I create and manage multiple windows in SDL, and if so, how?

Abstract art representing computer programming

Yes, SDL supports managing multiple windows. Each window in SDL is managed through a separate SDL_Window pointer. You can create multiple instances of your Window class or manage multiple SDL_Window pointers directly in your main application. Here’s a simple example of managing two windows:

#include <SDL.h>

int main(int argc, char** argv) {
  SDL_Init(SDL_INIT_VIDEO);

  SDL_Window* window1 = SDL_CreateWindow(
    "Window 1", 100, 100, 640, 480, 0);
  SDL_Window* window2 = SDL_CreateWindow(
    "Window 2", 750, 100, 640, 480, 0);

  bool running = true;
  SDL_Event event;

  while (running) {
    while (SDL_PollEvent(&event)) {
      if (event.type == SDL_QUIT) {
        running = false;
      }
    }

    SDL_UpdateWindowSurface(window1);
    SDL_UpdateWindowSurface(window2);
  }

  SDL_DestroyWindow(window1);
  SDL_DestroyWindow(window2);
  SDL_Quit();
  return 0;
}

This example initializes two separate windows and updates their surfaces in the main loop. When the SDL_QUIT event is detected, both windows close.

This Question is from the Lesson:

Creating a Window

Learn how to create and customize windows, covering initialization, window management, and rendering

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

This Question is from the Lesson:

Creating a Window

Learn how to create and customize windows, covering initialization, window management, and rendering

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

This course includes:

  • 118 Lessons
  • 92% Positive Reviews
  • Regularly Updated
  • Help and FAQs
Free, Unlimited Access

Professional C++

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

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