I want to understand how do the coordinates of a pixel change when the window size is changed (in my case the size is changed to fit the entire screen). I am trying to achieve this by writing a common code for both cases (i.e. fullscreen and not fullscreen).
From what I have seen, the conversion from one window size to another doesn't just depend on a multiplicative factor.
The fullscreen case (blue arrows are just for indicating the gap)
I programmed the spaceship to be at the left-bottom corner of the window in the not fullscreen case and when I change the size to fullscreen there is a gap between the spaceship and the bottom. How do I keep the spaceship in the corner even in the fullscreen mode?
Here is code for creating the window:
window = SDL_CreateWindow(title, xpos, ypos, screenWidth / 2,
screenHeight / 2, flags);
if (window) {
std::cout << "Window created!" << std::endl;
} else {
std::cout << "Error: " << SDL_GetError()
<< std::endl; // SDL_GetError() specifies the error
}
for toggling fullscreen:
void ToggleFullscreen(SDL_Window *Window) {
Uint32 FullscreenFlag = SDL_WINDOW_FULLSCREEN;
bool IsFullscreen = SDL_GetWindowFlags(Window) & FullscreenFlag;
SDL_SetWindowFullscreen(Window, IsFullscreen ? 0 : FullscreenFlag);
SDL_ShowCursor(IsFullscreen);
}
And the code for positioning the spaceship (the second and third arguments are the x and y coordinates respectively):
spaceship = new GameObject("Assets/Spaceship.png", 0, (screenHeight * 9) / 20, 0);
The definition of the GameObject constructor being used above (the TextureManager just returns a SDL_Texture of the image):
GameObject::GameObject(const char *textureSheet, int x, int y, bool isAnimated)
: xpos{x}, ypos{y} {
objTexture = TextureManager::LoadTexture(textureSheet);
srcRect.x = 0;
srcRect.y = 0;
srcRect.w = 32;
srcRect.h = 32;
destRect.x = xpos;
destRect.y = ypos;
destRect.h = (Game::screenHeight) / 20;
destRect.w = (Game::screenHeight) / 20;
}