Is it possible to nest the viewport?

The following code does not work, but you get the idea.

int SCREEN_WIDTH   =  500;
int SCREEN_HEIGHT = 500;

SDL_Rect viewportRect1 = {100, 100, 300, 300};
SDL_RenderSetViewport(mRenderer, &viewportRect1);

SDL_Rect viewportRect2 = {100, 100, 100, 100};
SDL_RencerSetViewport(mRenderer, &viewportRect2);

Thanks

gg

No, I would not expect this to be possible. You’re not setting a Viewport, you’re setting the Viewport.

You can probably work around this by drawing everything you need in the black area, then setting the Viewport for the white area and drawing that stuff. Or (I haven’t tried it so I can’t be sure) you could try using a Viewport and a Cliprect together, though of course the Cliprect doesn’t affect the origin, just allows clipping.

So the viewport is not meant to be nested?

For example, I made an array that hold the position of 10 viewports
like

SDL_Rect vpArray[10] = NULL;

vpArray[0] = new SDL_Rect {0, 0, 100, 100};
vpArray[1] = new SDL_Rect {10, 10, 90, 90};
vpArray[2] = new SDL_Rect {20, 20, 80, 80};
vpArray[3] = new SDL_Rect {30, 30, 70, 70};
vpArray[4] = new SDL_Rect {40, 40, 60, 60};
vpArray[5] = new SDL_Rect {50, 50, 50, 50};
vpArray[6] = new SDL_Rect {60, 60, 40, 40};
vpArray[7] = new SDL_Rect {70, 70, 30, 30};
vpArray[8] = new SDL_Rect {80, 80, 20, 20};
vpArray[9] = new SDL_Rect {90, 90, 10, 10};

// Rendering rects
SDL_Rect fullVpRect = {0, 0, 100, 100};
for(int i = 0; i <= 9; i++)
{
SDL_RenderSetViewport(mRenderer, vpArray[i]);
SDL_SetRenderDrawColor(mRenderer, 0, 0, 0, 0xff);
if(i & 2 == 0)
SDL_SetRenderDrawColor(mRenderer, 0xff, 0xff, 0xff, 0xff);
SDL_RenderFillRect(mRenderer,&fullVpRect);
}

Something like this?

Thank you very much.

That’s more the idea, I think. You might want to clear the Viewport at the end too.

Okey. So this seems to be valid right?

Thank you very much.