Support creating an app with fixed resolution & add a list of common resolutions

This commit is contained in:
Nikita Lisitsa 2022-03-02 13:55:42 +03:00
parent 223ce10e0f
commit 123783c80a
2 changed files with 22 additions and 3 deletions

View file

@ -3,6 +3,8 @@
#include <psemek/app/scene.hpp> #include <psemek/app/scene.hpp>
#include <psemek/app/scene_manager.hpp> #include <psemek/app/scene_manager.hpp>
#include <psemek/geom/vector.hpp>
#include <psemek/util/pimpl.hpp> #include <psemek/util/pimpl.hpp>
#include <SDL2/SDL_keycode.h> #include <SDL2/SDL_keycode.h>
@ -12,12 +14,25 @@
namespace psemek::app namespace psemek::app
{ {
static const geom::vector<int, 2> common_resolutions[] =
{
{1024, 768},
{1280, 720},
{1280, 1024},
{1366, 768},
{1440, 900},
{1536, 864},
{1600, 900},
{1920, 1080},
};
struct app struct app
: scene_base, scene_manager : scene_base, scene_manager
{ {
struct options struct options
{ {
int multisampling = 0; int multisampling = 0;
std::optional<geom::vector<int, 2>> fixed_resolution = std::nullopt;
bool highdpi = false; bool highdpi = false;
}; };

View file

@ -80,10 +80,15 @@ namespace psemek::app
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, opts.multisampling); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, opts.multisampling);
} }
std::uint32_t flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_MAXIMIZED | SDL_WINDOW_HIDDEN; std::uint32_t flags = SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN;
if (!opts.fixed_resolution)
flags |= SDL_WINDOW_RESIZABLE | SDL_WINDOW_MAXIMIZED;
if (opts.highdpi) flags |= SDL_WINDOW_ALLOW_HIGHDPI; if (opts.highdpi) flags |= SDL_WINDOW_ALLOW_HIGHDPI;
impl().window = SDL_CreateWindow(name.data(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1024, 768, flags); int width = opts.fixed_resolution ? (*opts.fixed_resolution)[0] : 1024;
int height = opts.fixed_resolution ? (*opts.fixed_resolution)[1] : 768;
impl().window = SDL_CreateWindow(name.data(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, flags);
if (!impl().window) if (!impl().window)
sdl2::fail("Failed to create window: "); sdl2::fail("Failed to create window: ");
@ -104,7 +109,6 @@ namespace psemek::app
gl::GetIntegerv(gl::MINOR_VERSION, &minor); gl::GetIntegerv(gl::MINOR_VERSION, &minor);
log::info() << "Initialized OpenGL " << major << '.' << minor << ", " << vendor << ", " << renderer; log::info() << "Initialized OpenGL " << major << '.' << minor << ", " << vendor << ", " << renderer;
int width, height;
SDL_GL_GetDrawableSize(impl().window, &width, &height); SDL_GL_GetDrawableSize(impl().window, &width, &height);
scene_base::on_resize(width, height); scene_base::on_resize(width, height);