SDL_SetWindowShape(3)

✨ SDL_SetWindowShape(3) ✨

okay bestie, gather round πŸ’– this is a page from the SDL3 FUNCTIONS collection, and it's all about SDL_SetWindowShape β€” the glow-up your window deserves.


🌸 NAME 🌸

SDL_SetWindowShape β€” set the shape of a transparent window. yes, shape. like, silhouette. main character energy for your window frame πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <SDL3/SDL_video.h>

bool SDL_SetWindowShape(SDL_Window *window, SDL_Surface *shape);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so here's the tea fr fr: this function sets the alpha channel of a transparent window, and any fully transparent areas are also transparent to mouse clicks. so it's not just a look, it's literally a vibe check for your input events too. obsessed.

ngl though, if you're using something besides the SDL render API, then you are responsible for drawing the alpha channel of the window to match the shape alpha channel to get consistent cross-platform results. no cap, that part is on you 🫢

the shape is copied inside this function, so you can free it afterwards. icon behaviour honestly. but if your shape surface changes, you should call SDL_SetWindowShape() again to update the window.

⚠️ heads up: this is an expensive operation, so it should be done sparingly. it's giving "treat it like a limited-edition drop", not "call it in a loop" πŸ’€

and the window must have been created with the SDL_WINDOW_TRANSPARENT flag. no flag, no shape, periodt.


πŸ’– FUNCTION PARAMETERS πŸ’–

  • window β€” the window. yeah, that one. the window you're shaping 🌈
  • shape β€” the surface representing the shape of the window, or NULL to remove any current shape. so NULL is basically the "never mind, back to rectangle" button πŸ™ˆ

⭐ RETURN VALUE ⭐

returns true on success or false on failure. and if it fails? call SDL_GetError() for more information β€” she will tell you what went wrong, iykyk.


🧚 THREAD SAFETY 🧚

this function should only be called on the main thread. don't be messy about it, bestie πŸ‘‘


πŸ’œ AVAILABILITY πŸ’œ

this function is available since SDL 3.2.0. so if you're on anything older, it's simply not giving ✨


and that's the whole page, mwah πŸ’‹ this was SDL_SetWindowShape(3) from Simple Directmedia Layer, version SDL 3.4.18 β€” go forth and shape your windows, you absolute legend πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from