SDL_Surface(3type)
π SDL_Surface β bestie, it's the pixel girly π
okay so you know how a manual page header is like a little name tag? this one says SDL_Surface(3type) and it lives in the SDL3 DATATYPES section, and honestly? she's the blueprint. the moment. the canvas. periodt. π
β¨ NAME β¨
SDL_Surface β a collection of pixels used in software blitting.
no cap, that's it. a whole vibe made of pixels. π
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_surface.h>
struct SDL_Surface
{
SDL_SurfaceFlags flags; /**< The flags of the surface, read-only */
SDL_PixelFormat format; /**< The format of the surface, read-only */
int w; /**< The width of the surface, read-only. */
int h; /**< The height of the surface, read-only. */
int pitch; /**< The distance in bytes between rows of pixels, read-only */
void *pixels; /**< A pointer to the pixels of the surface, the pixels are writeable if non-NULL */
int refcount; /**< Application reference count, used when freeing surface */
void *reserved; /**< Reserved for internal use */
};
look at her. an icon. π
π¦ DESCRIPTION π¦
okay so the pixels are laid out in memory in rows, and the top row comes first. very top-down, very organized, we respect it. each row takes up an amount of memory given by the pitch (which, in non-SDL APIs, people sometimes call the row stride β same thing, different name, iykyk).
inside each row, the pixels go left to right until you hit the w (width). each pixel eats up however many bits its format says it should, and for most formats that's one or more whole bytes per pixel β except in some indexed formats, where instead multiple pixels get packed into each single byte (sneaky!! π), plus a byte order that the format dictates. once all the pixels are encoded, whatever bytes are left over to reach the pitch are just padding to hit a desired alignment, and those contents are undefined. so like, don't read them, bestie. undefined means undefined. π
when a surface is holding YUV format data, the planes are assumed to be contiguous with no padding between them. example, since examples are everything: a 32x32 surface in NV12 format with a pitch of 32 would be 32x32 bytes of Y plane followed by 32x16 bytes of UV plane. math-ing. π₯
and when a surface is holding MJPG format data? then pixels points at the compressed JPEG image, and pitch is the length of that data. compressed girlies stay compressed. β¨
π AVAILABILITY π
this struct has been available since SDL 3.2.0. she's not new new, but she's not ancient either. π«Ά
β SEE ALSO β
SDL_CreateSurface(3)β go make one πSDL_DestroySurface(3)β and go free her when you're done, we do not leak in this house π
heads up bestie: reserved is for internal use only, so like. hands off. π
okay that's the whole page, you ate, I ate, we all ate. this was the Simple Directmedia Layer manual, SDL 3.4.18 era, page SDL_Surface(3type) β mwah, go blit something cute. ππ§πΈ
π¦ 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