+static void VID_OpenSystems(void)
+{
+ R_Modules_Start();
+ S_Open();
+ CDAudio_Open();
+}
+
+static void VID_CloseSystems(void)
+{
+ CDAudio_Close();
+ S_Close();
+ R_Modules_Shutdown();
+}
+
+void VID_Restart_f(void)
+{
+ Con_Printf("VID_Restart: changing from %s %dx%dx%dbpp %s, to %s %dx%dx%dbpp %s.\n",
+ current_vid_fullscreen ? "fullscreen" : "window", current_vid_width, current_vid_height, current_vid_bitsperpixel, current_vid_stencil ? "with stencil" : "without stencil",
+ vid_fullscreen.integer ? "fullscreen" : "window", vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_stencil.integer ? "with stencil" : "without stencil");
+ VID_Close();
+ if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_stencil.integer))
+ {
+ Con_Printf("Video mode change failed\n");
+ if (!VID_Mode(current_vid_fullscreen, current_vid_width, current_vid_height, current_vid_bitsperpixel, current_vid_stencil))
+ Sys_Error("Unable to restore to last working video mode\n");
+ }
+ VID_OpenSystems();
+}
+
+int vid_commandlinecheck = true;
+void VID_Open(void)
+{
+ int i;
+ if (vid_commandlinecheck)
+ {
+ // interpret command-line parameters
+ vid_commandlinecheck = false;
+ if ((i = COM_CheckParm("-window")) != 0)
+ Cvar_SetValueQuick(&vid_fullscreen, false);
+ if ((i = COM_CheckParm("-fullscreen")) != 0)
+ Cvar_SetValueQuick(&vid_fullscreen, true);
+ if ((i = COM_CheckParm("-width")) != 0)
+ Cvar_SetQuick(&vid_width, com_argv[i+1]);
+ if ((i = COM_CheckParm("-height")) != 0)
+ Cvar_SetQuick(&vid_height, com_argv[i+1]);
+ if ((i = COM_CheckParm("-bpp")) != 0)
+ Cvar_SetQuick(&vid_bitsperpixel, com_argv[i+1]);
+ if ((i = COM_CheckParm("-nostencil")) != 0)
+ Cvar_SetValueQuick(&vid_stencil, 0);
+ if ((i = COM_CheckParm("-stencil")) != 0)
+ Cvar_SetValueQuick(&vid_stencil, 1);
+ }
+
+ if (vid_stencil.integer && vid_bitsperpixel.integer != 32)
+ {
+ Con_Printf("vid_stencil not allowed without vid_bitsperpixel 32, turning off vid_stencil\n");
+ Cvar_SetValueQuick(&vid_stencil, 0);
+ }
+
+ Con_Printf("Starting video system\n");
+ if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_stencil.integer))
+ {
+ Con_Printf("Desired video mode fail, trying fallbacks...\n");
+ if (!vid_stencil.integer || !VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, false))
+ {
+ if (vid_fullscreen.integer)
+ {
+ if (!VID_Mode(true, 640, 480, 16, false))
+ if (!VID_Mode(false, 640, 480, 16, false))
+ Sys_Error("Video modes failed\n");
+ }
+ else
+ Sys_Error("Windowed video failed\n");
+ }
+ }
+ VID_OpenSystems();
+}
+
+void VID_Close(void)
+{
+ VID_CloseSystems();
+ VID_Shutdown();
+}