SDL_SetRenderScale(3)

πŸ’… SDL_SetRenderScale πŸ’…

okay so bestie, welcome to the SDL3 FUNCTIONS corner of the manual β€” this one's all about SDL_SetRenderScale, and it's genuinely iconic for anyone doing resolution-independent drawing. sit down, grab a strawberry, let's go πŸ“


✨ NAME ✨

SDL_SetRenderScale β€” set the drawing scale for rendering on the current target. that's the whole vibe. πŸ’–


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_render.h>

bool SDL_SetRenderScale(SDL_Renderer *renderer, float scaleX, float scaleY);

like, look at that signature. she's clean, she's simple, she takes exactly three things and returns a bool. no cap. πŸ‘‘


πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea: the drawing coordinates get scaled by the x and y scaling factors before the renderer even uses them. the way that works means you get resolution independent drawing with a single coordinate system β€” one coordinate system, every resolution, main character energy fr fr. ✨

if this ends up causing scaling or subpixel drawing in the rendering backend, it's handled using the appropriate quality hints. and ngl, for best results you want to use integer scaling factors β€” that's the move, trust. πŸ’―

also important: each render target has its own scale. this function sets the scale for the current render target, not all of them, not some of them, just the current one. iykyk. πŸŽ€


🧚 FUNCTION PARAMETERS 🧚

  • renderer β€” the rendering context. your little guy. the whole setup lives here. πŸ’œ
  • scaleX β€” the horizontal scaling factor. left-to-right glow-up. 🌈
  • scaleY β€” the vertical scaling factor. up-and-down glow-up. 🌸

⭐ RETURN VALUE ⭐

returns true on success, or false on failure. and if it's a false, do not just sit there wondering bestie β€” call SDL_GetError() for more information. she will tell you what went wrong. 😭


πŸ”₯ THREAD SAFETY πŸ”₯

this function should only be called on the main thread. no side quests, no background threads, no "but what if"β€” main thread only. periodt. πŸ’…

πŸŽ€ AVAILABILITY πŸŽ€

this function is available since SDL 3.2.0. if you're on something older, sorry babe, she's not there yet. πŸ™ˆ


πŸ‘‘ SEE ALSO πŸ‘‘


and that's the page!! πŸ’– source is Simple Directmedia Layer, version SDL 3.4.18, and honestly? slay. go scale something gorgeously, bestie β€” integer factors only, main thread only, mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from