The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Fullscreen resolution restore
theGiallo


Joined: 03 Nov 2014
Posts: 11
Location: Genova, IT
I'm using Debian with 2 monitors with different resolutions.
I Init SDL and create a window separately. If I create the window in fullscreen with a smaller resolution than the one of the primary monitor I get a strange fullscreen mode, with the Xorg view restricted to the small resolution, but the screen space is large as usual and I can move within it moving the mouse. The secondary screen remains normal.
On exit I destroy the renderer, the window and call SDL_Quit. If so my screen remain in the messy situation. If I do not destroy the window it returns to the normal full view.

I've made some mistake? Is this supposed to happen?

Code:

   // Initialize SDL's Video subsystem
   ret = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER);
   if (ret != 0)
   {
      const char *error = SDL_GetError();
      if (*error != '\0')
      {
         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not SDL_Init. SDL error: %s at line #%d of file %s", error, __LINE__, __FILE__);
         // SDL_ClearError();
         return 1;
      }
   }

   // Create an application window with the following settings:
   Environment::window = SDL_CreateWindow(
                  "Local Flight",                     // const char* title
                  SDL_WINDOWPOS_UNDEFINED,            // int x: initial x position, SDL_WINDOWPOS_CENTERED, or SDL_WINDOWPOS_UNDEFINED
                  SDL_WINDOWPOS_UNDEFINED,            // int y: initial y position, SDL_WINDOWPOS_CENTERED, or SDL_WINDOWPOS_UNDEFINED
                  1024,                               // int w: width, in pixels
                  576,                                // int h: height, in pixels
                  SDL_WINDOW_SHOWN
                  | SDL_WINDOW_FULLSCREEN             // Uint32 flags: window options, see docs
         );

   // Check that the window was successfully made
   if(Environment::window==NULL)
   {
      const char *error = SDL_GetError();
      if (*error != '\0')
      {
         // In the event that the window could not be made...
         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create window. SDL error: %s at line #%d of file %s", error, __LINE__, __FILE__);
         SDL_Quit();
         return 1;
      }
   }

   // Create accelerated renderer
   Environment::renderer = SDL_CreateRenderer(
                                 Environment::window,          // SDL_Window* window: the window where rendering is displayed
                                 -1,                           // int index: the index of the rendering driver to initialize, or -1 to initialize the first one supporting the requested flags
                                 SDL_RENDERER_ACCELERATED);    // Uint32 flags: 0, or one or more SDL_RendererFlags OR'd together;
   // Check that the renderer was successfully made
   if(Environment::renderer==NULL)
   {
      const char *error = SDL_GetError();
      if (*error != '\0')
      {
         // In the event that the window could not be made...
         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not create accelerated renderer. SDL error: %s at line #%d of file %s", error, __LINE__, __FILE__);
         // Fallback to software renderer
         Environment::renderer = SDL_CreateRenderer(
                                       Environment::window,
                                       -1,
                                       SDL_RENDERER_SOFTWARE);
         if(Environment::renderer==NULL)
         {
            const char *error = SDL_GetError();
            if (*error != '\0')
            {
               // In the event that the window could not be made...
               SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Could not even create software renderer. SDL error: %s at line #%d of file %s", error, __LINE__, __FILE__);
               SDL_Quit();
               return 1;
            }
         }
         SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Fallback to software renderer, you may observe poor performance.");
      }
   } else
   {
      // Settings
      SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
      SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
      SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
      SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);

      SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32);

      SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
      SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 2);

      SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);

      // glEnable(GL_MULTISAMPLE);
      ret = SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 16);
      DCHECKSDLERROR(ret);

      int Buffers, Samples;
      SDL_GL_GetAttribute( SDL_GL_MULTISAMPLEBUFFERS, &Buffers );
      SDL_GL_GetAttribute( SDL_GL_MULTISAMPLESAMPLES, &Samples );
      std::cout << "buf = " << Buffers << ", samples = " << Samples << "."<<std::endl;
   }


   /**
    * the other code
    * ...
    **/


   // Exit
   //---
   SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Exiting...");

   // Destroy renderer
   SDL_DestroyRenderer(Environment::renderer);

   // Close and destroy the window
   SDL_DestroyWindow(Environment::window); /// if I comment this line everithing will be OK

   // Quit SDL
   SDL_Quit();

   // Close the font
   TTF_CloseFont(font);

   // Quit SDL_ttf
   if (TTF_WasInit())
   {
      TTF_Quit();
   }
   return 0;
}