SDL_SetRenderViewport(3)

πŸ’– SDL_SetRenderViewport(3) πŸ’–

okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual, where today we're learning about SDL_SetRenderViewport β€” the little function that tells your renderer where it's allowed to draw. it's giving "setting boundaries, but make it graphics" ✨


🌸 NAME 🌸

SDL_SetRenderViewport β€” set the drawing area for rendering on the current target.

like, you're basically drawing a rectangle on the screen and saying "everything happens in here now, girl." πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <SDL3/SDL_render.h>

bool SDL_SetRenderViewport(SDL_Renderer *renderer, const SDL_Rect *rect);

look at her. two params. returns a bool. no cap, she's simple and she's iconic for it. πŸ‘‘


✨ DESCRIPTION ✨

so here's the tea πŸ“: drawing will clip to this area β€” and that's separately from any clipping you're already doing with SDL_SetRenderClipRect, so don't go thinking they're the same thing, because they are NOT. two different girls, two different jobs.

and the other part? the top left of the area becomes coordinate (0, 0) for all your future drawing commands. so your whole mental map of the canvas shifts. it's a whole new origin story, literally. 🌈

the area's width and height must be >= 0. periodt. don't try to be cute with negative dimensions, she will not play with you. πŸ’€

also important: each render target has its own viewport. so this function? it sets the viewport for the current render target, not all of them. iykyk. 🧚


πŸ’… FUNCTION PARAMETERS πŸ’…

  • renderer β€” the rendering context. your main character, the one doing the rendering. 🫢
  • rect β€” the SDL_Rect structure representing the drawing area, or NULL to set the viewport to the entire target. so NULL is basically the "never mind, full screen, we're free" option. slay. πŸ’–

⭐ RETURN VALUE ⭐

returns true on success or false on failure. and if it fails? call SDL_GetError() for more information, because she will tell you what went wrong, you just gotta ask. 😭


πŸ”₯ THREAD SAFETY πŸ”₯

this function should only be called on the main thread. do not be messy. do not be chaotic. main thread only, bestie. πŸ™ˆ

🌟 AVAILABILITY 🌟

this function is available since SDL 3.2.0. so if you're on something older, she is simply not there and no amount of manifesting will summon her. πŸ’œ


πŸ‘‘ SEE ALSO πŸ‘‘


and that's the whole page, gorgeous. go forth and set your viewports with confidence. πŸ¦‹βœ¨

this has been your girl from Simple Directmedia Layer, running SDL 3.4.18, signing off with a little SDL_SetRenderViewport(3) wink and a whole lot of love. mwah. πŸ’–πŸ’…πŸŒΈ

πŸ“¦ where this page comes from