diff --git a/libopenage/engine/engine.cpp b/libopenage/engine/engine.cpp index fa2c251b4d..dc787ebcf1 100644 --- a/libopenage/engine/engine.cpp +++ b/libopenage/engine/engine.cpp @@ -1,4 +1,4 @@ -// Copyright 2023-2023 the openage authors. See copying.md for legal info. +// Copyright 2023-2024 the openage authors. See copying.md for legal info. #include "engine.h" @@ -16,7 +16,8 @@ namespace openage::engine { Engine::Engine(mode mode, const util::Path &root_dir, const std::vector &mods, - bool debug_graphics) : + bool debug_graphics, + const renderer::window_settings &window_settings) : running{true}, run_mode{mode}, root_dir{root_dir}, @@ -56,7 +57,7 @@ Engine::Engine(mode mode, // if presenter is used, run it in a separate thread if (this->run_mode == mode::FULL) { this->threads.emplace_back([&, debug_graphics]() { - this->presenter->run(debug_graphics); + this->presenter->run(debug_graphics, window_settings); // Make sure that the presenter gets destructed in the same thread // otherwise OpenGL complains about missing contexts diff --git a/libopenage/engine/engine.h b/libopenage/engine/engine.h index 1fe4298061..d324fe4fda 100644 --- a/libopenage/engine/engine.h +++ b/libopenage/engine/engine.h @@ -9,6 +9,8 @@ #include "util/path.h" +#include + // TODO: Remove custom jthread definition when clang/libc++ finally supports it #if __llvm__ #if !__cpp_lib_jthread @@ -72,11 +74,13 @@ class Engine { * @param root_dir openage root directory. * @param mods The mods to load. * @param debug_graphics If true, enable OpenGL debug logging. + * @param window_settings window display setting */ Engine(mode mode, const util::Path &root_dir, const std::vector &mods, - bool debug_graphics = false); + bool debug_graphics = false, + const renderer::window_settings &window_settings = {}); // engine should not be copied or moved Engine(const Engine &) = delete; diff --git a/libopenage/main.cpp b/libopenage/main.cpp index e7794be40c..f8e6b45f3f 100644 --- a/libopenage/main.cpp +++ b/libopenage/main.cpp @@ -1,4 +1,4 @@ -// Copyright 2015-2023 the openage authors. See copying.md for legal info. +// Copyright 2015-2024 the openage authors. See copying.md for legal info. #include "main.h" @@ -31,7 +31,25 @@ int run_game(const main_arguments &args) { run_mode = openage::engine::Engine::mode::HEADLESS; } - openage::engine::Engine engine{run_mode, args.root_path, args.mods, args.gl_debug}; + // convert window arguments to window settings + renderer::window_settings win_settings = {}; + win_settings.width = args.window_args.width; + win_settings.height = args.window_args.height; + win_settings.vsync = args.window_args.vsync; + + renderer::window_mode wmode; + if (args.window_args.mode == "fullscreen") { + wmode = renderer::window_mode::FULLSCREEN; + } + else if (args.window_args.mode == "borderless") { + wmode = renderer::window_mode::BORDERLESS; + } + else { + wmode = renderer::window_mode::WINDOWED; + } + win_settings.mode = wmode; + + openage::engine::Engine engine{run_mode, args.root_path, args.mods, args.gl_debug, win_settings}; engine.loop(); diff --git a/libopenage/main.h b/libopenage/main.h index 0e60c386cc..e99b374642 100644 --- a/libopenage/main.h +++ b/libopenage/main.h @@ -1,4 +1,4 @@ -// Copyright 2015-2023 the openage authors. See copying.md for legal info. +// Copyright 2015-2024 the openage authors. See copying.md for legal info. #pragma once @@ -16,6 +16,24 @@ namespace openage { +/** + * Window parameters struct. + * + * pxd: + * + * cppclass window_arguments: + * int width + * int height + * bool vsync + * string mode + */ +struct window_arguments { + int width; + int height; + bool vsync; + std::string mode; +}; + /** * Used for passing arguments to run_game. * @@ -26,12 +44,14 @@ namespace openage { * bool gl_debug * bool headless * vector[string] mods + * window_arguments window_args */ struct main_arguments { util::Path root_path; bool gl_debug; bool headless; std::vector mods; + window_arguments window_args; }; diff --git a/libopenage/presenter/presenter.cpp b/libopenage/presenter/presenter.cpp index a37362be95..6d77a72710 100644 --- a/libopenage/presenter/presenter.cpp +++ b/libopenage/presenter/presenter.cpp @@ -32,7 +32,6 @@ #include "renderer/stages/skybox/render_stage.h" #include "renderer/stages/terrain/render_stage.h" #include "renderer/stages/world/render_stage.h" -#include "renderer/window.h" #include "time/time_loop.h" #include "util/path.h" @@ -48,10 +47,10 @@ Presenter::Presenter(const util::Path &root_dir, time_loop{time_loop} {} -void Presenter::run(bool debug_graphics) { +void Presenter::run(bool debug_graphics, const renderer::window_settings &window_settings) { log::log(INFO << "Presenter: Launching subsystems..."); - this->init_graphics(debug_graphics); + this->init_graphics(debug_graphics, window_settings); this->init_input(); @@ -93,18 +92,14 @@ std::shared_ptr Presenter::init_window_system() { return std::make_shared(); } -void Presenter::init_graphics(bool debug) { +void Presenter::init_graphics(bool debug, const renderer::window_settings &window_settings) { log::log(INFO << "Presenter: Initializing graphics subsystems..."); // Start up rendering framework this->gui_app = this->init_window_system(); // Window and renderer - renderer::window_settings settings; - settings.width = 1024; - settings.height = 768; - settings.debug = debug; - this->window = renderer::Window::create("openage presenter test", settings); + this->window = renderer::Window::create("openage presenter test", window_settings); this->renderer = this->window->make_renderer(); // Asset mangement diff --git a/libopenage/presenter/presenter.h b/libopenage/presenter/presenter.h index b43d4fc60f..6f45800a32 100644 --- a/libopenage/presenter/presenter.h +++ b/libopenage/presenter/presenter.h @@ -7,6 +7,9 @@ #include "util/path.h" +#include + + namespace qtgui { class GuiApplication; } @@ -88,8 +91,9 @@ class Presenter { * Start the presenter and initialize subsystems. * * @param debug_graphics If true, enable OpenGL debug logging. + * @param window_settings window display setting */ - void run(bool debug_graphics = false); + void run(bool debug_graphics = false, const renderer::window_settings &window_settings = {}); /** * Set the game simulation controlled by this presenter. @@ -120,7 +124,7 @@ class Presenter { * - main renderer * - component renderers (Terrain, Game Entities, GUI) */ - void init_graphics(bool debug = false); + void init_graphics(bool debug = false, const renderer::window_settings &window_settings = {}); /** * Initialize the GUI. diff --git a/libopenage/renderer/opengl/window.cpp b/libopenage/renderer/opengl/window.cpp index 5f75717540..d832c49337 100644 --- a/libopenage/renderer/opengl/window.cpp +++ b/libopenage/renderer/opengl/window.cpp @@ -57,6 +57,21 @@ GlWindow::GlWindow(const std::string &title, this->window->setFormat(format); this->window->create(); + // set display mode + switch (settings.mode) { + case window_mode::FULLSCREEN: + this->window->showFullScreen(); + break; + case window_mode::BORDERLESS: + this->window->setFlags(this->window->flags() | Qt::FramelessWindowHint); + this->window->show(); + break; + case window_mode::WINDOWED: + default: + this->window->showNormal(); + break; + } + this->context = std::make_shared(this->window, settings.debug); if (not this->context->get_raw_context()->isValid()) { throw Error{MSG(err) << "Failed to create Qt OpenGL context."}; diff --git a/libopenage/renderer/window.h b/libopenage/renderer/window.h index 71960e2d17..6f34aa58e3 100644 --- a/libopenage/renderer/window.h +++ b/libopenage/renderer/window.h @@ -21,6 +21,15 @@ namespace openage::renderer { class WindowEventHandler; +/** + * Modes for window display. + */ +enum class window_mode { + FULLSCREEN, + BORDERLESS, + WINDOWED +}; + /** * Settings for creating a window. */ @@ -35,6 +44,8 @@ struct window_settings { bool vsync = true; // If true, enable debug logging for the selected backend. bool debug = false; + // Display mode for the window. + window_mode mode = window_mode::FULLSCREEN; };