Is it possible to nest the viewport to create the Rect tree??


I’ve been working on my own project to create a (super) small game engine for a while now. I’d like to ask if anyone know how to make a “nested” scrollable rect or texture?

The idea is similar to <div> tag on HTML where you can set the overflow attribute to :auto then the scroll bar appears on the right side of the div for scrolling things up and down.

I’ve made my own version trying to resemble the idea with SDL_RenderSetViewport(), but it seems unable to be “nested” Every time the function is called. The origin did not shift to the new coordinate.

For example,

const int SCREEN_WIDTH = 500, SCREEN_HEIGHT = 500;
mViewportRect = {100, 100, 400, 400};
SDL_RecderSetViewport(mRenderer, &mViewportRect);

Viewport starts at 100, 100, ends at 400, 400
After this all textures origin coordinate shifts to 100, 100

mViewportRect2 = {50, 50, 250, 250};
SDL_RecderSetViewport(mRenderer, &mViewportRect2);

The new origin (0, 0) suppose to shift to 150, 150, but everything drawn here still starts at the top left, (cord 50, 50)

Thank you very much for your advice.