From: Ingo Ruhnke Date: Thu, 31 Jul 2014 05:01:43 +0000 (+0200) Subject: Implemented fullscreen mode selection, OpenGL only for the moment X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=d6070419a90f036f00b640d5a9d0efdd8a2975a4;p=supertux.git Implemented fullscreen mode selection, OpenGL only for the moment --- diff --git a/src/supertux/gameconfig.cpp b/src/supertux/gameconfig.cpp index 235198c67..0322a9dc1 100644 --- a/src/supertux/gameconfig.cpp +++ b/src/supertux/gameconfig.cpp @@ -28,6 +28,7 @@ Config::Config() : profile(1), fullscreen_size(800, 600), + fullscreen_refresh_rate(0), window_size(800, 600), aspect_size(0, 0), // auto detect magnification(0.0f), @@ -75,6 +76,7 @@ Config::load() config_video_lisp->get("fullscreen_width", fullscreen_size.width); config_video_lisp->get("fullscreen_height", fullscreen_size.height); + config_video_lisp->get("fullscreen_refresh_rate", fullscreen_refresh_rate); config_video_lisp->get("window_width", window_size.width); config_video_lisp->get("window_height", window_size.height); @@ -120,6 +122,7 @@ Config::save() writer.write("fullscreen_width", fullscreen_size.width); writer.write("fullscreen_height", fullscreen_size.height); + writer.write("fullscreen_refresh_rate", fullscreen_refresh_rate); writer.write("window_width", window_size.width); writer.write("window_height", window_size.height); diff --git a/src/supertux/gameconfig.hpp b/src/supertux/gameconfig.hpp index 527241fd2..5836644ac 100644 --- a/src/supertux/gameconfig.hpp +++ b/src/supertux/gameconfig.hpp @@ -34,6 +34,9 @@ public: // the width/height to be used to display the game in fullscreen Size fullscreen_size; + // refresh rate for use in fullscreen, 0 for auto + int fullscreen_refresh_rate; + /** the width/height of the window managers window */ Size window_size; diff --git a/src/supertux/main.cpp b/src/supertux/main.cpp index 15ac35b78..b1d0cedb5 100644 --- a/src/supertux/main.cpp +++ b/src/supertux/main.cpp @@ -319,6 +319,7 @@ Main::parse_commandline(int argc, char** argv) g_config->window_size = Size(800, 600); g_config->fullscreen_size = Size(800, 600); + g_config->fullscreen_refresh_rate = 0; g_config->aspect_size = Size(0, 0); // auto detect } else if(arg == "--window" || arg == "-w") { @@ -342,6 +343,7 @@ Main::parse_commandline(int argc, char** argv) { g_config->window_size = Size(width, height); g_config->fullscreen_size = Size(width, height); + g_config->fullscreen_refresh_rate = 0; } } } else if(arg == "--aspect" || arg == "-a") { @@ -481,7 +483,7 @@ Main::init_video() log_info << (g_config->use_fullscreen?"fullscreen ":"window ") << " Window: " << g_config->window_size - << " Fullscreen: " << g_config->fullscreen_size + << " Fullscreen: " << g_config->fullscreen_size << "@" << g_config->fullscreen_refresh_rate << " Area: " << g_config->aspect_size << std::endl; } diff --git a/src/supertux/menu/options_menu.cpp b/src/supertux/menu/options_menu.cpp index f1f96d4d4..d65aa7d10 100644 --- a/src/supertux/menu/options_menu.cpp +++ b/src/supertux/menu/options_menu.cpp @@ -106,36 +106,25 @@ OptionsMenu::OptionsMenu() : } } - - for(int disp_mode_ctr = 0; disp_mode_ctr < SDL_GetNumDisplayModes(0); disp_mode_ctr++) + int display_mode_count = SDL_GetNumDisplayModes(0); + for(int i = 0; i < display_mode_count; ++i) { -#ifdef OLD_SDL1 - SDL_DisplayMode* current = NULL; - int disp_retval = SDL_GetDisplayMode(0, // Display Index - disp_mode_ctr, // Mode index (default to first) - current); // DisplayMode structure ptr - if (disp_retval == -1) - { // No resolutions at all available, bad - } - else if(disp_retval == 0) - { // All resolutions should work, so we fall back to hardcoded defaults - std::stringstream width; - std::stringstream height; - width << current->w; - height << current->h; - fullscreen_res->list.push_back(width.str() + "x" + height.str()); + SDL_DisplayMode mode; + int ret = SDL_GetDisplayMode(0, i, &mode); + if (ret != 0) + { + log_warning << "failed to get display mode: " << SDL_GetError() << std::endl; } else { + std::ostringstream out; + out << mode.w << "x" << mode.h << "@" << mode.refresh_rate; + fullscreen_res->list.push_back(out.str()); } -#endif } - // On Ubuntu/Linux resolutions are returned from highest to - // lowest, so reverse them - std::sort(fullscreen_res->list.begin(), fullscreen_res->list.end(), StringUtil::numeric_less); - + std::ostringstream out; - out << g_config->fullscreen_size.width << "x" << g_config->fullscreen_size.height; + out << g_config->fullscreen_size.width << "x" << g_config->fullscreen_size.height << "@" << g_config->fullscreen_refresh_rate; std::string fllscrn_sz = out.str(); size_t cnt = 0; for (std::vector::iterator i = fullscreen_res->list.begin(); i != fullscreen_res->list.end(); ++i) @@ -216,25 +205,25 @@ OptionsMenu::menu_action(MenuItem* item) { switch (item->id) { case MNID_ASPECTRATIO: - { - if (item->list[item->selected] == _("auto")) - { - g_config->aspect_size = Size(0, 0); // Magic values - Renderer::instance()->apply_config(); - MenuManager::recalc_pos(); - } - else if (sscanf(item->list[item->selected].c_str(), "%d:%d", - &g_config->aspect_size.width, &g_config->aspect_size.height) == 2) - { - Renderer::instance()->apply_config(); - MenuManager::recalc_pos(); - } - else { - assert(!"This must not be reached"); + if (item->list[item->selected] == _("auto")) + { + g_config->aspect_size = Size(0, 0); // Magic values + Renderer::instance()->apply_config(); + MenuManager::recalc_pos(); + } + else if (sscanf(item->list[item->selected].c_str(), "%d:%d", + &g_config->aspect_size.width, &g_config->aspect_size.height) == 2) + { + Renderer::instance()->apply_config(); + MenuManager::recalc_pos(); + } + else + { + assert(!"This must not be reached"); + } } - } - break; + break; case MNID_MAGNIFICATION: if (item->list[item->selected] == _("auto")) @@ -250,10 +239,18 @@ OptionsMenu::menu_action(MenuItem* item) break; case MNID_FULLSCREEN_RESOLUTION: - if(sscanf(item->list[item->selected].c_str(), "%dx%d", - &g_config->fullscreen_size.width, &g_config->fullscreen_size.height) == 2) { - // do nothing, changes are only applied when toggling fullscreen mode + int width; + int height; + int refresh_rate; + if(sscanf(item->list[item->selected].c_str(), "%dx%d@%d", + &width, &height, &refresh_rate) == 3) + { + // do nothing, changes are only applied when toggling fullscreen mode + g_config->fullscreen_size.width = width; + g_config->fullscreen_size.height = height; + g_config->fullscreen_refresh_rate = refresh_rate; + } } break; diff --git a/src/video/gl/gl_renderer.cpp b/src/video/gl/gl_renderer.cpp index 739ac7f17..d8697856f 100644 --- a/src/video/gl/gl_renderer.cpp +++ b/src/video/gl/gl_renderer.cpp @@ -615,7 +615,24 @@ GLRenderer::apply_video_mode(const Size& size, bool fullscreen) { int fullscreen_flags = SDL_WINDOW_FULLSCREEN; // SDL_WINDOW_FULLSCREEN_DESKTOP or 0 SDL_SetWindowDisplayMode(window, NULL); - SDL_SetWindowFullscreen(window, fullscreen_flags); + + SDL_DisplayMode mode; + mode.format = SDL_PIXELFORMAT_RGB888; + mode.w = g_config->fullscreen_size.width; + mode.h = g_config->fullscreen_size.height; + mode.refresh_rate = g_config->fullscreen_refresh_rate; + mode.driverdata = 0; + + if (SDL_SetWindowDisplayMode(window, &mode) != 0) + { + log_warning << "failed to set display mode: " + << mode.w << "x" << mode.h << "@" << mode.refresh_rate << ": " + << SDL_GetError() << std::endl; + } + else + { + SDL_SetWindowFullscreen(window, fullscreen_flags); + } } else {