SDL_LockSurface(3)
π SDL_LockSurface(3) π
okay bestie, so we're in the SDL3 FUNCTIONS corner of the manual, and today's main character is SDL_LockSurface β it's giving "let me at those pixels" energy. no cap.
β¨ NAME β¨
SDL_LockSurface β set up a surface so you can go straight in and touch the pixels yourself. direct access, hand on the glass, no middleman. π«Ά
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_surface.h>
bool SDL_LockSurface(SDL_Surface *surface);
π¦ DESCRIPTION π¦
okay so picture this: between your calls to SDL_LockSurface() and SDL_UnlockSurface(), you can write to and read from surface->pixels, using whatever pixel format is chillin' in surface->format. it's literally right there for you. π
and the moment you're done messing with the surface? you should hit SDL_UnlockSurface() to release it. don't be the person who locks and never unlocks, that's not the vibe. π
here's the tea though β not all surfaces require locking. if SDL_MUSTLOCK(surface) evaluates to 0, then you can read and write to the surface any time you want, and the pixel format of the surface will not change. so chill, it's fine. β¨
π FUNCTION PARAMETERS π
surfaceβ theSDL_Surfacestructure that's getting locked. that's the one. that's her. π
β RETURN VALUE β
returns true on success or false on failure. if it flops, call SDL_GetError() for more info β she'll tell you what went wrong. π
π₯ THREAD SAFETY π₯
you can call this function on different threads, as long as it's with different surfaces. multiple surfaces, multiple threads, everyone thriving. π
but lowkey important: the "locking" this function is talking about is making the pixels available for direct access β it is not thread-safe locking. those are two different things, bestie, don't mix them up. π
π AVAILABILITY π
this function has been available since SDL 3.2.0. she's been here, she's iconic. β¨
πΈ SEE ALSO πΈ
okay that's the whole page, you ate it fr fr π this was brought to you by Simple Directmedia Layer, running SDL 3.4.18 β go lock a surface, bestie, and remember to unlock it. mwah ππ§
π¦ 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