SDL_SetColorKey(3)
π SDL_SetColorKey π
okay bestie, gather round, because this one is literally the transparent pixel icon of the SDL API. this is SDL_SetColorKey from the SDL API Reference, and she is that girl π
β¨ NAME β¨
SDL_SetColorKey β sets the color key (transparent pixel) in a blittable surface, and does the RLE acceleration thing too. no cap π¦
β¨ SYNOPSIS β¨
#include "SDL.h"
int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key);
β¨ DESCRIPTION β¨
so basically, this function sets the color key β that's the transparent pixel β in a blittable surface, and it also turns RLE blit acceleration on or off. two jobs, one function, she's working overtime π
RLE acceleration can substantially speed up blitting of images that have big horizontal runs of transparent pixels β iykyk, those are the pixels that match the key value. πββοΈπ¨
the key has to be the same pixel format as the surface, okay? and SDL_MapRGB is often useful for getting a value that actually works. don't skip that part bestie π
here's the flag tea, sip slowly π
- if
flagisSDL_SRCCOLORKEY, thenkeyis the transparent pixel value in the source image of a blit. - if
flagis OR'd withSDL_RLEACCEL, then the surface will be drawn using RLE acceleration whenever it's drawn withSDL_BlitSurface. and here's the lowkey sneaky bit: the surface doesn't get actually encoded for RLE acceleration until the first timeSDL_BlitSurfaceorSDL_DisplayFormatis called on it. it's giving "I'll do it later" energy, but fr fr it does happen π - if
flagis0, this function clears any current color key. gone. bye. periodt π
β¨ RETURN VALUE β¨
this function returns 0, or -1 if there was an error. so if you see that -1... it's not a vibe, something went wrong π
β¨ SEE ALSO β¨
SDL_BlitSurfaceSDL_DisplayFormatSDL_MapRGBSDL_SetAlpha
go read those too, you're already here, might as well slay the whole set π
and that's the whole page, bestie!! this was SDL, part of the SDL API Reference, and it was last touched up on Tue 11 Sep 2001, 23:01. iconic date, iconic function. mwah π«Άβ¨πΈ
π¦ where this page comes from
- debian bookworm: libsdl1.2-dev 1.2.15+dfsg2-8 Β· LGPL-2.1-or-later
- nixos 26.05: SDL_sixel 0-unstable-2016-02-06
- nixpkgs unstable: SDL_sixel 0-unstable-2016-02-06
- ubuntu jammy: libsdl1.2-dev 1.2.15+dfsg2-6 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms