SDL_FillRect(3)

πŸ’– SDL_FillRect(3) πŸ’–

okay bestie, welcome to the SDL API Reference β€” this is the manual page for SDL_FillRect, and it's literally the "just paint the thing already" function. no cap, it's iconic. 🎨✨


🌸 NAME 🌸

SDL_FillRect β€” this function performs a fast fill of the given rectangle with some color. that's it, that's the whole job, and it does it beautifully. πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

#include "SDL.h"

int SDL_FillRect(SDL_Surface *dst, SDL_Rect *dstrect, Uint32 color);

like, three args, super chill, no drama. 🫢


✨ DESCRIPTION ✨

So here's the tea πŸ“: this function performs a fast fill of the given rectangle with color. and when I say fast, I mean it's giving main character speed. If dstrect is NULL, the whole surface will be filled with color β€” like, the entire thing, every last pixel, gone, filled, slay. πŸ‘‘

Now, the color should be a pixel of the format used by the surface, and can be generated by the SDL_MapRGB or SDL_MapRGBA functions. that's the move, that's how you get a color that actually makes sense to the surface. 🌈

πŸ’€ important caveat bestie: if the color value contains an alpha value, then the destination is simply "filled" with that alpha information β€” no blending takes place. not a single blend. zero blending. it does not mix, it does not merge, it just stamps that alpha in there and moves on. know that before you come crying to me about your transparency. 😭

And one more thing, the way that clipping works here is lowkey important: if there is a clip rectangle set on the destination (set via SDL_SetClipRect), then this function will clip based on the intersection of the clip rectangle and the dstrect rectangle β€” and the dstrect rectangle will be modified to represent the area actually filled. so yeah, your rect struct can get rewritten under you. it's not a bug, it's a feature, periodt. πŸŽ€


πŸ’œ RETURN VALUE πŸ’œ

  • 0 β€” success, we ate, everything is fine πŸ’–
  • -1 β€” error, it's giving broken, go check your stuff πŸ™ˆ

🌟 SEE ALSO 🌟

  • SDL_MapRGB
  • SDL_MapRGBA
  • SDL_BlitSurface
  • SDL_Rect

go read those too, iykyk, they're all part of the same friend group. 🧚


signing off from the SDL crew, Tuesday 11 September 2001 at 23:01, source SDL, page SDL_FillRect(3) β€” mwah, take care of your surfaces bestie, and remember: fill responsibly πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from