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 a SDL_PixelType value. πŸ‘‘
  • order β€” the order of your new format. probably a SDL_BitmapOrder, SDL_PackedOrder, or SDL_ArrayOrder value. πŸŽ€
  • layout β€” the layout of your new format. probably an SDL_PackedLayout value, 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