SDL_CreateSurface(3)

✨ SDL_CreateSurface β€” it's giving brand new surface πŸ’–

okay bestie, this one lives in the SDL3 FUNCTIONS section of the manual, so you already know it's a glow-up moment. It's SDL_CreateSurface(3), and it's here to hand you a shiny fresh surface with exactly the pixel format you asked for. πŸ¦‹


🌸 NAME 🌸

SDL_CreateSurface β€” Allocate a new surface with a specific pixel format.


🌈 SYNOPSIS 🌈

#include <SDL3/SDL_surface.h>

SDL_Surface * SDL_CreateSurface(int width, int height, SDL_PixelFormat format);

πŸ’… DESCRIPTION πŸ’…

So here's the tea: the pixels of the new surface are initialized to zero. That's it, that's the whole vibe β€” clean slate, all zeroes, no drama. ✨


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • width β€” the width of the surface. like, how wide bestie.
  • height β€” the height of the surface. the vertical situation.
  • format β€” the SDL_PixelFormat for the new surface's pixel format. this is the whole lewk, don't skip it. πŸ’–

🫢 RETURN VALUE 🫢

Returns the new SDL_Surface structure that is created β€” slay β€” or NULL on failure. 😭 If you get NULL, do not panic, just call SDL_GetError() for more information and it'll tell you what went wrong.

ngl a NULL here is a whole mood ruiner, so always check fr fr.

🧚 THREAD SAFETY 🧚

It is safe to call this function from any thread. periodt. every thread can get one, no gatekeeping. πŸ‘‘


⭐ AVAILABILITY ⭐

This function is available since SDL 3.2.0. so if you're on anything older… it's not giving, sorry bestie. πŸ’€


πŸ’œ SEE ALSO πŸ’œ

iykyk: you made it, so eventually you gotta SDL_DestroySurface it. don't leave your surfaces orphaned, that's not main character energy. 🌸

okay that's the whole page!! πŸ˜­πŸ’– this was Simple Directmedia Layer business, brought to you by SDL 3.4.18 β€” yes, that's the version, and the docs date along with it. go make something iconic with your zeroed-out little surface, bestie. πŸŽ€πŸ¦‹βœ¨

πŸ“¦ where this page comes from