SDL_CreatePalette(3)

✨ NAME ✨

SDL_CreatePalette β€” bestie, this is the one that makes you a whole new palette structure with however many color entries you want πŸ’– (yes it's an SDL3 function, and yes we're gonna get you through it)


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_pixels.h>

SDL_Palette * SDL_CreatePalette(int ncolors);

πŸŽ€ DESCRIPTION πŸŽ€

Okay so real talk: this gives you a brand new palette. And the vibe of the entries when you first get it? Every single one of them is initialized to white. All of them. Every color entry. White. 🀍


πŸ¦‹ FUNCTION PARAMETERS πŸ¦‹

  • ncolors β€” this is literally just how many color entries you want your palette to have. That's the number. That's the whole job. πŸ’…

πŸ’œ RETURN VALUE πŸ’œ

On success you get a shiny new SDL_Palette structure back. 🫢

On failure β€” like if there legit wasn't enough memory for it 😭 β€” you get NULL. And when that happens, call SDL_GetError() to find out what went wrong, because it will tell you.


🌈 THREAD SAFETY 🌈

It is safe to call this function from any thread. Every thread. No gatekeeping. Go off, concurrent bestie πŸ‘‘


⭐ AVAILABILITY ⭐

This function has been available since SDL 3.2.0. Not new new, but not ancient either. Iconic behavior. ✨


πŸ“ SEE ALSO πŸ“

fr fr, go read SDL_DestroyPalette(3) too β€” you gotta clean up after yourself, bestie, no cap πŸ™ˆ

Okay that's the whole page!! Simple Directmedia Layer is the source, we're rolling on SDL 3.4.18, and this SDL_CreatePalette(3) moment is over β€” go make something gorgeous with your palette, mwah πŸ’–πŸŽ€πŸ§š

πŸ“¦ where this page comes from