SDL_CreateSurfacePalette(3)
π SDL_CreateSurfacePalette(3) π
okay bestie, welcome to the SDL3 FUNCTIONS section of the manual, and today's main character is SDL_CreateSurfacePalette β she makes palettes and handcuffs them to your surface. it's giving matchmaker, honestly. π
β¨ NAME β¨
SDL_CreateSurfacePalette</purpose> β create a palette and associate it with a surface. yeah. that's the whole job. iconic behavior. π
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_surface.h>
SDL_Palette * SDL_CreateSurfacePalette(SDL_Surface *surface);
π¦ DESCRIPTION π¦
so here's the tea, bestie. this function creates a palette that's compatible with the surface you hand it. then it gives that palette right back to you so you can go in and mess with it however you want, and the surface will automatically start using the new palette in all its future operations. it justβ¦ does that. no extra steps. slay. π
and the best part?? you do not need to destroy the returned palette. do not free it yourself. it gets freed when its reference count hits 0, which usually happens when the surface gets destroyed. so like, it's self-cleaning. we love a low-maintenance queen. π§
now, the palette's initial contents depend on what kind of surface you're working with:
- Bitmap surfaces β those are the ones with format
SDL_PIXELFORMAT_INDEX1LSBorSDL_PIXELFORMAT_INDEX1MSBβ get their palette initialized with0as white and1as black. yes, that's backwards from what your brain expects. no, it is not a typo. it's just how it is. π - Other surfaces get a palette initialized with white in every single entry. all of them. every last one. white as far as the eye can see. ποΈ
oh and also β if you call this on a surface that already has a palette? no drama, a brand new palette gets created to replace the old one. out with the old, in with the new. it's giving glow-up. β¨
π FUNCTION PARAMETERS π
surfaceβ theSDL_Surfacestructure to update. that's your girl. hand her over. π«Ά
π₯ RETURN VALUE π₯
returns a shiny new SDL_Palette structure on success, or NULL on failure β like, for example, if the surface didn't have an index format. π
if you gotNULLback, go callSDL_GetError()for more info. she will tell you what went wrong. always read the error, bestie. always. π
π THREAD SAFETY π
this function can be called on different threads with different surfaces. so parallel palette-ing is fully on the table. just keep the surfaces separate and you're golden. no cap. β
π AVAILABILITY π
this function has been available since SDL 3.2.0. if you're on anything older, she simply does not exist yet. sorry babe. π
π SEE ALSO π
SDL_SetPaletteColors(3)β the next chapter of your palette journey, fr fr. go read it. π
Simple Directmedia Layer Β· SDL 3.4.18 Β· SDL_CreateSurfacePalette(3)
and that's the whole page, bestie!! π you now know everything this manual knows about making palettes. go forth and be palette-pilled. mwah. ππ¦πΈ
π¦ 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