Support creating an app with fixed resolution & add a list of common resolutions
This commit is contained in:
parent
223ce10e0f
commit
123783c80a
2 changed files with 22 additions and 3 deletions
|
|
@ -3,6 +3,8 @@
|
|||
#include <psemek/app/scene.hpp>
|
||||
#include <psemek/app/scene_manager.hpp>
|
||||
|
||||
#include <psemek/geom/vector.hpp>
|
||||
|
||||
#include <psemek/util/pimpl.hpp>
|
||||
|
||||
#include <SDL2/SDL_keycode.h>
|
||||
|
|
@ -12,12 +14,25 @@
|
|||
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
|
||||
: scene_base, scene_manager
|
||||
{
|
||||
struct options
|
||||
{
|
||||
int multisampling = 0;
|
||||
std::optional<geom::vector<int, 2>> fixed_resolution = std::nullopt;
|
||||
bool highdpi = false;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -80,10 +80,15 @@ namespace psemek::app
|
|||
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;
|
||||
|
||||
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)
|
||||
sdl2::fail("Failed to create window: ");
|
||||
|
||||
|
|
@ -104,7 +109,6 @@ namespace psemek::app
|
|||
gl::GetIntegerv(gl::MINOR_VERSION, &minor);
|
||||
log::info() << "Initialized OpenGL " << major << '.' << minor << ", " << vendor << ", " << renderer;
|
||||
|
||||
int width, height;
|
||||
SDL_GL_GetDrawableSize(impl().window, &width, &height);
|
||||
scene_base::on_resize(width, height);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue