+ Cmd_AddCommand("vid_restart", VID_Restart_f);
+ if (gamemode == GAME_GOODVSBAD2)
+ Cvar_Set("gl_combine", "0");
+}
+
+int current_vid_fullscreen;
+int current_vid_width;
+int current_vid_height;
+int current_vid_bitsperpixel;
+int current_vid_stencil;
+extern int VID_InitMode (int fullscreen, int width, int height, int bpp, int stencil);
+int VID_Mode(int fullscreen, int width, int height, int bpp, int stencil)
+{
+ Con_Printf("Video: %s %dx%dx%d %s\n", fullscreen ? "fullscreen" : "window", width, height, bpp, stencil ? "with stencil" : "without stencil");
+ if (VID_InitMode(fullscreen, width, height, bpp, stencil))
+ {
+ current_vid_fullscreen = fullscreen;
+ current_vid_width = width;
+ current_vid_height = height;
+ current_vid_bitsperpixel = bpp;
+ current_vid_stencil = stencil;
+ Cvar_SetValueQuick(&vid_fullscreen, fullscreen);
+ Cvar_SetValueQuick(&vid_width, width);
+ Cvar_SetValueQuick(&vid_height, height);
+ Cvar_SetValueQuick(&vid_bitsperpixel, bpp);
+ Cvar_SetValueQuick(&vid_stencil, stencil);
+ return true;
+ }
+ else
+ return false;
+}
+
+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, width, height;
+ 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);
+ width = 0;
+ height = 0;
+ if ((i = COM_CheckParm("-width")) != 0)
+ width = atoi(com_argv[i+1]);
+ if ((i = COM_CheckParm("-height")) != 0)
+ height = atoi(com_argv[i+1]);
+ if (width == 0)
+ width = height * 4 / 3;
+ if (height == 0)
+ height = width * 3 / 4;
+ if (width)
+ Cvar_SetValueQuick(&vid_width, width);
+ if (height)
+ Cvar_SetValueQuick(&vid_height, height);
+ 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_DPrintf("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();