SDL_ReadSurfacePixel(3)
β¨ SDL_ReadSurfacePixel(3) β¨
okay so bestie, welcome to the SDL3 FUNCTIONS section of the manual π this one's called SDL_ReadSurfacePixel and it is exactly what it sounds like β we're grabbing one single pixel. one. singular. pixel. it's giving surgical precision π
πΈ NAME πΈ
SDL_ReadSurfacePixel β Retrieves a single pixel from a surface. yes queen, one pixel, that's the whole job π
π¦ SYNOPSIS π¦
#include <SDL3/SDL_surface.h>
bool SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
look at her. seven whole arguments. she's thriving ππ
π DESCRIPTION π
so here's the tea, and it's important tea π«: this function prioritizes correctness over speed. like, it is not trying to be fast, it is trying to be right. that means it's literally perfect for unit tests, but it is not intended for use in a game engine. nope. do not put this in your render loop. i'm serious. it's the friend who double-checks the receipt at the restaurant β beloved, correct, not fast π’β¨
and ooh, second thing: like SDL_GetRGBA, this uses the entire 0..255 range when converting color components from pixel formats with less than 8 bits per RGB component. so a lil 5-bit channel still gets stretched all the way out to the full 0-255 glow-up π
π₯ no wasted range, no crumbs.
π FUNCTION PARAMETERS π
surfaceβ the surface to read. that's our girl. the thing we're peeking at πxβ the horizontal coordinate,0 <= x < width. stay in bounds bestie, we do not wander off the edge πyβ the vertical coordinate,0 <= y < height. same energy, but vertical πrβ a pointer filled in with the red channel,0-255, orNULLto ignore this channel. don't care about red? passNULL, live your truth πgβ a pointer filled in with the green channel,0-255, orNULLto ignore this channel. same deal, green edition πΏbβ a pointer filled in with the blue channel,0-255, orNULLto ignore this channel. blue bestie, also optional πaβ a pointer filled in with the alpha channel,0-255, orNULLto ignore this channel. alpha! the transparency of it all π«Ά
ngl the NULL thing is lowkey iconic β you can literally ask for just the channels you want and ghost the rest. obsessed.
β RETURN VALUE β
Returns true on success or false on failure π₯² and if it fails, call SDL_GetError() for more information. like, she will tell you what went wrong, you just have to ask π
π§ THREAD SAFETY π§
This function can be called on different threads with different surfaces. π
so like β multiple threads, multiple surfaces, absolutely no drama. note the vibe check though: different surfaces. don't be messy about it π
π AVAILABILITY π
This function is available since SDL 3.2.0. she's new-ish and she knows it β¨
and that's the whole page, bestie β go read a pixel, you've earned it π π¦
with love from the Simple Directmedia Layer girlies, SDL 3.4.18 era π (the date line was giving mysterious, so we're just gonna say hi and go) πβ¨
π¦ 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