SDL_SetWindowIcon(3)

πŸ’– SDL_SetWindowIcon(3) πŸ’–

okay so bestie, welcome to the SDL3 FUNCTIONS corner of the man pages, this one is literally called SDL_SetWindowIcon and it does exactly one iconic thing: it sets the icon for a window. that's it. that's the whole vibe. πŸŽ€


✨ NAME ✨

SDL_SetWindowIcon β€” set the icon for a window. πŸ’…


🌈 SYNOPSIS 🌈

#include <SDL3/SDL_video.h>

bool SDL_SetWindowIcon(SDL_Window *window, SDL_Surface *icon);

like. two arguments. one bool. we love a minimal signature. πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so here's the tea, and it's actually kind of genius. πŸ“

if you pass this function a surface that has alternate representations added to it using SDL_AddSurfaceAlternateImage(), then that surface gets interpreted as the content for 100% display scale, and the alternate representations get used for high DPI situations. so it's giving "one icon, many resolutions, we're prepared for every screen." ✨

for example β€” and this is the example, bestie, I'm not making it up β€” if the original surface is 32x32, then on a 2x macOS display or 200% display scale on Windows, a 64x64 version of the image will be used, if available. πŸ‘€

and if a matching version of the image isn't available? then the closest larger size image will be downscaled to the appropriate size and be used instead, if available. and if that's not available either? then the closest smaller image will be upscaled and be used instead. it's a whole fallback chain and honestly it ate. πŸ”₯


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • window β€” the window you're changing, bestie. the one getting the glow-up. πŸ’–
  • icon β€” an SDL_Surface structure containing the icon for the window. yes, a whole SDL_Surface. bring your own pixels. πŸ–ΌοΈ

⭐ RETURN VALUE ⭐

returns true on success or false on failure. 😭

and if it fails, call SDL_GetError() for more information, because the error message is the group chat that will tell you what actually went wrong. no cap. πŸ’€


🧚 THREAD SAFETY 🧚

⚠️ this function should only be called on the main thread. periodt. do not try it anywhere else, the main character energy stays on the main thread. πŸ‘‘

🌸 AVAILABILITY 🌸

this function is available since SDL 3.2.0. so if you're on something older, it's simply not giving. πŸ™ˆ


πŸ’œ SEE ALSO πŸ’œ


Simple Directmedia Layer Β· SDL 3.4.18 Β· SDL_SetWindowIcon(3)

and that's the whole page babes, mwah πŸ’‹ this was SDL 3.4.18 brought to you by the Simple Directmedia Layer girlies, signing off, stay slaying your window icons βœ¨πŸ’…πŸŒΈ

πŸ“¦ where this page comes from