SDL_WriteSurfacePixel(3)

✨ SDL_WriteSurfacePixel ✨

okay bestie, welcome to the SDL_WriteSurfacePixel(3) page β€” part of the SDL3 FUNCTIONS collection, obviously πŸ’…


🌸 NAME 🌸

SDL_WriteSurfacePixel β€” Writes a single pixel to a surface.

like... one pixel. a single lil guy. that's the whole job πŸŽ€


✨ SYNOPSIS ✨

#include <SDL3/SDL_surface.h>

bool SDL_WriteSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 r, Uint8 g, Uint8 b, Uint8 a);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so here's the vibe: this function is prioritizing correctness over speed. it's not trying to be fast, it's trying to be right. so it's giving very much unit tests energy β€” but not intended for use in a game engine, bestie, please don't ship it in your render loop 😭

and lowkey important: like SDL_MapRGBA, this uses the entire 0..255 range when converting color components from pixel formats with less than 8 bits per RGB component. so no weird half-range shenanigans, it's full range, no cap ✨


πŸ’– FUNCTION PARAMETERS πŸ’–

  • surface β€” the surface to write to. your canvas, your moment, your main character 🫢
  • x β€” the horizontal coordinate, 0 <= x < width. stay in bounds pls πŸ’€
  • y β€” the vertical coordinate, 0 <= y < height. same energy, vertical edition 🌈
  • r β€” the red channel value, 0-255. ❀️
  • g β€” the green channel value, 0-255. πŸ’š
  • b β€” the blue channel value, 0-255. πŸ’™
  • a β€” the alpha channel value, 0-255. πŸ‘»

⭐ RETURN VALUE ⭐

Returns true on success or false on failure πŸ₯² β€” and if it fails, call SDL_GetError() for more information. she will tell you what went wrong, periodt.


🧚 THREAD SAFETY 🧚

This function can be called on different threads with different surfaces. so like, go off, parallelize β€” just keep your surfaces separate, iykyk πŸ‘‘


🌸 AVAILABILITY 🌸

This function is available since SDL 3.2.0. so if you're on anything older... girl. upgrade πŸ’…


no cap: it's correctness-first on purpose. don't be out here using it in a game engine and then acting surprised, bestie πŸ™ˆ

Simple Directmedia Layer Β· SDL 3.4.18 Β· SDL_WriteSurfacePixel(3)

and that's the whole page, mwah πŸ’– tysm for reading, go write exactly one pixel and slay πŸŽ€πŸ¦‹βœ¨

πŸ“¦ where this page comes from