Set the viewport size and resolution on resoultion change.
This commit is contained in:
parent
a1e507ef12
commit
0674f2d28d
1 changed files with 20 additions and 0 deletions
|
@ -23,6 +23,7 @@
|
|||
#include "sizeratio.hpp"
|
||||
#include <SDL2/SDL.h>
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
|
||||
namespace cloonel {
|
||||
struct SDLMain::LocalData {
|
||||
|
@ -102,6 +103,25 @@ namespace cloonel {
|
|||
///------------------------------------------------------------------------
|
||||
void SDLMain::SetResolution (ushort2 parRes) {
|
||||
m_localData->sizeratio.UpdateResolution(static_cast<float2>(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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue