https://github.com/libsdl-org/Maelstrom/commit/7b9d92f65152c2325ee8465ffb57fe3752ace757
From 7b9d92f65152c2325ee8465ffb57fe3752ace757 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 2 Oct 2012 03:37:15 -0700
Subject: [PATCH] Pick a higher resolution for systems that support it even if
the classic resolution is also supported.
---
game/init.cpp | 40 ++++++++++++--------------------------
screenlib/SDL_FrameBuf.cpp | 38 ++++++++++++++++++++++++++++++++----
screenlib/SDL_FrameBuf.h | 3 +++
3 files changed, 49 insertions(+), 32 deletions(-)
diff --git a/game/init.cpp b/game/init.cpp
index c64e796e..497fa7fa 100644
--- a/game/init.cpp
+++ b/game/init.cpp
@@ -166,38 +166,21 @@ static bool InitResolutions(int &w, int &h)
}
}
-#if 0 // We don't need this now that we're guaranteed our logical resolution
- // Look for the best mode in two passes, first check to see if any of
- // our supported modes are available, and if not just grab the first mode
- // that's bigger than any of our supported modes and stretch to that.
- SDL_DisplayMode mode;
- int displayIndex = 0;
- for (int pass = 0; pass < 2; ++pass) {
- bool exact = (pass == 0);
- for (int i = 0; i < SDL_GetNumDisplayModes(displayIndex); ++i) {
- if (SDL_GetDisplayMode(displayIndex, i, &mode) < 0) {
- continue;
- }
- gResolutionIndex = FindResolution(mode.w, mode.h);
- if (gResolutionIndex >= 0) {
- // Note that we're going to request our best supported resolution here.
- w = gResolutions[gResolutionIndex].w;
- h = gResolutions[gResolutionIndex].h;
- if (exact && (mode.w != w || mode.h != h)) {
- continue;
- }
- return true;
- }
- }
+ // Try to get our desktop size and use the closest supported resolution
+ screen->GetDesktopSize(w, h);
+ if (!w || !h) {
+ w = GAME_WIDTH;
+ h = GAME_HEIGHT;
+ }
+ gResolutionIndex = FindResolution(w, h);
+ if (gResolutionIndex >= 0) {
+ w = gResolutions[gResolutionIndex].w;
+ h = gResolutions[gResolutionIndex].h;
+ return true;
}
error("Couldn't find any supported resolutions\n");
return false;
-#else
- w = GAME_WIDTH;
- h = GAME_HEIGHT;
- return true;
-#endif
}
/* ----------------------------------------------------------------- */
@@ -840,6 +823,7 @@ int DoInitializations(Uint32 window_flags, Uint32 render_flags)
error("Fatal: %s\n", screen->Error());
return(-1);
}
+ screen->SetLogicalSize(GAME_WIDTH, GAME_HEIGHT);
screen->SetCaption("Maelstrom");
screen->Clear();
screen->Update();
diff --git a/screenlib/SDL_FrameBuf.cpp b/screenlib/SDL_FrameBuf.cpp
index 5d6cae97..2a678369 100644
--- a/screenlib/SDL_FrameBuf.cpp
+++ b/screenlib/SDL_FrameBuf.cpp
@@ -72,14 +72,13 @@ FrameBuf:: Init(int width, int height, Uint32 window_flags, Uint32 render_flags,
}
/* Set the output area */
- int w = width;
- int h = height;
if (Resizable()) {
+ int w, h;
SDL_GetWindowSize(window, &w, &h);
+ UpdateWindowSize(w, h);
} else {
- SDL_RenderSetLogicalSize(renderer, width, height);
+ SetLogicalSize(width, height);
}
- UpdateWindowSize(w, h);
return(0);
}
@@ -159,12 +158,43 @@ FrameBuf::DisableTextInput()
SDL_StopTextInput();
}
+void
+FrameBuf:: GetDesktopSize(int &w, int &h)
+{
+ SDL_DisplayMode mode;
+
+ if (SDL_GetDesktopDisplayMode(0, &mode) < 0) {
+ w = 0;
+ h = 0;
+ } else {
+ w = mode.w;
+ h = mode.h;
+ }
+}
+
void
FrameBuf:: GetDisplaySize(int &w, int &h)
{
SDL_GetWindowSize(window, &w, &h);
}
+void
+FrameBuf:: GetLogicalSize(int &w, int &h)
+{
+ SDL_RenderGetLogicalSize(renderer, &w, &h);
+ if (!w || !h) {
+ w = Width();
+ h = Height();
+ }
+}
+
+void
+FrameBuf:: SetLogicalSize(int w, int h)
+{
+ SDL_RenderSetLogicalSize(renderer, w, h);
+ UpdateWindowSize(w, h);
+}
+
void
FrameBuf:: QueueBlit(SDL_Texture *src,
int srcx, int srcy, int srcw, int srch,
diff --git a/screenlib/SDL_FrameBuf.h b/screenlib/SDL_FrameBuf.h
index eb0197ca..c529fed5 100644
--- a/screenlib/SDL_FrameBuf.h
+++ b/screenlib/SDL_FrameBuf.h
@@ -107,7 +107,10 @@ class FrameBuf : public ErrorBase {
bool Resizable() const {
return resizable;
}
+ void GetDesktopSize(int &w, int &h);
void GetDisplaySize(int &w, int &h);
+ void GetLogicalSize(int &w, int &h);
+ void SetLogicalSize(int w, int h);
/* Blit and update routines */
void QueueBlit(SDL_Texture *src,