Implemented fullscreen mode selection, OpenGL only for the moment
authorIngo Ruhnke <grumbel@gmail.com>
Thu, 31 Jul 2014 05:01:43 +0000 (07:01 +0200)
committerIngo Ruhnke <grumbel@gmail.com>
Thu, 31 Jul 2014 05:01:43 +0000 (07:01 +0200)
src/supertux/gameconfig.cpp
src/supertux/gameconfig.hpp
src/supertux/main.cpp
src/supertux/menu/options_menu.cpp
src/video/gl/gl_renderer.cpp

index 235198c..0322a9d 100644 (file)
@@ -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);
index 527241f..5836644 100644 (file)
@@ -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;
 
index 15ac35b..b1d0ced 100644 (file)
@@ -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;
 }
 
index f1f96d4..d65aa7d 100644 (file)
@@ -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<std::string>::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;
 
index 739ac7f..d869785 100644 (file)
@@ -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
     {