SDL_LockTexture(3)
π SDL_LockTexture(3) π
okay bestie, welcome to the SDL3 FUNCTIONS section of the manual, and today's main character is SDL_LockTexture π
β¨ NAME β¨
SDL_LockTexture β lock a portion of the texture for write-only pixel access. yes, write-only, we'll get to that, it matters, i promise π«Ά
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_render.h>
bool SDL_LockTexture(SDL_Texture *texture,
const SDL_Rect *rect,
void **pixels, int *pitch);
that's the whole vibe right there, no cap β¨
π¦ DESCRIPTION π¦
so here's the tea β β as an optimization, the pixels you get handed to edit don't necessarily contain the old texture data. it's giving "surprise, it's empty in here". this is a write-only operation, and if you need to keep a copy of the texture data you should do that at the application level. so like, back it up yourself, bestie, don't come crying to SDL π
you must use SDL_UnlockTexture() to unlock the pixels and apply any changes. that's the whole point. lock, write, unlock, apply. periodt π
π FUNCTION PARAMETERS π
textureβ the texture to lock for access, which was created withSDL_TEXTUREACCESS_STREAMING. if it wasn't made with that flag, we are not doing this today πrectβ anSDL_Rectstructure representing the area to lock for access;NULLto lock the entire texture. just the whole thing. go off πpixelsβ this is filled in with a pointer to the locked pixels, appropriately offset by the locked area. SDL hands you the pointer, you don't bring your own β¨pitchβ this is filled in with the pitch of the locked pixels; the pitch is the length of one row in bytes. one row. in bytes. that's the definition, memorize it π§
β RETURN VALUE β
returns true on success π or false if the texture is not valid or was not created with SDL_TEXTUREACCESS_STREAMING π β and if that happens, call SDL_GetError() for more information. she'll tell you what went wrong, she's very honest π«Ά
π₯ THREAD SAFETY π₯
this function should only be called on the main thread. do not be passing this to a worker thread, bestie, i'm begging π
π AVAILABILITY π
this function is available since SDL 3.2.0 π
π SEE ALSO π
and that's the whole page, bestie. lock it, write it, unlock it, slay π β¨
Simple Directmedia Layer β’ version SDL 3.4.18 β’ and yeah this page is literally titled SDL_LockTexture(3), we love a self-titled moment π mwah, go forth and stream those textures π¦πΈ
π¦ 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