SDL_ConvertSurface(3)
β¨ SDL_ConvertSurface β¨
okay bestie, gather round, because this one is literally the glow-up station for your surfaces π
it's from the SDL3 FUNCTIONS collection and it's called SDL_ConvertSurface β the icon, the moment, the main character of pixel format conversions π
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_surface.h>
SDL_Surface * SDL_ConvertSurface(SDL_Surface *surface, SDL_PixelFormat format);
like, that's it. two little args, one big slay π¦
π DESCRIPTION π
so the whole point of this function? it's for optimizing images so your repeat blits go zoom β‘ you convert the original, and the result gets stored as a brand new surface. then that new optimized surface can be the source for all your future blits, and those blits are just faster. it's giving β¨performanceβ¨ and honestly we're obsessed.
quick side quest: if you're converting to an indexed surface and you wanna map colors to a palette, you should hit up SDL_ConvertSurfaceAndColorspace() instead, bestie. this one is not that one. no cap π
and one more lil thing that's lowkey important β if the original surface has alternate images, the new surface will have a reference to them as well π«Ά so nothing gets lost in the conversion, we love a faithful copy.
π FUNCTION PARAMETERS π
surfaceβ the existingSDL_Surfacestructure you wanna convert, i.e. the one getting the makeover πformatβ the new pixel format. this is the vibe you're converting into β¨
β RETURN VALUE β
it returns the new SDL_Surface structure it just created π₯³ or NULL if it failed, and in that case please call SDL_GetError() for the deets β she will tell you what went wrong, fr fr π
π THREAD SAFETY π
this one is actually flexible, periodt. you can call it on different threads, as long as you're using different surfaces. so like, don't be chaotic and share one surface across threads, but different surfaces on different threads? go off π
π¦ AVAILABILITY π¦
available since SDL 3.2.0 β so if you're on anything older, this function is not gonna manifest for you, sorry bestie π
π SEE ALSO π
iykyk, go read those next π
that's the whole page, and no detail got left on read π«Ά brought to you by the fine folks at Simple Directmedia Layer, running SDL 3.4.18 β mwah, slay, bye π β¨
π¦ 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