Is there a reason to use viewports?

I’m trying to understand what the point of setting a viewport is and I haven’t found any decent explanation for it. The problem I have is that this code:

// Using a viewport
SDL_RenderSetViewport(&renderer, &viewportRect);
SDL_RenderCopy(&renderer, &texture, nullptr, nullptr);

produces the exact same result as this code:

// Using a destination rect
SDL_RenderCopy(&renderer, &texture, nullptr, &viewportRect);

The only difference I can see is if you try to render something outside of the viewport it isn’t rendered. So what am I missing about this?

Custom viewports let you confine and scale your drawing to one area of the screen without your drawing code having to know about it or care if you don’t want it to.

So one possible use would be if you had an in-game level editor, maybe with one area on screen that’s a level viewer and the rest is editor widgets. When you draw the level viewer, set a custom viewport and then just call your normal level rendering code. Everything will be contained within that viewport and scaled to fit.

Not rendering anything drawn outside the viewport is exactly the point, and exactly the advantage.

One nice use I’ve found for them is marquis-style scrolling text. Rather than wrap your text render function in another function that can draw part of a letter/line, or rather than try to draw only part of the rendered image, just throw a viewport in there and you’re good to go. I used this for an in-game window that can have an arbitrary number of lines of text in it.

The same concept applies for minimaps and stuff too. If you have an icon that’s on the edge of the minimap’s range, it’ll automatically be truncated if you define that boundary with a viewport.