SDL_FOURCC(3)

πŸ’– SDL_FOURCC πŸ’–

okay bestie, welcome to SDL_FOURCC β€” it's a macro from the SDL3 FUNCTIONS lineup (yes that's the manual section, we're fancy here), and it's literally just: define a four character code as a Uint32. that's the whole vibe. four lil characters in, one big number out. slay. πŸŽ€


✨ SYNOPSIS ✨

include the header first, always:

#include <SDL3/SDL_stdinc.h>

#define SDL_FOURCC(A, B, C, D) \
    ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
     (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
     (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
     (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))

look at her. four casts, four shifts, three ORs. she's packing those bytes like a girl packing a carry-on. πŸ’…


🌸 MACRO PARAMETERS 🌸

  • A β€” the first ASCII character. she goes in the lowest spot (shift 0), first in line, main character energy πŸ‘‘
  • B β€” the second ASCII character.
  • C β€” the third ASCII character.
  • D β€” the fourth ASCII character. she gets the highest spot (shift 24), living her best life at the top πŸ¦‹

⭐ RETURN VALUE ⭐

returns the four characters converted into a Uint32, one character per byte. so yeah, all four of them squeezed into one number, each one minding her own byte. iconic honestly. ✨


🧚 THREAD SAFETY 🧚

it is safe to call this macro from any thread. no drama, no locks, no fighting. everyone can use her at the same time, no cap. 🫢


🌈 AVAILABILITY 🌈

this macro has been available since SDL 3.2.0. so if you're on something older… babe. 😭

reminder bestie: this is a macro, not a function β€” the compiler just yeets the expression in wherever you write it. the exact expansion above is the one and only, don't go inventing your own. πŸ™ˆ

and that's the whole page!! no SEE ALSO, no bugs, no authors listed β€” just pure four-character-code excellence. πŸ’œ

written up by Simple Directmedia Layer, version SDL 3.4.18, dated SDL_FOURCC(3). mwah. πŸ’…πŸŒΈ

πŸ“¦ where this page comes from