SDL_MapSurfaceRGB(3)
π SDL_MapSurfaceRGB π
okay bestie, welcome to the SDL3 FUNCTIONS section of the manual, and today's main character is SDL_MapSurfaceRGB β she maps an RGB triple to an opaque pixel value for a surface. that's it, that's the gig, and she does it flawlessly. periodt. β¨
π SYNOPSIS π
#include <SDL3/SDL_surface.h>
Uint32 SDL_MapSurfaceRGB(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b);
like, look at her. clean signature. no notes. π«Ά
β¨ DESCRIPTION β¨
so what does she actually do? this function maps the RGB color value to the specified pixel format and hands you back the pixel value that best approximates the RGB color value you gave her, for that pixel format. it's giving translator, but for colors. π
if the surface has a palette, then the index of the closest matching color in the palette will be returned. she's out here doing her best matchmaking, fr fr. π
if the surface pixel format has an alpha component, that alpha will be returned as all 1 bits β which is fully opaque. no half-transparent nonsense, she said opaque and she meant it. π
and here's the cute lil detail you need to remember: if the pixel format bpp (color depth) is less than 32-bpp, then the unused upper bits of the return value can safely be ignored. like, with a 16-bpp format the return value can be assigned to a Uint16, and similarly a Uint8 for an 8-bpp format. so don't panic about the extra bits bestie, they're just vibes. π
π¦ FUNCTION PARAMETERS π¦
surfaceβ the surface to use for the pixel format and palette. your source of truth, your blueprint, your girl. πΈrβ the red component of the pixel in the range0-255. π₯gβ the green component of the pixel in the range0-255. πbβ the blue component of the pixel in the range0-255. π
β RETURN VALUE β
Returns a pixel value. that's the whole thing. iconic, honestly. π
π§ THREAD SAFETY π§
good news bestie: this function can be called on different threads with different surfaces. so go forth and parallelize, just keep your surfaces separate, okay? no sharing drama. π
π AVAILABILITY π
This function is available since SDL 3.2.0. so if you're on anything older... not me finding out the hard way. π
π SEE ALSO π
SDL_MapSurfaceRGBA(3)β her sister, the one who actually cares about alpha. go say hi. π
and that's the whole page, bestie!! this lil slice of documentation came to you courtesy of Simple Directmedia Layer, version SDL 3.4.18 β tysm for reading, mwah, slay, drink water, and go map some pixels. ππ
β¨π¦πΈπ«Ά
π¦ 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