From 079037b73990b6107e59c7f1cd971c3a1cc221d1 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Tue, 8 Dec 2015 13:21:05 +0100 Subject: SDL: Prevent graphics stretching in fullscreen when using SDL2. As a side effect we get better coordinates from mouse move events in fullscreen, i.e. we do not get actual window coordinates but something close to actual viewport coordinates. The easily noticable issue is that mouse coordinates inside black bars are outside of the viewport. For example, the x coordinate can get negative when there's a black bar at the left side. --- backends/graphics/surfacesdl/surfacesdl-graphics.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'backends') diff --git a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp index 9cb14525ee..01afc84b24 100644 --- a/backends/graphics/surfacesdl/surfacesdl-graphics.cpp +++ b/backends/graphics/surfacesdl/surfacesdl-graphics.cpp @@ -2380,7 +2380,8 @@ void SurfaceSdlGraphicsManager::deinitializeRenderer() { SDL_Surface *SurfaceSdlGraphicsManager::SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) { deinitializeRenderer(); - if (!_window->createWindow(width, height, (flags & SDL_FULLSCREEN) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)) { + const bool isFullscreen = (flags & SDL_FULLSCREEN) != 0; + if (!_window->createWindow(width, height, isFullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)) { return nullptr; } @@ -2390,6 +2391,14 @@ SDL_Surface *SurfaceSdlGraphicsManager::SDL_SetVideoMode(int width, int height, return nullptr; } + // We set the logical renderer size to the requested resolution in + // fullscreen. This assures that SDL2 adds black bars if needed to prevent + // stretching. + if (isFullscreen && SDL_RenderSetLogicalSize(_renderer, width, height) < 0) { + deinitializeRenderer(); + return nullptr; + } + _screenTexture = SDL_CreateTexture(_renderer, SDL_PIXELFORMAT_RGB565, SDL_TEXTUREACCESS_STREAMING, width, height); if (!_screenTexture) { deinitializeRenderer(); -- cgit v1.2.3