SDL_CreateTextureFromSurface(3)
π SDL_CreateTextureFromSurface π
okay bestie, welcome to SDL3 FUNCTIONS β this one's called SDL_CreateTextureFromSurface and it does exactly what it says on the tin: you hand it a surface, it hands you back a whole texture. glow-up arc, fr fr. β¨
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_render.h>
SDL_Texture * SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *surface);
π¦ DESCRIPTION π¦
so here's the tea, and it's important tea: the surface is not modified or freed by this function. like, it doesn't touch your surface, it doesn't take it out, it doesn't do anything to it. it just looks at it and copies the vibes over. you still own that surface, you still gotta deal with it yourself. no cap. π
the SDL_TextureAccess hint for the created texture is SDL_TEXTUREACCESS_STATIC. that's just the way it is, that's its whole personality. π
and okay, this is the part people get caught off guard by: the pixel format of the created texture may be different from the pixel format of the surface. yeah. they don't have to match. if you need to know what format you actually ended up with, you can query it using the SDL_PROP_TEXTURE_FORMAT_NUMBER property. iykyk. π
π FUNCTION PARAMETERS π
rendererβ the rendering context. this is your main character, the one doing the rendering. it needs to exist and it needs to be the one you want this texture to belong to.surfaceβ theSDL_Surfacestructure containing pixel data used to fill the texture. this is your source material bestie, the raw pixel data getting poured into the new texture. π«Ά
β RETURN VALUE β
you get the created texture back! π icon. it ate.
but if it fails, you get NULL. and listen, don't just sit there wondering what went wrong β call SDL_GetError() for more information, she will tell you. π
π₯ THREAD SAFETY π₯
this function should only be called on the main thread. no side quests, no background threads, no sneaking it into a worker. main thread only, periodt. π
π AVAILABILITY π
this function is available since SDL 3.2.0. so if you're on something older, bestie, it's giving "not found" and you gotta upgrade. π
π SEE ALSO π
(and yes, you WILL need that last one eventually β textures don't clean themselves up, that's your job π)
Simple Directmedia Layer Β· SDL 3.4.18 Β· SDL_CreateTextureFromSurface(3)
okay that's the whole page bestie, go make some textures, you're literally gonna slay π§β¨π
π¦ 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