SDL_CreateWindow(3)
π SDL_CreateWindow π
okay bestie, welcome to the SDL3 video era, this is SDL_CreateWindow(3) and it is literally how you make a window. yes. a whole window. your lil rectangle of destiny. let's go πͺβ¨
πΈ NAME πΈ
SDL_CreateWindow β spawn a window with the dimensions and flags you want, no cap.
β¨ SYNOPSIS β¨
#include <SDL3/SDL_video.h>
SDL_Window * SDL_CreateWindow(const char *title, int w, int h, SDL_WindowFlags flags);
π¦ DESCRIPTION π¦
so here's the tea: the size you ask for? it's a request, bestie. it might not be what you get, because desktop layout and window manager policies have opinions, and honestly? they're the main character here. your app needs to be prepared to handle a window of any size. any. size. it's giving "flexible or perish" π
flags can be any of the following, OR'd together (yes, mix and match, it's a vibe):
SDL_WINDOW_FULLSCREENβ fullscreen window at desktop resolution π₯οΈSDL_WINDOW_OPENGLβ window usable with an OpenGL contextSDL_WINDOW_HIDDENβ window is not visible πSDL_WINDOW_BORDERLESSβ no window decoration, clean face, no frame πSDL_WINDOW_RESIZABLEβ window can be resizedSDL_WINDOW_MINIMIZEDβ window is minimizedSDL_WINDOW_MAXIMIZEDβ window is maximizedSDL_WINDOW_MOUSE_GRABBEDβ window has grabbed mouse focusSDL_WINDOW_INPUT_FOCUSβ window has input focusSDL_WINDOW_MOUSE_FOCUSβ window has mouse focusSDL_WINDOW_EXTERNALβ window not created by SDLSDL_WINDOW_MODALβ window is modalSDL_WINDOW_HIGH_PIXEL_DENSITYβ window uses high pixel density back buffer if possible β¨SDL_WINDOW_MOUSE_CAPTUREβ window has mouse captured (unrelated toMOUSE_GRABBED, do not confuse them, they are different girls)SDL_WINDOW_ALWAYS_ON_TOPβ window should always be above others πSDL_WINDOW_UTILITYβ window should be treated as a utility window, not showing in the task bar and window listSDL_WINDOW_TOOLTIPβ window should be treated as a tooltip and does not get mouse or keyboard focus, requires a parent windowSDL_WINDOW_POPUP_MENUβ window should be treated as a popup menu, requires a parent windowSDL_WINDOW_KEYBOARD_GRABBEDβ window has grabbed keyboard inputSDL_WINDOW_VULKANβ window usable with a Vulkan instanceSDL_WINDOW_METALβ window usable with a Metal instanceSDL_WINDOW_TRANSPARENTβ window with transparent buffer π«₯SDL_WINDOW_NOT_FOCUSABLEβ window should not be focusable
the SDL_Window will be shown if SDL_WINDOW_HIDDEN is not set. and if you did hide it at creation time? no worries babe, SDL_ShowWindow() can show it later. delayed slay π
on Apple's macOS, you must set the NSHighResolutionCapable Info.plist property to YES, otherwise you will not receive a High-DPI OpenGL canvas. periodt. don't skip this one.
the window pixel size may differ from its window coordinate size if the window is on a high pixel density display. use SDL_GetWindowSize() to query the client area's size in window coordinates, and SDL_GetWindowSizeInPixels() or SDL_GetRenderOutputSize() to query the drawable size in pixels. note that the drawable size can vary after the window is created and should be queried again if you get an SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED event. yeah it moves, she's dynamic, keep up π¦
if the window is created with any of the SDL_WINDOW_OPENGL or SDL_WINDOW_VULKAN flags, then the corresponding LoadLibrary function (SDL_GL_LoadLibrary or SDL_Vulkan_LoadLibrary) is called, and the corresponding UnloadLibrary function is called by SDL_DestroyWindow(). it's a whole situationship, they come as a pair.
if SDL_WINDOW_VULKAN is specified and there isn't a working Vulkan driver, SDL_CreateWindow() will fail, because SDL_Vulkan_LoadLibrary() will fail. chain reaction, bestie π
if SDL_WINDOW_METAL is specified on an OS that does not support Metal, SDL_CreateWindow() will fail.
if you intend to use this window with an SDL_Renderer, you should use SDL_CreateWindowAndRenderer() instead of this function, to avoid window flicker. fr fr, save yourself the flicker.
on non-Apple devices, SDL requires you to either not link to the Vulkan loader or link to a dynamic library version. this limitation may be removed in a future version of SDL. so like, it's a thing for now, iykyk.
π FUNCTION PARAMETERS π
titleβ the title of the window, in UTF-8 encoding.wβ the width of the window.hβ the height of the window.flagsβ0, or one or moreSDL_WindowFlagsOR'd together.
β RETURN VALUE β
returns the window that was created, or NULL on failure π β in which case, call SDL_GetError() for more information. she'll tell you what went wrong.
π§ THREAD SAFETY π§
this function should only be called on the main thread. main character energy only, no side quests on other threads.
π AVAILABILITY π
this function is available since SDL 3.2.0.
π SEE ALSO π
SDL_CreateWindowAndRenderer(3)SDL_CreatePopupWindow(3)SDL_CreateWindowWithProperties(3)SDL_DestroyWindow(3)
and that's the whole page, bestie π«Ά this lil drop is from Simple Directmedia Layer, version SDL 3.4.18, and yeah it's SDL_CreateWindow(3) β go make a window, you're gonna eat π
β¨π
π¦ where this page comes from
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms