I'm very confused about the SDL2 viewport, I did some googling to find out how to implement it but people keep mentioning things like "world coordinates" which I don't have in my game.
Question : Do I even need world coordinates for the SDL2 viewport to work? If yes, how do I implement it?
I've currently got a problem where if my viewport goes too much to the right or down, the entire window will become green, kinda like if it stopped rendering all my sprites.
Here's a GIF to show you what I mean :
As you can see, whenever I go too much to the right or down the entire screen goes green.
I thought this maybe was beause of me not using world coordinates, but I have no idea I'm just guessing stuff at this point...
My current codes for moving the viewport, drawing it, and such looks like this :
Creating the viewport / camera :
Camera::Camera(Uint16 x, Uint16 y, Uint16 w, Uint16 h)
{
// Sets up the viewport positions and sizes
viewport.x = x;
viewport.y = y;
viewport.w = w;
viewport.h = h;
// Sets the viewport so that SDL uses it
SDL_RenderSetViewport(Window::GetRenderer(), &viewport);
}
Drawing the viewport : (gets called every frame)
void Camera::DrawCameraViewport()
{
SDL_RenderSetViewport(Window::GetRenderer(), &viewport);
}
I set the cameras position during runtime like this :
void Camera::SetCameraPosition(int _x, int _y)
{
viewport.x = _x;
viewport.y = _y;
}
And here's how I set the cameras position using the above function :
Note : Sorry, the line became giantic...
camera->SetCameraPosition(
-SpriteManager::GetPlayerSprite()->GetPosition().x
+ Window::GetWindowMiddlePoint().x
- SpriteManager::GetPlayerSprite()->GetMiddlePoint().x
, -SpriteManager::GetPlayerSprite()->GetPosition().y
+ Window::GetWindowMiddlePoint().y
- SpriteManager::GetPlayerSprite()->GetMiddlePoint().y);
Question : Am I implementing the viewport correctly?