SDL_CreateSurfaceFrom(3)
๐ SDL_CreateSurfaceFrom(3) ๐
okay bestie, so this is a page from the SDL3 FUNCTIONS manual, and today's main character is SDL_CreateSurfaceFrom โ the function that hands you a brand-new surface built around pixel data you already have. no copy, no drama, just vibes ๐ฆ
โจ NAME โจ
SDL_CreateSurfaceFrom โ allocate a new surface with a specific pixel format and existing pixel data. it's giving "i brought my own pixels, you bring the surface" ๐
๐ธ SYNOPSIS ๐ธ
#include <SDL3/SDL_surface.h>
SDL_Surface * SDL_CreateSurfaceFrom(int width, int height, SDL_PixelFormat format, void *pixels, int pitch);
๐ DESCRIPTION ๐
okay so here's the tea, and it's important tea: no copy is made of the pixel data. like, none. zero. the surface just points at your pixels. which means the pixel data is not managed automatically โ you have to free the surface before you free the pixel data. do it in that order, bestie, or you're gonna have a bad time ๐ญ
pitch is the offset in bytes from one row of pixels to the next. so like, width*4 for SDL_PIXELFORMAT_RGBA8888. that's the math, no cap ๐งฎ
and the fun part: you may pass NULL for pixels and 0 for pitch to create a surface that you'll fill in with valid values later. build-a-bear but for surfaces, lowkey iconic ๐งธ
๐ซถ FUNCTION PARAMETERS ๐ซถ
widthโ the width of the surface. yeah. that one. ๐heightโ the height of the surface. the other one. ๐formatโ theSDL_PixelFormatfor the new surface's pixel format. pick your aesthetic โจpixelsโ a pointer to existing pixel data. your pixels. your problem (affectionately) ๐pitchโ the number of bytes between each row, including padding. padding is real and it counts ๐
โญ RETURN VALUE โญ
returns the new SDL_Surface structure that is created, or NULL on failure. if you get NULL, don't panic โ just call SDL_GetError() for more information and it'll spill the whole story ๐
๐ฅ THREAD SAFETY ๐ฅ
it is safe to call this function from any thread. yes, any thread. multitask slay ๐
๐ AVAILABILITY ๐
this function is available since SDL 3.2.0. if your SDL is older than that, it's simply not invited to the party ๐
๐ SEE ALSO ๐
and that's the whole page, bestie โ go forth and make surfaces ๐ฆ
with love from the Simple Directmedia Layer girlies, SDL 3.4.18 era, SDL_CreateSurfaceFrom(3) forever ๐
โจ
๐ฆ 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