I have a large viewport on the right side of the screen (here "Layers"), and I render a rectangle inside that viewport ("actorRect"). Then, I set viewport to actorRect and try to SDL_RenderDrawLines a stickman in the rectangle.
The stickman gets rendered way over on the left side of the screen, as if it were using the plain x,y coordinates of the ActorRect.
In the above picture, I circled my stickman and drew an arrow pointing at actorRect. (actorRect is only green here so I can tell where it is. Later it's gonna be some other color, or like an outline or something, idk yet).
I want that stickman to render inside that rectangle.
Here's a code snippet:
//vector mStickmanIcon = {/*...a bunch of points...*/};
SDL_RenderSetViewport(gRenderer, &Layers);
SDL_SetRenderDrawColor(gRenderer, 200,250,165,255);
SDL_RenderFillRect(gRenderer, &actorRect);
SDL_RenderSetViewport(gRenderer, &actorRect);
SDL_SetRenderDrawColor(gRenderer, 0,0,0,255);
SDL_RenderDrawLines(gRenderer, mStickmanIcon.data(), mStickmanIcon.size());
What do you guys think? Any advice? Please limit answers to SDL2. I'm not using OpenGL.
I'm also interested in simple ways to offset vectors of SDL_Point so that I can do away with actorRect altogether, but I figure I'll probably want to nest viewports again later, so that's the question I'm asking.
ETA: I added the following code to find out the locations of those items on screen:
SDL_Rect myRect;
SDL_RenderGetViewport(gRenderer, &myRect);
printf("Viewport h,w,x,y: %i,%i,%i,%i\n", myRect.h,myRect.w,myRect.x,myRect.y);
for(int i = 0; i < mStickmanIcon.size(); i++)
{
printf("stickman i,x,y: %i,%i,%i\n", i,mStickmanIcon.data()[i].x, mStickmanIcon.data()[i].y);
}
Here's the output:
stickman i,x,y: 0,5,15
stickman i,x,y: 1,8,12
stickman i,x,y: 2,11,15
stickman i,x,y: 3,8,12
stickman i,x,y: 4,8,9
stickman i,x,y: 5,5,9
stickman i,x,y: 6,11,9
stickman i,x,y: 7,8,9
stickman i,x,y: 8,8,6
stickman i,x,y: 9,7,6
stickman i,x,y: 10,5,4
stickman i,x,y: 11,5,2
stickman i,x,y: 12,7,0
stickman i,x,y: 13,8,0
stickman i,x,y: 14,11,2
stickman i,x,y: 15,11,4
stickman i,x,y: 16,9,6
Viewport h,w,x,y: 16,16,247,119
Looking through SDL, it doesn't seem like it's easily possible to nest viewports. You're in luck, though - since you've already got an existing viewport, as well as a rectangle you've just drawn, why not use that rectangle's coordinates as the base for your new viewport?
//vector mStickmanIcon = {/*...a bunch of points...*/};
SDL_RenderSetViewport(gRenderer, &Layers);
SDL_SetRenderDrawColor(gRenderer, 200,250,165,255);
SDL_RenderFillRect(gRenderer, &actorRect);
SDL_Rect actorView;
actorView.x = Layers.x + actorRect.x;
actorView.y = Layers.y + actorRect.y;
actorView.w = actorRect.w;
actorView.h = actorRect.h;
SDL_RenderSetViewport(gRenderer, &actorView);
SDL_SetRenderDrawColor(gRenderer, 0,0,0,255);
SDL_RenderDrawLines(gRenderer, mStickmanIcon.data(), mStickmanIcon.size());