Window as a mask

Hello people,

How can I use the window as a mask for cropping everything that’s not on the screen?

this Category is about coding on libSDL, not with. That would be

Are you looking for ?


I already found the solution:

SDL_Rect resolution = {0, 0, window_width, window_height};

SDL_RenderSetViewport(renderer, &resolution);

I don’t see how that helps. I think you are looking for a plain source rect, but that was so simple that I didn’t suggest that.

But maybe someone else gets it =)

I mean I have a Display and on that my windows are appearing.
What are you trying to do?
Something like this?


This way he wil show only whats inside the window, but the game stills renders whats outside

SDL_RenderSetViewport blocks the renderer from rendering whats outside

I maybe totally wrong, but isn’t rendering what the user isn’t seeing a waste of performance?

Well, I don’t get the point. Here is a source rect animation I set up.


If I understand the user correctly, he/she wants to use clipping to only render what’s inside the viewport, which can be done with the help of the SDL_RenderSetViewport() function.
Your solution only clips textures, which in this case isn’t what the user wants.

Maybe a SDL Developer enlightens me with insights, I am in the mindset, that the viewport is mainly for splitting the window in areas. Like stated here:
and here:


Well, I may be wrong so I’ll just leave it to someone else to answer.