7 // LordHavoc: these are only set in wgl
8 qboolean isG200 = false; // LordHavoc: the Matrox G200 can't do per pixel alpha, and it uses a D3D driver for GL... ugh...
9 qboolean isRagePro = false; // LordHavoc: the ATI Rage Pro has limitations with per pixel alpha (the color scaler does not apply to per pixel alpha images...), although not as bad as a G200.
11 // GL_ARB_multitexture
12 int gl_textureunits = 0;
13 // GL_ARB_texture_env_combine or GL_EXT_texture_env_combine
14 int gl_combine_extension = false;
15 // GL_EXT_compiled_vertex_array
16 int gl_supportslockarrays = false;
17 // GLX_SGI_video_sync or WGL_EXT_swap_control
18 int gl_videosyncavailable = false;
20 int gl_stencil = false;
21 // 3D textures available
22 int gl_texture3d = false;
23 // GL_ARB_texture_cubemap
24 int gl_texturecubemap = false;
25 // GL_ARB_texture_env_dot3
26 int gl_dot3arb = false;
28 // LordHavoc: if window is hidden, don't update screen
29 int vid_hidden = true;
30 // LordHavoc: if window is not the active window, don't hog as much CPU time,
31 // let go of the mouse, turn off sound, and restore system gamma ramps...
32 int vid_activewindow = true;
34 cvar_t vid_fullscreen = {CVAR_SAVE, "vid_fullscreen", "1"};
35 cvar_t vid_width = {CVAR_SAVE, "vid_width", "640"};
36 cvar_t vid_height = {CVAR_SAVE, "vid_height", "480"};
37 cvar_t vid_bitsperpixel = {CVAR_SAVE, "vid_bitsperpixel", "16"};
38 cvar_t vid_stencil = {CVAR_SAVE, "vid_stencil", "0"};
40 cvar_t vid_mouse = {CVAR_SAVE, "vid_mouse", "1"};
41 cvar_t gl_combine = {0, "gl_combine", "1"};
43 cvar_t in_pitch_min = {0, "in_pitch_min", "-90"};
44 cvar_t in_pitch_max = {0, "in_pitch_max", "90"};
46 cvar_t m_filter = {CVAR_SAVE, "m_filter","0"};
48 // brand of graphics chip
49 const char *gl_vendor;
50 // graphics chip model and other information
51 const char *gl_renderer;
52 // begins with 1.0.0, 1.1.0, 1.2.0, 1.2.1, 1.3.0, 1.3.1, or 1.4.0
53 const char *gl_version;
54 // extensions list, space separated
55 const char *gl_extensions;
57 const char *gl_platform;
58 // another extensions list, containing platform-specific extensions that are
59 // not in the main list
60 const char *gl_platformextensions;
61 // name of driver library (opengl32.dll, libGL.so.1, or whatever)
64 // GL_ARB_multitexture
65 void (GLAPIENTRY *qglMultiTexCoord2f) (GLenum, GLfloat, GLfloat);
66 void (GLAPIENTRY *qglActiveTexture) (GLenum);
67 void (GLAPIENTRY *qglClientActiveTexture) (GLenum);
69 // GL_EXT_compiled_vertex_array
70 void (GLAPIENTRY *qglLockArraysEXT) (GLint first, GLint count);
71 void (GLAPIENTRY *qglUnlockArraysEXT) (void);
74 // general GL functions
76 void (GLAPIENTRY *qglClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
78 void (GLAPIENTRY *qglClear)(GLbitfield mask);
80 //void (GLAPIENTRY *qglAlphaFunc)(GLenum func, GLclampf ref);
81 void (GLAPIENTRY *qglBlendFunc)(GLenum sfactor, GLenum dfactor);
82 void (GLAPIENTRY *qglCullFace)(GLenum mode);
84 void (GLAPIENTRY *qglDrawBuffer)(GLenum mode);
85 void (GLAPIENTRY *qglReadBuffer)(GLenum mode);
86 void (GLAPIENTRY *qglEnable)(GLenum cap);
87 void (GLAPIENTRY *qglDisable)(GLenum cap);
88 //GLboolean GLAPIENTRY *qglIsEnabled)(GLenum cap);
90 void (GLAPIENTRY *qglEnableClientState)(GLenum cap);
91 void (GLAPIENTRY *qglDisableClientState)(GLenum cap);
93 void (GLAPIENTRY *qglGetBooleanv)(GLenum pname, GLboolean *params);
94 void (GLAPIENTRY *qglGetDoublev)(GLenum pname, GLdouble *params);
95 void (GLAPIENTRY *qglGetFloatv)(GLenum pname, GLfloat *params);
96 void (GLAPIENTRY *qglGetIntegerv)(GLenum pname, GLint *params);
98 GLenum (GLAPIENTRY *qglGetError)(void);
99 const GLubyte* (GLAPIENTRY *qglGetString)(GLenum name);
100 void (GLAPIENTRY *qglFinish)(void);
101 void (GLAPIENTRY *qglFlush)(void);
103 void (GLAPIENTRY *qglClearDepth)(GLclampd depth);
104 void (GLAPIENTRY *qglDepthFunc)(GLenum func);
105 void (GLAPIENTRY *qglDepthMask)(GLboolean flag);
106 void (GLAPIENTRY *qglDepthRange)(GLclampd near_val, GLclampd far_val);
107 void (GLAPIENTRY *qglColorMask)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
109 void (GLAPIENTRY *qglDrawRangeElements)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
110 void (GLAPIENTRY *qglDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
111 void (GLAPIENTRY *qglVertexPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
112 //void (GLAPIENTRY *qglNormalPointer)(GLenum type, GLsizei stride, const GLvoid *ptr);
113 void (GLAPIENTRY *qglColorPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
114 void (GLAPIENTRY *qglTexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
115 void (GLAPIENTRY *qglArrayElement)(GLint i);
117 void (GLAPIENTRY *qglColor4f)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
118 void (GLAPIENTRY *qglTexCoord2f)(GLfloat s, GLfloat t);
119 void (GLAPIENTRY *qglVertex2f)(GLfloat x, GLfloat y);
120 void (GLAPIENTRY *qglVertex3f)(GLfloat x, GLfloat y, GLfloat z);
121 void (GLAPIENTRY *qglBegin)(GLenum mode);
122 void (GLAPIENTRY *qglEnd)(void);
124 void (GLAPIENTRY *qglMatrixMode)(GLenum mode);
125 void (GLAPIENTRY *qglOrtho)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val);
126 void (GLAPIENTRY *qglFrustum)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val);
127 void (GLAPIENTRY *qglViewport)(GLint x, GLint y, GLsizei width, GLsizei height);
128 //void (GLAPIENTRY *qglPushMatrix)(void);
129 //void (GLAPIENTRY *qglPopMatrix)(void);
130 void (GLAPIENTRY *qglLoadIdentity)(void);
131 void (GLAPIENTRY *qglLoadMatrixd)(const GLdouble *m);
132 void (GLAPIENTRY *qglLoadMatrixf)(const GLfloat *m);
133 //void (GLAPIENTRY *qglMultMatrixd)(const GLdouble *m);
134 //void (GLAPIENTRY *qglMultMatrixf)(const GLfloat *m);
135 //void (GLAPIENTRY *qglRotated)(GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
136 void (GLAPIENTRY *qglRotatef)(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
137 //void (GLAPIENTRY *qglScaled)(GLdouble x, GLdouble y, GLdouble z);
138 //void (GLAPIENTRY *qglScalef)(GLfloat x, GLfloat y, GLfloat z);
139 //void (GLAPIENTRY *qglTranslated)(GLdouble x, GLdouble y, GLdouble z);
140 void (GLAPIENTRY *qglTranslatef)(GLfloat x, GLfloat y, GLfloat z);
142 void (GLAPIENTRY *qglReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
144 void (GLAPIENTRY *qglStencilFunc)(GLenum func, GLint ref, GLuint mask);
145 void (GLAPIENTRY *qglStencilMask)(GLuint mask);
146 void (GLAPIENTRY *qglStencilOp)(GLenum fail, GLenum zfail, GLenum zpass);
147 void (GLAPIENTRY *qglClearStencil)(GLint s);
149 //void (GLAPIENTRY *qglTexEnvf)(GLenum target, GLenum pname, GLfloat param);
150 void (GLAPIENTRY *qglTexEnvi)(GLenum target, GLenum pname, GLint param);
151 //void (GLAPIENTRY *qglTexParameterf)(GLenum target, GLenum pname, GLfloat param);
152 void (GLAPIENTRY *qglTexParameteri)(GLenum target, GLenum pname, GLint param);
154 void (GLAPIENTRY *qglGenTextures)(GLsizei n, GLuint *textures);
155 void (GLAPIENTRY *qglDeleteTextures)(GLsizei n, const GLuint *textures);
156 void (GLAPIENTRY *qglBindTexture)(GLenum target, GLuint texture);
157 void (GLAPIENTRY *qglPrioritizeTextures)(GLsizei n, const GLuint *textures, const GLclampf *priorities);
158 GLboolean (GLAPIENTRY *qglAreTexturesResident)(GLsizei n, const GLuint *textures, GLboolean *residences);
159 GLboolean (GLAPIENTRY *qglIsTexture)(GLuint texture);
160 void (GLAPIENTRY *qglPixelStoref)(GLenum pname, GLfloat param);
161 void (GLAPIENTRY *qglPixelStorei)(GLenum pname, GLint param);
163 void (GLAPIENTRY *qglTexImage1D)(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
164 void (GLAPIENTRY *qglTexImage2D)(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
165 void (GLAPIENTRY *qglTexSubImage1D)(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels);
166 void (GLAPIENTRY *qglTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
167 void (GLAPIENTRY *qglCopyTexImage1D)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border);
168 void (GLAPIENTRY *qglCopyTexImage2D)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
169 void (GLAPIENTRY *qglCopyTexSubImage1D)(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
170 void (GLAPIENTRY *qglCopyTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
173 void (GLAPIENTRY *qglDrawRangeElementsEXT)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
175 //void (GLAPIENTRY *qglColorTableEXT)(int, int, int, int, int, const void *);
177 void (GLAPIENTRY *qglTexImage3D)(GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
178 void (GLAPIENTRY *qglTexSubImage3D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels);
179 void (GLAPIENTRY *qglCopyTexSubImage3D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
182 int GL_CheckExtension(const char *name, const gl_extensionfunctionlist_t *funcs, const char *disableparm, int silent)
185 const gl_extensionfunctionlist_t *func;
187 Con_Printf("checking for %s... ", name);
189 for (func = funcs;func && func->name;func++)
190 *func->funcvariable = NULL;
192 if (disableparm && COM_CheckParm(disableparm))
194 Con_Printf("disabled by commandline\n");
198 if (strstr(gl_extensions, name) || strstr(gl_platformextensions, name) || (strncmp(name, "GL_", 3) && strncmp(name, "WGL_", 4) && strncmp(name, "GLX_", 4) && strncmp(name, "AGL_", 4)))
200 for (func = funcs;func && func->name != NULL;func++)
202 // functions are cleared before all the extensions are evaluated
203 if (!(*func->funcvariable = (void *) GL_GetProcAddress(func->name)))
206 Con_Printf("missing function \"%s\" - broken driver!\n", func->name);
210 // delay the return so it prints all missing functions
213 Con_Printf("enabled\n");
218 Con_Printf("not detected\n");
223 static gl_extensionfunctionlist_t opengl110funcs[] =
225 {"glClearColor", (void **) &qglClearColor},
226 {"glClear", (void **) &qglClear},
227 // {"glAlphaFunc", (void **) &qglAlphaFunc},
228 {"glBlendFunc", (void **) &qglBlendFunc},
229 {"glCullFace", (void **) &qglCullFace},
230 {"glDrawBuffer", (void **) &qglDrawBuffer},
231 {"glReadBuffer", (void **) &qglReadBuffer},
232 {"glEnable", (void **) &qglEnable},
233 {"glDisable", (void **) &qglDisable},
234 // {"glIsEnabled", (void **) &qglIsEnabled},
235 {"glEnableClientState", (void **) &qglEnableClientState},
236 {"glDisableClientState", (void **) &qglDisableClientState},
237 {"glGetBooleanv", (void **) &qglGetBooleanv},
238 {"glGetDoublev", (void **) &qglGetDoublev},
239 {"glGetFloatv", (void **) &qglGetFloatv},
240 {"glGetIntegerv", (void **) &qglGetIntegerv},
241 {"glGetError", (void **) &qglGetError},
242 {"glGetString", (void **) &qglGetString},
243 {"glFinish", (void **) &qglFinish},
244 {"glFlush", (void **) &qglFlush},
245 {"glClearDepth", (void **) &qglClearDepth},
246 {"glDepthFunc", (void **) &qglDepthFunc},
247 {"glDepthMask", (void **) &qglDepthMask},
248 {"glDepthRange", (void **) &qglDepthRange},
249 {"glDrawElements", (void **) &qglDrawElements},
250 {"glColorMask", (void **) &qglColorMask},
251 {"glVertexPointer", (void **) &qglVertexPointer},
252 // {"glNormalPointer", (void **) &qglNormalPointer},
253 {"glColorPointer", (void **) &qglColorPointer},
254 {"glTexCoordPointer", (void **) &qglTexCoordPointer},
255 {"glArrayElement", (void **) &qglArrayElement},
256 {"glColor4f", (void **) &qglColor4f},
257 {"glTexCoord2f", (void **) &qglTexCoord2f},
258 {"glVertex2f", (void **) &qglVertex2f},
259 {"glVertex3f", (void **) &qglVertex3f},
260 {"glBegin", (void **) &qglBegin},
261 {"glEnd", (void **) &qglEnd},
262 {"glMatrixMode", (void **) &qglMatrixMode},
263 {"glOrtho", (void **) &qglOrtho},
264 {"glFrustum", (void **) &qglFrustum},
265 {"glViewport", (void **) &qglViewport},
266 // {"glPushMatrix", (void **) &qglPushMatrix},
267 // {"glPopMatrix", (void **) &qglPopMatrix},
268 {"glLoadIdentity", (void **) &qglLoadIdentity},
269 {"glLoadMatrixd", (void **) &qglLoadMatrixd},
270 {"glLoadMatrixf", (void **) &qglLoadMatrixf},
271 // {"glMultMatrixd", (void **) &qglMultMatrixd},
272 // {"glMultMatrixf", (void **) &qglMultMatrixf},
273 // {"glRotated", (void **) &qglRotated},
274 {"glRotatef", (void **) &qglRotatef},
275 // {"glScaled", (void **) &qglScaled},
276 // {"glScalef", (void **) &qglScalef},
277 // {"glTranslated", (void **) &qglTranslated},
278 {"glTranslatef", (void **) &qglTranslatef},
279 {"glReadPixels", (void **) &qglReadPixels},
280 {"glStencilFunc", (void **) &qglStencilFunc},
281 {"glStencilMask", (void **) &qglStencilMask},
282 {"glStencilOp", (void **) &qglStencilOp},
283 {"glClearStencil", (void **) &qglClearStencil},
284 // {"glTexEnvf", (void **) &qglTexEnvf},
285 {"glTexEnvi", (void **) &qglTexEnvi},
286 // {"glTexParameterf", (void **) &qglTexParameterf},
287 {"glTexParameteri", (void **) &qglTexParameteri},
288 {"glPixelStoref", (void **) &qglPixelStoref},
289 {"glPixelStorei", (void **) &qglPixelStorei},
290 {"glGenTextures", (void **) &qglGenTextures},
291 {"glDeleteTextures", (void **) &qglDeleteTextures},
292 {"glBindTexture", (void **) &qglBindTexture},
293 {"glPrioritizeTextures", (void **) &qglPrioritizeTextures},
294 {"glAreTexturesResident", (void **) &qglAreTexturesResident},
295 {"glIsTexture", (void **) &qglIsTexture},
296 {"glTexImage1D", (void **) &qglTexImage1D},
297 {"glTexImage2D", (void **) &qglTexImage2D},
298 {"glTexSubImage1D", (void **) &qglTexSubImage1D},
299 {"glTexSubImage2D", (void **) &qglTexSubImage2D},
300 {"glCopyTexImage1D", (void **) &qglCopyTexImage1D},
301 {"glCopyTexImage2D", (void **) &qglCopyTexImage2D},
302 {"glCopyTexSubImage1D", (void **) &qglCopyTexSubImage1D},
303 {"glCopyTexSubImage2D", (void **) &qglCopyTexSubImage2D},
307 static gl_extensionfunctionlist_t drawrangeelementsfuncs[] =
309 {"glDrawRangeElements", (void **) &qglDrawRangeElements},
313 static gl_extensionfunctionlist_t drawrangeelementsextfuncs[] =
315 {"glDrawRangeElementsEXT", (void **) &qglDrawRangeElementsEXT},
319 static gl_extensionfunctionlist_t multitexturefuncs[] =
321 {"glMultiTexCoord2fARB", (void **) &qglMultiTexCoord2f},
322 {"glActiveTextureARB", (void **) &qglActiveTexture},
323 {"glClientActiveTextureARB", (void **) &qglClientActiveTexture},
327 static gl_extensionfunctionlist_t compiledvertexarrayfuncs[] =
329 {"glLockArraysEXT", (void **) &qglLockArraysEXT},
330 {"glUnlockArraysEXT", (void **) &qglUnlockArraysEXT},
334 static gl_extensionfunctionlist_t texture3dfuncs[] =
336 {"glTexImage3D", (void **) &qglTexImage3D},
337 {"glTexSubImage3D", (void **) &qglTexSubImage3D},
338 {"glCopyTexSubImage3D", (void **) &qglCopyTexSubImage3D},
342 static gl_extensionfunctionlist_t texture3dextfuncs[] =
344 {"glTexImage3DEXT", (void **) &qglTexImage3D},
345 {"glTexSubImage3DEXT", (void **) &qglTexSubImage3D},
346 {"glCopyTexSubImage3DEXT", (void **) &qglCopyTexSubImage3D},
350 void VID_CheckExtensions(void)
352 gl_stencil = vid_stencil.integer;
353 gl_combine_extension = false;
355 gl_supportslockarrays = false;
358 if (!GL_CheckExtension("OpenGL 1.1.0", opengl110funcs, NULL, false))
359 Sys_Error("OpenGL 1.1.0 functions not found\n");
361 Con_Printf ("GL_VENDOR: %s\n", gl_vendor);
362 Con_Printf ("GL_RENDERER: %s\n", gl_renderer);
363 Con_Printf ("GL_VERSION: %s\n", gl_version);
364 Con_Printf ("GL_EXTENSIONS: %s\n", gl_extensions);
365 Con_Printf ("%s_EXTENSIONS: %s\n", gl_platform, gl_platformextensions);
367 Con_Printf("Checking OpenGL extensions...\n");
369 if (!GL_CheckExtension("glDrawRangeElements", drawrangeelementsfuncs, "-nodrawrangeelements", true))
370 GL_CheckExtension("GL_EXT_draw_range_elements", drawrangeelementsextfuncs, "-nodrawrangeelements", false);
372 if (GL_CheckExtension("GL_ARB_multitexture", multitexturefuncs, "-nomtex", false))
374 qglGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_textureunits);
375 gl_combine_extension = GL_CheckExtension("GL_ARB_texture_env_combine", NULL, "-nocombine", false) || GL_CheckExtension("GL_EXT_texture_env_combine", NULL, "-nocombine", false);
376 if (gl_combine_extension)
377 gl_dot3arb = GL_CheckExtension("GL_ARB_texture_env_dot3", NULL, "-nodot3", false);
380 gl_texture3d = GL_CheckExtension("glTexImage3D", texture3dfuncs, "-notexture3d", false) || GL_CheckExtension("GL_EXT_texture3D", texture3dextfuncs, "-notexture3d", false);
381 gl_texturecubemap = GL_CheckExtension("GL_ARB_texture_cube_map", NULL, "-nocubemap", false);
382 gl_supportslockarrays = GL_CheckExtension("GL_EXT_compiled_vertex_array", compiledvertexarrayfuncs, "-nocva", false);
384 // we don't care if it's an extension or not, they are identical functions, so keep it simple in the rendering code
385 if (qglDrawRangeElements == NULL)
386 qglDrawRangeElements = qglDrawRangeElementsEXT;
389 void Force_CenterView_f (void)
391 cl.viewangles[PITCH] = 0;
394 void IN_PreMove(void)
398 void CL_AdjustAngles(void);
399 void IN_PostMove(void)
401 // clamp after the move as well to prevent messed up rendering angles
405 void IN_Mouse(usercmd_t *cmd, float mx, float my)
407 int mouselook = (in_mlook.state & 1) || freelook.integer;
408 float mouse_x, mouse_y;
409 static float old_mouse_x = 0, old_mouse_y = 0;
411 if (m_filter.integer)
413 mouse_x = (mx + old_mouse_x) * 0.5;
414 mouse_y = (my + old_mouse_y) * 0.5;
425 // LordHavoc: viewzoom affects mouse sensitivity for sniping
426 mouse_x *= sensitivity.value * cl.viewzoom;
427 mouse_y *= sensitivity.value * cl.viewzoom;
429 // Add mouse X/Y movement to cmd
430 if ((in_strafe.state & 1) || (lookstrafe.integer && mouselook))
431 cmd->sidemove += m_side.value * mouse_x;
433 cl.viewangles[YAW] -= m_yaw.value * mouse_x;
438 if (mouselook && !(in_strafe.state & 1))
439 cl.viewangles[PITCH] += m_pitch.value * mouse_y;
442 if ((in_strafe.state & 1) && noclip_anglehack)
443 cmd->upmove -= m_forward.value * mouse_y;
445 cmd->forwardmove -= m_forward.value * mouse_y;
449 void VID_Shared_Init(void)
451 Cvar_RegisterVariable(&vid_fullscreen);
452 Cvar_RegisterVariable(&vid_width);
453 Cvar_RegisterVariable(&vid_height);
454 Cvar_RegisterVariable(&vid_bitsperpixel);
455 Cvar_RegisterVariable(&vid_stencil);
456 Cvar_RegisterVariable(&vid_mouse);
457 Cvar_RegisterVariable(&gl_combine);
458 Cvar_RegisterVariable(&in_pitch_min);
459 Cvar_RegisterVariable(&in_pitch_max);
460 Cvar_RegisterVariable(&m_filter);
461 Cmd_AddCommand("force_centerview", Force_CenterView_f);
462 Cmd_AddCommand("vid_restart", VID_Restart_f);
465 int current_vid_fullscreen;
466 int current_vid_width;
467 int current_vid_height;
468 int current_vid_bitsperpixel;
469 int current_vid_stencil;
470 extern int VID_InitMode (int fullscreen, int width, int height, int bpp, int stencil);
471 int VID_Mode(int fullscreen, int width, int height, int bpp, int stencil)
473 Con_Printf("Video: %s %dx%dx%d %s\n", fullscreen ? "fullscreen" : "window", width, height, bpp, stencil ? "with stencil" : "without stencil");
474 if (VID_InitMode(fullscreen, width, height, bpp, stencil))
476 current_vid_fullscreen = fullscreen;
477 current_vid_width = width;
478 current_vid_height = height;
479 current_vid_bitsperpixel = bpp;
480 current_vid_stencil = stencil;
481 Cvar_SetValueQuick(&vid_fullscreen, fullscreen);
482 Cvar_SetValueQuick(&vid_width, width);
483 Cvar_SetValueQuick(&vid_height, height);
484 Cvar_SetValueQuick(&vid_bitsperpixel, bpp);
485 Cvar_SetValueQuick(&vid_stencil, stencil);
492 static void VID_OpenSystems(void)
499 static void VID_CloseSystems(void)
503 R_Modules_Shutdown();
506 void VID_Restart_f(void)
508 Con_Printf("VID_Restart: changing from %s %dx%dx%dbpp %s, to %s %dx%dx%dbpp %s.\n",
509 current_vid_fullscreen ? "fullscreen" : "window", current_vid_width, current_vid_height, current_vid_bitsperpixel, current_vid_stencil ? "with stencil" : "without stencil",
510 vid_fullscreen.integer ? "fullscreen" : "window", vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_stencil.integer ? "with stencil" : "without stencil");
512 if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_stencil.integer))
514 Con_Printf("Video mode change failed\n");
515 if (!VID_Mode(current_vid_fullscreen, current_vid_width, current_vid_height, current_vid_bitsperpixel, current_vid_stencil))
516 Sys_Error("Unable to restore to last working video mode\n");
521 int vid_commandlinecheck = true;
525 if (vid_commandlinecheck)
527 // interpret command-line parameters
528 vid_commandlinecheck = false;
529 if ((i = COM_CheckParm("-window")) != 0)
530 Cvar_SetValueQuick(&vid_fullscreen, false);
531 if ((i = COM_CheckParm("-fullscreen")) != 0)
532 Cvar_SetValueQuick(&vid_fullscreen, true);
533 if ((i = COM_CheckParm("-width")) != 0)
534 Cvar_SetQuick(&vid_width, com_argv[i+1]);
535 if ((i = COM_CheckParm("-height")) != 0)
536 Cvar_SetQuick(&vid_height, com_argv[i+1]);
537 if ((i = COM_CheckParm("-bpp")) != 0)
538 Cvar_SetQuick(&vid_bitsperpixel, com_argv[i+1]);
539 if ((i = COM_CheckParm("-nostencil")) != 0)
540 Cvar_SetValueQuick(&vid_stencil, 0);
541 if ((i = COM_CheckParm("-stencil")) != 0)
542 Cvar_SetValueQuick(&vid_stencil, 1);
545 Con_Printf("Starting video system\n");
546 if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_stencil.integer))
548 Con_Printf("Desired video mode fail, trying fallbacks...\n");
549 if (!vid_stencil.integer || !VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, false))
551 if (vid_fullscreen.integer)
553 if (!VID_Mode(true, 640, 480, 16, false))
554 if (!VID_Mode(false, 640, 480, 16, false))
555 Sys_Error("Video modes failed\n");
558 Sys_Error("Windowed video failed\n");