From 0674f2d28dd3539f09f60e40d10d45e683e5aca4 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Tue, 25 Mar 2014 00:21:10 +0100 Subject: [PATCH] Set the viewport size and resolution on resoultion change. --- src/sdlmain.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/sdlmain.cpp b/src/sdlmain.cpp index 5f3601e..eaa6ae7 100644 --- a/src/sdlmain.cpp +++ b/src/sdlmain.cpp @@ -23,6 +23,7 @@ #include "sizeratio.hpp" #include #include +#include namespace cloonel { struct SDLMain::LocalData { @@ -102,6 +103,25 @@ namespace cloonel { ///------------------------------------------------------------------------ void SDLMain::SetResolution (ushort2 parRes) { m_localData->sizeratio.UpdateResolution(static_cast(parRes)); + { + SDL_Renderer* const renderer = GetRenderer(); + assert(renderer); + const int retVal = SDL_RenderSetLogicalSize(renderer, parRes.x(), parRes.y()); + if (retVal) { + std::ostringstream oss; + oss << "Error setting logical size to renderer to " << parRes.x() << "x" << parRes.y() << ": " << SDL_GetError(); + throw std::runtime_error(oss.str()); + } + + const SDL_Rect area = { 0, 0, parRes.x(), parRes.y() }; + const int retValViewport = SDL_RenderSetViewport(renderer, &area); + if (retValViewport) { + std::ostringstream oss; + oss << "Error setting viewport to renderer to " << parRes.x() << "x" << parRes.y() << ": " << SDL_GetError(); + throw std::runtime_error(oss.str()); + } + } + for (auto currNotifiable : m_localData->resChangeNotifList) { currNotifiable->NotifyResChanged(m_localData->sizeratio); }