SDL_SetSurfaceColorKey(3)
π SDL_SetSurfaceColorKey π
okay so bestie, we're in the SDL3 FUNCTIONS section of the manual, and today's main character is SDL_SetSurfaceColorKey(3). she's the one who decides which pixel gets to be invisible. let's go π«Ά
β¨ NAME β¨
SDL_SetSurfaceColorKey</purl> β set the color key (transparent pixel) in a surface. yes, the whole point is making one specific pixel value β¨not existβ¨ during a blit. iconic behaviour, honestly π
β¨ SYNOPSIS β¨
#include <SDL3/SDL_surface.h>
bool SDL_SetSurfaceColorKey(SDL_Surface *surface, bool enabled, Uint32 key);
β¨ DESCRIPTION β¨
so the color key is literally a pixel value that gets treated as transparent in a blit. like, ghosted. not rendered. gone. π¦
for example, you can use this to say that cyan pixels should be considered transparent, and therefore not rendered at all. poof. bye. π
and it's a pixel of the format used by the surface, as generated by SDL_MapRGB(). so don't just make up a number, bestie, run it through SDL_MapRGB() first or it's giving chaos. π
β¨ FUNCTION PARAMETERS β¨
surfaceβ theSDL_Surfacestructure to update. this is the one getting the glow-up β¨enabledβtrueto enable color key,falseto disable color key. flip the switch, queen πkeyβ the transparent pixel. the one we're sending to the shadow realm π
β¨ 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, fr fr.
β¨ THREAD SAFETY β¨
this function can be called on different threads with different surfaces. so like, multi-threaded girlies, you're safe β as long as the surfaces are different ones. no sharing, no drama π
β¨ AVAILABILITY β¨
this function is available since SDL 3.2.0. so if you're on something older, that's a no from her πΈ
β¨ SEE ALSO β¨
and that's the whole page, bestie!! this beauty comes to you from Simple Directmedia Layer, version SDL 3.4.18 π go forth and make pixels invisible, you absolute icon βππ
π¦ 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