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.
Answers to questions are automatically generated and may not have been reviewed.
Learn how to create and customize windows, covering initialization, window management, and rendering