# Does SDL2 actually support multiple windows?

**URL:** <https://discourse.libsdl.org/t/does-sdl2-actually-support-multiple-windows/25933>\
**Category:** SDL Development\
**Created:** [March 22, 2019, 10:59am UTC](https://discourse.libsdl.org/t/does-sdl2-actually-support-multiple-windows/25933 "2019-03-22T10:59:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lamefun](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/l/ecb155/32.png) [@lamefun](https://discourse.libsdl.org/u/lamefun)\
**Post date:** [March 22, 2019, 10:59am UTC](https://discourse.libsdl.org/t/does-sdl2-actually-support-multiple-windows/25933/1 "2019-03-22T10:59:00Z")

</div>

It’s possible to call SDL\_CreateWindow multiple times and it indeed opens multiple windows, but what then? Specifically, how to swap buffers when multiple windows are present?

```cpp
// Render window1.
SDL_GL_MakeCurrent(glContext1, window1);
glClear(GL_COLOR_BUFFER_BIT);

// Render window2.
SDL_GL_MakeCurrent(glContext2, window2);
glClear(GL_COLOR_BUFFER_BIT);

// Waits for V-Sync then swaps buffers.
SDL_GL_MakeCurrent(glContext1, window1); // Is context switch needed?
SDL_GL_SwapWindow(window1); 

// Does this swap buffers immediately or wait for the next V-Sync?
// If it swaps buffers immediately, how does it know that it doesn't
// need to wait? Is there a time limit? If it waits for V-Sybc every
// time, how to swap buffers when multiple windows are present?
SDL_GL_MakeCurrent(glContext2, window2); // Is context switch needed?
SDL_GL_SwapWindow(window2); 

```

---

<div class="post-metadata">

**Author:** ![rtrussell](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/rtrussell/32/4768_2.png) [@rtrussell](https://discourse.libsdl.org/u/rtrussell)\
**Post date:** [March 22, 2019, 2:37pm UTC](https://discourse.libsdl.org/t/does-sdl2-actually-support-multiple-windows/25933/2 "2019-03-22T14:37:16Z")

</div>

> [@lamefun](#):
>
> Specifically, how to swap buffers when multiple windows are present?

In my experience it is necessary only to call `SDL_RenderPresent()` for each window (i.e. each renderer). Whether or not it waits for vSync depends on whether the SDL\_RENDERER\_PRESENTVSYNC flag was passed to `SDL_CreateRenderer()`.
