SDL_GetWindowSurface(3)
π SDL_GetWindowSurface(3) π
okay bestie, welcome to the SDL3 FUNCTIONS section of the manual, we're gonna talk about surfaces, windows, and the sacred art of not freeing things you don't own π«Ά
β¨ NAME β¨
SDL_GetWindowSurface β grab the SDL_Surface that's chillin' with your window π
β¨ SYNOPSIS β¨
#include <SDL3/SDL_video.h>
SDL_Surface * SDL_GetWindowSurface(SDL_Window *window);
β¨ DESCRIPTION β¨
so basically? if it needs to, this function makes you a brand new surface in the optimal format for the window. that's the whole point. no cap.
and here's the part everyone gets wrong on the first try: this surface gets freed when the window is destroyed. do NOT free this surface. like. it's not yours. it's the window's. hands off. π
also, the moment you resize the window, this surface gets invalidated. poof. gone. so after a resize you have to call this function again to get a valid surface back. it's giving "the vibe check resets every time you change the layout," iykyk.
and you may not combine this with 3D or the rendering API on this window. pick a lane. pick one. it's not both. π
oh and also β this function is affected by SDL_HINT_FRAMEBUFFER_ACCELERATION. just so you know. the hint has opinions and they matter here.
β¨ FUNCTION PARAMETERS β¨
windowβ the window you're querying, bestie. that's the one. π
β¨ RETURN VALUE β¨
returns the surface associated with the window π β¦or NULL if it failed π. and if you get NULL, go call SDL_GetError() for more info, because it will tell you what went wrong. it's not gonna gatekeep.
β¨ THREAD SAFETY β¨
main thread only, periodt. π«π§΅ this function should only be called on the main thread.
β¨ AVAILABILITY β¨
this function has been available since SDL 3.2.0. she's not new new but she's not ancient either. β¨
β¨ SEE ALSO β¨
SDL_DestroyWindowSurface(3)SDL_WindowHasSurface(3)SDL_UpdateWindowSurface(3)SDL_UpdateWindowSurfaceRects(3)
and that's the whole page, bestie!! πΈ go forth, get your surface, and do not free it π
this was brought to you by the lovely folks at Simple Directmedia Layer, straight outta SDL 3.4.18, and yes, the manual page was literally called SDL_GetWindowSurface(3) the whole time β iconic of her, honestly. mwah ππ¦
π¦ 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