SDL_CreateWindow
Opens a window. Flags choose how it can be drawn into (OpenGL, Vulkan…) and how it behaves.
Signature
SDL_Window * SDL_CreateWindow(const char *title, int w, int h, SDL_WindowFlags flags);
How it works
The window alone shows nothing: you still need something that draws into it. For 2D, create an SDL_Renderer for it (or use SDL_CreateWindowAndRenderer, which does both). For OpenGL add SDL_WINDOW_OPENGL and create a context; for Vulkan add SDL_WINDOW_VULKAN; SDL_GPU needs no flag.
Unlike SDL2 there are no x and y parameters: the system places the window. Move it afterwards with SDL_SetWindowPosition if you care.
Parameters
Title bar text, UTF-8.
Width in window coordinates (not always pixels: see SDL_GetWindowSizeInPixels).
Height in window coordinates.
0, or flags combined with |.
Common values
- SDL_WINDOW_RESIZABLE
- The user can resize it.
- SDL_WINDOW_HIGH_PIXEL_DENSITY
- Ask for the full pixel resolution on Retina / high-DPI screens.
- SDL_WINDOW_FULLSCREEN
- Start in full screen (desktop resolution).
- SDL_WINDOW_OPENGL / SDL_WINDOW_VULKAN
- The window will be used with an OpenGL context / a Vulkan surface.
- SDL_WINDOW_HIDDEN
- Create it invisible; SDL_ShowWindow later.
- SDL_WINDOW_BORDERLESS
- No title bar or border.
Return value
The window, or NULL on failure (see SDL_GetError).
Tips & pitfalls
The size is a request: a tiling window manager or a small screen may give you another one. Handle any size.
Example
1SDL_Window* window = SDL_CreateWindow("Editor", 1280, 720,
2 SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY);
3if (!window) {
4 SDL_Log("CreateWindow: %s", SDL_GetError());
5 return 1;
6}
7SDL_Renderer* renderer = SDL_CreateRenderer(window, nullptr);