SDL_DEFINE_PIXELFORMAT(3)
π SDL_DEFINE_PIXELFORMAT π
okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual, this one's SDL_DEFINE_PIXELFORMAT(3) and it's literally the macro that lets you cook up your own non-FourCC pixel formats. custom pixel formats?? in THIS economy?? yes queen. π
β¨ NAME β¨
SDL_DEFINE_PIXELFORMAT β a macro for defining custom non-FourCC pixel formats. that's it, that's the whole vibe. π¦
β¨ SYNOPSIS β¨
#include <SDL3/SDL_pixels.h>
#define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \
((1 << 28) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \
((bits) << 8) | ((bytes) << 0))
like look at those bit shifts. she's doing MATH. bit manipulation main character energy fr fr π
β¨ DESCRIPTION β¨
so here's the tea π β when you wanna define one of these, you're basically smooshing all your format info into one single number using bitwise magic. for example, defining SDL_PIXELFORMAT_RGBA8888 looks like this:
SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_RGBA, SDL_PACKEDLAYOUT_8888, 32, 4)
see how every single parameter gets its own little slice of the number? that's the whole point bestie. one integer, all the deets. iconic. β¨
β¨ MACRO PARAMETERS β¨
typeβ the type of your new format. probably aSDL_PixelTypevalue. πorderβ the order of your new format. probably aSDL_BitmapOrder,SDL_PackedOrder, orSDL_ArrayOrdervalue. πlayoutβ the layout of your new format. probably anSDL_PackedLayoutvalue, or just zero. π¦bitsβ how many bits per pixel your new format has. π₯bytesβ how many bytes per pixel your new format has. π
β¨ RETURN VALUE β¨
returns a format value in the style of SDL_PixelFormat. slay. π
β¨ THREAD SAFETY β¨
it is safe to call this macro from any thread. go off, thread queen, no locks needed, no cap. π§
β¨ AVAILABILITY β¨
this macro is available since SDL 3.2.0. so if you're on something older... not me finding out the hard way π
lowkey reminder: this is a macro, so it's all compile-time bit-shifting, no function call, no drama. but fr fr keep your parameters legit or your format value will be giving chaos. π
that's the whole page bestie, you ate it, now go define some pixel formats and be the main character of your own framebuffer π
πΈ mwah, this was brought to you by Simple Directmedia Layer, version SDL 3.4.18, and this lil SDL_DEFINE_PIXELFORMAT(3) manual page. bye pookie π«Άπ
π¦ 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