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β theSDL_Rectstructure representing the drawing area, orNULLto set the viewport to the entire target. soNULLis 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 π
SDL_GetRenderViewport(3)β the getter, the reader, the nosy bestie who asks what you set. πSDL_RenderViewportSet(3)β checks if a viewport was ever set in the first place. the vibe check function, fr fr. β
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
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms