resolution fix
[vg.git] / vg.h
diff --git a/vg.h b/vg.h
index 17bc6eee93b817f032ce128a0e1893f9c71161ec..25dc65ecda9fe173b754daa9adcce05a9c76cb55 100644 (file)
--- a/vg.h
+++ b/vg.h
@@ -677,24 +677,38 @@ VG_STATIC void _vg_init_window( const char *window_name )
       exit(0);
    }
 
+
+
+
    /* TODO: Allow chosing the modes at startup */
-   vg_info( "Getting display mode\n" );
-   SDL_DisplayMode mode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 };
-   if( SDL_GetDisplayMode( display_index, mode_index, &mode ) != 0 )
+   vg_info( "Getting default display mode\n" );
+   SDL_DisplayMode vm_ideal = { 0, 0, 0, 0, 0 };
+   if( SDL_GetDisplayMode( display_index, mode_index, &vm_ideal ) != 0 )
    {
       vg_error( "SDL_GetDisplayMode failed: %s", SDL_GetError() );
       exit(0);
    }
 
-   vg.refresh_rate = mode.refresh_rate;
+   if( vg.window_x )
+      vm_ideal.w = vg.window_x;
+
+   if( vg.window_y )
+      vm_ideal.h = vg.window_y;
+
 
-   if( !vg.window_x )
-      vg.window_x = mode.w;
+   SDL_DisplayMode vm_best;
+   if( !SDL_GetClosestDisplayMode( display_index, &vm_ideal, &vm_best ) )
+   {
+      vg_error( "SDL_GetClosestDisplayMode failed: %s", SDL_GetError() );
+      exit(0);
+   }
 
-   if( !vg.window_y )
-      vg.window_y = mode.h;
+   vg.refresh_rate = vm_best.refresh_rate;
+   vg.window_x = vm_best.w;
+   vg.window_y = vm_best.h;
 
-   vg_info( "CreateWindow( %d %d )\n", vg.window_x, vg.window_y );
+   vg_info( "CreateWindow( %d %d @%.2fhz )\n", vg.window_x, vg.window_y,
+                                               vg.refresh_rate );
 
    /* TODO: Allow selecting closest video mode from launch opts */
    if((vg.window = SDL_CreateWindow( window_name,
@@ -702,10 +716,16 @@ VG_STATIC void _vg_init_window( const char *window_name )
                                      SDL_WINDOWPOS_UNDEFINED,
                                      vg.window_x, vg.window_y,
 
-                                     SDL_WINDOW_FULLSCREEN_DESKTOP | 
+                                     SDL_WINDOW_FULLSCREEN | 
                                      SDL_WINDOW_OPENGL |
                                      SDL_WINDOW_INPUT_GRABBED )))
    {
+      if( SDL_SetWindowDisplayMode( vg.window, &vm_best ) )
+      {
+         vg_error( "SDL_SetWindowDisplayMode failed: %s", SDL_GetError() );
+         SDL_Quit();
+         exit(0);
+      }
    }
    else
    {