bird
[vg.git] / vg.h
diff --git a/vg.h b/vg.h
index ada54695aee189dc37a0583dceabc5cd6c17786d..eb858a38b33017d7fc20b5e457c91802d8c41b00 100644 (file)
--- a/vg.h
+++ b/vg.h
@@ -176,9 +176,7 @@ struct vg
    engine_stage;
 
    /* graphics */
-#if 0
    m4x4f pv;
-#endif
    enum quality_profile
    {
       k_quality_profile_high = 0,
@@ -373,13 +371,11 @@ VG_STATIC void vg_bake_shaders(void)
 {
    vg_acquire_thread_sync();
 
-#if 0
    vg_function_push( (struct vg_cmd)
    {
-      .name = "shaders",
+      .name = "reload_shaders",
       .function = vg_shaders_live_recompile
    });
-#endif
 
    vg_shaders_compile();
    vg_release_thread_sync();
@@ -552,9 +548,7 @@ VG_STATIC void _vg_gameloop_render(void)
          }
 
          /* FIXME */
-#if 0
          audio_debug_ui( vg.pv );
-#endif
          vg_ui();
          _vg_console_draw();
          
@@ -597,7 +591,6 @@ VG_STATIC void _vg_gameloop(void)
 
       _vg_gameloop_update();
       _vg_gameloop_render();
-      audio_push_console_vol();
 
       SDL_GL_SwapWindow( vg.window );
       _vg_run_synced();
@@ -677,29 +670,55 @@ 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;
+
+
+   SDL_DisplayMode vm_best;
+   if( !SDL_GetClosestDisplayMode( display_index, &vm_ideal, &vm_best ) )
+   {
+      vg_error( "SDL_GetClosestDisplayMode failed: %s", SDL_GetError() );
+      exit(0);
+   }
+
+   vg.refresh_rate = vm_best.refresh_rate;
+   vg.window_x = vm_best.w;
+   vg.window_y = vm_best.h;
 
-   vg_info( "CreateWindow\n" );
+   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,
                                      SDL_WINDOWPOS_UNDEFINED,
                                      SDL_WINDOWPOS_UNDEFINED,
-                                     mode.w, mode.h,
+                                     vg.window_x, vg.window_y,
 
                                      SDL_WINDOW_FULLSCREEN_DESKTOP | 
                                      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
    {
@@ -751,6 +770,16 @@ VG_STATIC void _vg_init_window( const char *window_name )
    }
    else
       vg_success( "Using adaptive Vsync\n" );
+
+   SDL_DisplayMode dispmode;
+   if( !SDL_GetWindowDisplayMode( vg.window, &dispmode ) )
+   {
+      if( dispmode.refresh_rate )
+      {
+         vg.refresh_rate = dispmode.refresh_rate;
+         vg_info( "Refresh rate: %d\n", dispmode.refresh_rate );
+      }
+   }
 }
 
 VG_STATIC void vg_enter( int argc, char *argv[], const char *window_name )