- // Clear the screen to avoid garbage in unreachable areas after we
- // reset the coordinate system
- SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
- SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
- SDL_RenderClear(renderer);
- SDL_RenderPresent(renderer);
- SDL_RenderClear(renderer);
-
- // This doesn't really do what we want, as it sales the area to fill
- // the screen, but seems to be the only way to reset the coordinate
- // system and it's "close enough" to what we want, see:
- // https://bugzilla.libsdl.org/show_bug.cgi?id=2179
- SDL_RenderSetLogicalSize(renderer, SCREEN_WIDTH, SCREEN_HEIGHT);
+ // Clear the screen to avoid garbage in unreachable areas after we
+ // reset the coordinate system
+ SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
+ SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
+ SDL_RenderClear(renderer);
+ SDL_RenderPresent(renderer);
+ SDL_RenderClear(renderer);
+
+ viewport.x = std::max(0, (screen_size.width - new_size.width) / 2);
+ viewport.y = std::max(0, (screen_size.height - new_size.height) / 2);
+ viewport.w = std::min(new_size.width, screen_size.width);
+ viewport.h = std::min(new_size.height, screen_size.height);
+
+ SDL_RenderSetScale(renderer, 1.0f, 1.0f);
+ SDL_RenderSetViewport(renderer, &viewport);
+ SDL_RenderSetScale(renderer, g_config->magnification, g_config->magnification);
+ }