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;
27 // GL_SGIS_texture_edge_clamp
28 int gl_support_clamptoedge = false;
30 // LordHavoc: if window is hidden, don't update screen
31 int vid_hidden = true;
32 // LordHavoc: if window is not the active window, don't hog as much CPU time,
33 // let go of the mouse, turn off sound, and restore system gamma ramps...
34 int vid_activewindow = true;
35 // LordHavoc: whether to allow use of hwgamma (disabled when window is inactive)
36 int vid_allowhwgamma = false;
38 // we don't know until we try it!
39 int vid_hardwaregammasupported = true;
40 // whether hardware gamma ramps are currently in effect
41 int vid_usinghwgamma = false;
43 unsigned short vid_gammaramps[768];
44 unsigned short vid_systemgammaramps[768];
46 cvar_t vid_fullscreen = {CVAR_SAVE, "vid_fullscreen", "1"};
47 cvar_t vid_width = {CVAR_SAVE, "vid_width", "640"};
48 cvar_t vid_height = {CVAR_SAVE, "vid_height", "480"};
49 cvar_t vid_bitsperpixel = {CVAR_SAVE, "vid_bitsperpixel", "16"};
50 cvar_t vid_stencil = {CVAR_SAVE, "vid_stencil", "0"};
52 cvar_t vid_mouse = {CVAR_SAVE, "vid_mouse", "1"};
53 cvar_t gl_combine = {0, "gl_combine", "1"};
55 cvar_t in_pitch_min = {0, "in_pitch_min", "-70"};
56 cvar_t in_pitch_max = {0, "in_pitch_max", "80"};
58 cvar_t m_filter = {CVAR_SAVE, "m_filter","0"};
60 cvar_t v_gamma = {CVAR_SAVE, "v_gamma", "1"};
61 cvar_t v_contrast = {CVAR_SAVE, "v_contrast", "1"};
62 cvar_t v_brightness = {CVAR_SAVE, "v_brightness", "0"};
63 cvar_t v_color_enable = {CVAR_SAVE, "v_color_enable", "0"};
64 cvar_t v_color_black_r = {CVAR_SAVE, "v_color_black_r", "0"};
65 cvar_t v_color_black_g = {CVAR_SAVE, "v_color_black_g", "0"};
66 cvar_t v_color_black_b = {CVAR_SAVE, "v_color_black_b", "0"};
67 cvar_t v_color_grey_r = {CVAR_SAVE, "v_color_grey_r", "0.5"};
68 cvar_t v_color_grey_g = {CVAR_SAVE, "v_color_grey_g", "0.5"};
69 cvar_t v_color_grey_b = {CVAR_SAVE, "v_color_grey_b", "0.5"};
70 cvar_t v_color_white_r = {CVAR_SAVE, "v_color_white_r", "1"};
71 cvar_t v_color_white_g = {CVAR_SAVE, "v_color_white_g", "1"};
72 cvar_t v_color_white_b = {CVAR_SAVE, "v_color_white_b", "1"};
73 cvar_t v_overbrightbits = {CVAR_SAVE, "v_overbrightbits", "0"};
74 cvar_t v_hwgamma = {0, "v_hwgamma", "1"};
76 // brand of graphics chip
77 const char *gl_vendor;
78 // graphics chip model and other information
79 const char *gl_renderer;
80 // begins with 1.0.0, 1.1.0, 1.2.0, 1.2.1, 1.3.0, 1.3.1, or 1.4.0
81 const char *gl_version;
82 // extensions list, space separated
83 const char *gl_extensions;
85 const char *gl_platform;
86 // another extensions list, containing platform-specific extensions that are
87 // not in the main list
88 const char *gl_platformextensions;
89 // name of driver library (opengl32.dll, libGL.so.1, or whatever)
92 // GL_ARB_multitexture
93 //void (GLAPIENTRY *qglMultiTexCoord2f) (GLenum, GLfloat, GLfloat);
94 void (GLAPIENTRY *qglActiveTexture) (GLenum);
95 void (GLAPIENTRY *qglClientActiveTexture) (GLenum);
97 // GL_EXT_compiled_vertex_array
98 void (GLAPIENTRY *qglLockArraysEXT) (GLint first, GLint count);
99 void (GLAPIENTRY *qglUnlockArraysEXT) (void);
102 // general GL functions
104 void (GLAPIENTRY *qglClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
106 void (GLAPIENTRY *qglClear)(GLbitfield mask);
108 //void (GLAPIENTRY *qglAlphaFunc)(GLenum func, GLclampf ref);
109 void (GLAPIENTRY *qglBlendFunc)(GLenum sfactor, GLenum dfactor);
110 void (GLAPIENTRY *qglCullFace)(GLenum mode);
112 //void (GLAPIENTRY *qglDrawBuffer)(GLenum mode);
113 //void (GLAPIENTRY *qglReadBuffer)(GLenum mode);
114 void (GLAPIENTRY *qglEnable)(GLenum cap);
115 void (GLAPIENTRY *qglDisable)(GLenum cap);
116 //GLboolean GLAPIENTRY *qglIsEnabled)(GLenum cap);
118 void (GLAPIENTRY *qglEnableClientState)(GLenum cap);
119 void (GLAPIENTRY *qglDisableClientState)(GLenum cap);
121 //void (GLAPIENTRY *qglGetBooleanv)(GLenum pname, GLboolean *params);
122 //void (GLAPIENTRY *qglGetDoublev)(GLenum pname, GLdouble *params);
123 //void (GLAPIENTRY *qglGetFloatv)(GLenum pname, GLfloat *params);
124 void (GLAPIENTRY *qglGetIntegerv)(GLenum pname, GLint *params);
126 GLenum (GLAPIENTRY *qglGetError)(void);
127 const GLubyte* (GLAPIENTRY *qglGetString)(GLenum name);
128 void (GLAPIENTRY *qglFinish)(void);
129 void (GLAPIENTRY *qglFlush)(void);
131 void (GLAPIENTRY *qglClearDepth)(GLclampd depth);
132 void (GLAPIENTRY *qglDepthFunc)(GLenum func);
133 void (GLAPIENTRY *qglDepthMask)(GLboolean flag);
134 //void (GLAPIENTRY *qglDepthRange)(GLclampd near_val, GLclampd far_val);
135 void (GLAPIENTRY *qglColorMask)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
137 void (GLAPIENTRY *qglDrawRangeElements)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
138 void (GLAPIENTRY *qglDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
139 void (GLAPIENTRY *qglVertexPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
140 //void (GLAPIENTRY *qglNormalPointer)(GLenum type, GLsizei stride, const GLvoid *ptr);
141 void (GLAPIENTRY *qglColorPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
142 void (GLAPIENTRY *qglTexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
143 //void (GLAPIENTRY *qglArrayElement)(GLint i);
145 void (GLAPIENTRY *qglColor4f)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
146 //void (GLAPIENTRY *qglTexCoord2f)(GLfloat s, GLfloat t);
147 //void (GLAPIENTRY *qglVertex2f)(GLfloat x, GLfloat y);
148 //void (GLAPIENTRY *qglVertex3f)(GLfloat x, GLfloat y, GLfloat z);
149 //void (GLAPIENTRY *qglBegin)(GLenum mode);
150 //void (GLAPIENTRY *qglEnd)(void);
152 void (GLAPIENTRY *qglMatrixMode)(GLenum mode);
153 void (GLAPIENTRY *qglOrtho)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val);
154 void (GLAPIENTRY *qglFrustum)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val);
155 void (GLAPIENTRY *qglViewport)(GLint x, GLint y, GLsizei width, GLsizei height);
156 //void (GLAPIENTRY *qglPushMatrix)(void);
157 //void (GLAPIENTRY *qglPopMatrix)(void);
158 void (GLAPIENTRY *qglLoadIdentity)(void);
159 //void (GLAPIENTRY *qglLoadMatrixd)(const GLdouble *m);
160 void (GLAPIENTRY *qglLoadMatrixf)(const GLfloat *m);
161 //void (GLAPIENTRY *qglMultMatrixd)(const GLdouble *m);
162 //void (GLAPIENTRY *qglMultMatrixf)(const GLfloat *m);
163 //void (GLAPIENTRY *qglRotated)(GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
164 //void (GLAPIENTRY *qglRotatef)(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
165 //void (GLAPIENTRY *qglScaled)(GLdouble x, GLdouble y, GLdouble z);
166 //void (GLAPIENTRY *qglScalef)(GLfloat x, GLfloat y, GLfloat z);
167 //void (GLAPIENTRY *qglTranslated)(GLdouble x, GLdouble y, GLdouble z);
168 //void (GLAPIENTRY *qglTranslatef)(GLfloat x, GLfloat y, GLfloat z);
170 void (GLAPIENTRY *qglReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
172 void (GLAPIENTRY *qglStencilFunc)(GLenum func, GLint ref, GLuint mask);
173 void (GLAPIENTRY *qglStencilMask)(GLuint mask);
174 void (GLAPIENTRY *qglStencilOp)(GLenum fail, GLenum zfail, GLenum zpass);
175 void (GLAPIENTRY *qglClearStencil)(GLint s);
177 //void (GLAPIENTRY *qglTexEnvf)(GLenum target, GLenum pname, GLfloat param);
178 void (GLAPIENTRY *qglTexEnvi)(GLenum target, GLenum pname, GLint param);
179 //void (GLAPIENTRY *qglTexParameterf)(GLenum target, GLenum pname, GLfloat param);
180 //void (GLAPIENTRY *qglTexParameterfv)(GLenum target, GLenum pname, GLfloat *params);
181 void (GLAPIENTRY *qglTexParameteri)(GLenum target, GLenum pname, GLint param);
183 void (GLAPIENTRY *qglGenTextures)(GLsizei n, GLuint *textures);
184 void (GLAPIENTRY *qglDeleteTextures)(GLsizei n, const GLuint *textures);
185 void (GLAPIENTRY *qglBindTexture)(GLenum target, GLuint texture);
186 //void (GLAPIENTRY *qglPrioritizeTextures)(GLsizei n, const GLuint *textures, const GLclampf *priorities);
187 //GLboolean (GLAPIENTRY *qglAreTexturesResident)(GLsizei n, const GLuint *textures, GLboolean *residences);
188 GLboolean (GLAPIENTRY *qglIsTexture)(GLuint texture);
189 //void (GLAPIENTRY *qglPixelStoref)(GLenum pname, GLfloat param);
190 void (GLAPIENTRY *qglPixelStorei)(GLenum pname, GLint param);
192 void (GLAPIENTRY *qglTexImage1D)(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
193 void (GLAPIENTRY *qglTexImage2D)(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
194 void (GLAPIENTRY *qglTexSubImage1D)(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels);
195 void (GLAPIENTRY *qglTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
196 void (GLAPIENTRY *qglCopyTexImage1D)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border);
197 void (GLAPIENTRY *qglCopyTexImage2D)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
198 void (GLAPIENTRY *qglCopyTexSubImage1D)(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
199 void (GLAPIENTRY *qglCopyTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
202 void (GLAPIENTRY *qglDrawRangeElementsEXT)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
204 //void (GLAPIENTRY *qglColorTableEXT)(int, int, int, int, int, const void *);
206 void (GLAPIENTRY *qglTexImage3D)(GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
207 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);
208 void (GLAPIENTRY *qglCopyTexSubImage3D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
210 void (GLAPIENTRY *qglScissor)(GLint x, GLint y, GLsizei width, GLsizei height);
212 void (GLAPIENTRY *qglPolygonOffset)(GLfloat factor, GLfloat units);
214 int GL_CheckExtension(const char *name, const dllfunction_t *funcs, const char *disableparm, int silent)
217 const dllfunction_t *func;
219 Con_Printf("checking for %s... ", name);
221 for (func = funcs;func && func->name;func++)
222 *func->funcvariable = NULL;
224 if (disableparm && COM_CheckParm(disableparm))
226 Con_Printf("disabled by commandline\n");
230 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)))
232 for (func = funcs;func && func->name != NULL;func++)
234 // functions are cleared before all the extensions are evaluated
235 if (!(*func->funcvariable = (void *) GL_GetProcAddress(func->name)))
238 Con_Printf("missing function \"%s\" - broken driver!\n", func->name);
242 // delay the return so it prints all missing functions
245 Con_Printf("enabled\n");
250 Con_Printf("not detected\n");
255 static dllfunction_t opengl110funcs[] =
257 {"glClearColor", (void **) &qglClearColor},
258 {"glClear", (void **) &qglClear},
259 // {"glAlphaFunc", (void **) &qglAlphaFunc},
260 {"glBlendFunc", (void **) &qglBlendFunc},
261 {"glCullFace", (void **) &qglCullFace},
262 // {"glDrawBuffer", (void **) &qglDrawBuffer},
263 // {"glReadBuffer", (void **) &qglReadBuffer},
264 {"glEnable", (void **) &qglEnable},
265 {"glDisable", (void **) &qglDisable},
266 // {"glIsEnabled", (void **) &qglIsEnabled},
267 {"glEnableClientState", (void **) &qglEnableClientState},
268 {"glDisableClientState", (void **) &qglDisableClientState},
269 // {"glGetBooleanv", (void **) &qglGetBooleanv},
270 // {"glGetDoublev", (void **) &qglGetDoublev},
271 // {"glGetFloatv", (void **) &qglGetFloatv},
272 {"glGetIntegerv", (void **) &qglGetIntegerv},
273 {"glGetError", (void **) &qglGetError},
274 {"glGetString", (void **) &qglGetString},
275 {"glFinish", (void **) &qglFinish},
276 {"glFlush", (void **) &qglFlush},
277 {"glClearDepth", (void **) &qglClearDepth},
278 {"glDepthFunc", (void **) &qglDepthFunc},
279 {"glDepthMask", (void **) &qglDepthMask},
280 // {"glDepthRange", (void **) &qglDepthRange},
281 {"glDrawElements", (void **) &qglDrawElements},
282 {"glColorMask", (void **) &qglColorMask},
283 {"glVertexPointer", (void **) &qglVertexPointer},
284 // {"glNormalPointer", (void **) &qglNormalPointer},
285 {"glColorPointer", (void **) &qglColorPointer},
286 {"glTexCoordPointer", (void **) &qglTexCoordPointer},
287 // {"glArrayElement", (void **) &qglArrayElement},
288 {"glColor4f", (void **) &qglColor4f},
289 // {"glTexCoord2f", (void **) &qglTexCoord2f},
290 // {"glVertex2f", (void **) &qglVertex2f},
291 // {"glVertex3f", (void **) &qglVertex3f},
292 // {"glBegin", (void **) &qglBegin},
293 // {"glEnd", (void **) &qglEnd},
294 {"glMatrixMode", (void **) &qglMatrixMode},
295 {"glOrtho", (void **) &qglOrtho},
296 {"glFrustum", (void **) &qglFrustum},
297 {"glViewport", (void **) &qglViewport},
298 // {"glPushMatrix", (void **) &qglPushMatrix},
299 // {"glPopMatrix", (void **) &qglPopMatrix},
300 {"glLoadIdentity", (void **) &qglLoadIdentity},
301 // {"glLoadMatrixd", (void **) &qglLoadMatrixd},
302 {"glLoadMatrixf", (void **) &qglLoadMatrixf},
303 // {"glMultMatrixd", (void **) &qglMultMatrixd},
304 // {"glMultMatrixf", (void **) &qglMultMatrixf},
305 // {"glRotated", (void **) &qglRotated},
306 // {"glRotatef", (void **) &qglRotatef},
307 // {"glScaled", (void **) &qglScaled},
308 // {"glScalef", (void **) &qglScalef},
309 // {"glTranslated", (void **) &qglTranslated},
310 // {"glTranslatef", (void **) &qglTranslatef},
311 {"glReadPixels", (void **) &qglReadPixels},
312 {"glStencilFunc", (void **) &qglStencilFunc},
313 {"glStencilMask", (void **) &qglStencilMask},
314 {"glStencilOp", (void **) &qglStencilOp},
315 {"glClearStencil", (void **) &qglClearStencil},
316 // {"glTexEnvf", (void **) &qglTexEnvf},
317 {"glTexEnvi", (void **) &qglTexEnvi},
318 // {"glTexParameterf", (void **) &qglTexParameterf},
319 // {"glTexParameterfv", (void **) &qglTexParameterfv},
320 {"glTexParameteri", (void **) &qglTexParameteri},
321 // {"glPixelStoref", (void **) &qglPixelStoref},
322 {"glPixelStorei", (void **) &qglPixelStorei},
323 {"glGenTextures", (void **) &qglGenTextures},
324 {"glDeleteTextures", (void **) &qglDeleteTextures},
325 {"glBindTexture", (void **) &qglBindTexture},
326 // {"glPrioritizeTextures", (void **) &qglPrioritizeTextures},
327 // {"glAreTexturesResident", (void **) &qglAreTexturesResident},
328 {"glIsTexture", (void **) &qglIsTexture},
329 {"glTexImage1D", (void **) &qglTexImage1D},
330 {"glTexImage2D", (void **) &qglTexImage2D},
331 {"glTexSubImage1D", (void **) &qglTexSubImage1D},
332 {"glTexSubImage2D", (void **) &qglTexSubImage2D},
333 {"glCopyTexImage1D", (void **) &qglCopyTexImage1D},
334 {"glCopyTexImage2D", (void **) &qglCopyTexImage2D},
335 {"glCopyTexSubImage1D", (void **) &qglCopyTexSubImage1D},
336 {"glCopyTexSubImage2D", (void **) &qglCopyTexSubImage2D},
337 {"glScissor", (void **) &qglScissor},
338 {"glPolygonOffset", (void **) &qglPolygonOffset},
342 static dllfunction_t drawrangeelementsfuncs[] =
344 {"glDrawRangeElements", (void **) &qglDrawRangeElements},
348 static dllfunction_t drawrangeelementsextfuncs[] =
350 {"glDrawRangeElementsEXT", (void **) &qglDrawRangeElementsEXT},
354 static dllfunction_t multitexturefuncs[] =
356 //{"glMultiTexCoord2fARB", (void **) &qglMultiTexCoord2f},
357 {"glActiveTextureARB", (void **) &qglActiveTexture},
358 {"glClientActiveTextureARB", (void **) &qglClientActiveTexture},
362 static dllfunction_t compiledvertexarrayfuncs[] =
364 {"glLockArraysEXT", (void **) &qglLockArraysEXT},
365 {"glUnlockArraysEXT", (void **) &qglUnlockArraysEXT},
369 static dllfunction_t texture3dextfuncs[] =
371 {"glTexImage3DEXT", (void **) &qglTexImage3D},
372 {"glTexSubImage3DEXT", (void **) &qglTexSubImage3D},
373 {"glCopyTexSubImage3DEXT", (void **) &qglCopyTexSubImage3D},
377 void VID_CheckExtensions(void)
379 gl_stencil = vid_stencil.integer;
380 gl_combine_extension = false;
382 gl_supportslockarrays = false;
384 gl_support_clamptoedge = false;
386 if (!GL_CheckExtension("OpenGL 1.1.0", opengl110funcs, NULL, false))
387 Sys_Error("OpenGL 1.1.0 functions not found\n");
389 Con_Printf ("GL_VENDOR: %s\n", gl_vendor);
390 Con_Printf ("GL_RENDERER: %s\n", gl_renderer);
391 Con_Printf ("GL_VERSION: %s\n", gl_version);
392 Con_Printf ("GL_EXTENSIONS: %s\n", gl_extensions);
393 Con_Printf ("%s_EXTENSIONS: %s\n", gl_platform, gl_platformextensions);
395 Con_Printf("Checking OpenGL extensions...\n");
397 if (!GL_CheckExtension("glDrawRangeElements", drawrangeelementsfuncs, "-nodrawrangeelements", true))
398 GL_CheckExtension("GL_EXT_draw_range_elements", drawrangeelementsextfuncs, "-nodrawrangeelements", false);
400 if (GL_CheckExtension("GL_ARB_multitexture", multitexturefuncs, "-nomtex", false))
402 qglGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_textureunits);
403 gl_combine_extension = GL_CheckExtension("GL_ARB_texture_env_combine", NULL, "-nocombine", false) || GL_CheckExtension("GL_EXT_texture_env_combine", NULL, "-nocombine", false);
404 if (gl_combine_extension)
405 gl_dot3arb = GL_CheckExtension("GL_ARB_texture_env_dot3", NULL, "-nodot3", false);
408 gl_texture3d = GL_CheckExtension("GL_EXT_texture3D", texture3dextfuncs, "-notexture3d", false);
409 gl_texturecubemap = GL_CheckExtension("GL_ARB_texture_cube_map", NULL, "-nocubemap", false);
410 gl_supportslockarrays = GL_CheckExtension("GL_EXT_compiled_vertex_array", compiledvertexarrayfuncs, "-nocva", false);
411 gl_support_clamptoedge = GL_CheckExtension("GL_EXT_texture_edge_clamp", NULL, "-noedgeclamp", false) || GL_CheckExtension("GL_SGIS_texture_edge_clamp", NULL, "-noedgeclamp", false);
413 // we don't care if it's an extension or not, they are identical functions, so keep it simple in the rendering code
414 if (qglDrawRangeElements == NULL)
415 qglDrawRangeElements = qglDrawRangeElementsEXT;
418 void Force_CenterView_f (void)
420 cl.viewangles[PITCH] = 0;
423 void IN_PreMove(void)
427 void CL_AdjustAngles(void);
428 void IN_PostMove(void)
430 // clamp after the move as well to prevent messed up rendering angles
434 void IN_Mouse(usercmd_t *cmd, float mx, float my)
436 int mouselook = (in_mlook.state & 1) || freelook.integer;
437 float mouse_x, mouse_y;
438 static float old_mouse_x = 0, old_mouse_y = 0;
440 if (m_filter.integer)
442 mouse_x = (mx + old_mouse_x) * 0.5;
443 mouse_y = (my + old_mouse_y) * 0.5;
454 // LordHavoc: viewzoom affects mouse sensitivity for sniping
455 mouse_x *= sensitivity.value * cl.viewzoom;
456 mouse_y *= sensitivity.value * cl.viewzoom;
458 // Add mouse X/Y movement to cmd
459 if ((in_strafe.state & 1) || (lookstrafe.integer && mouselook))
460 cmd->sidemove += m_side.value * mouse_x;
462 cl.viewangles[YAW] -= m_yaw.value * mouse_x;
467 if (mouselook && !(in_strafe.state & 1))
468 cl.viewangles[PITCH] += m_pitch.value * mouse_y;
471 if ((in_strafe.state & 1) && noclip_anglehack)
472 cmd->upmove -= m_forward.value * mouse_y;
474 cmd->forwardmove -= m_forward.value * mouse_y;
478 static float cachegamma, cachebrightness, cachecontrast, cacheblack[3], cachegrey[3], cachewhite[3];
479 static int cacheoverbrightbits = -1, cachecolorenable, cachehwgamma;
480 #define BOUNDCVAR(cvar, m1, m2) c = &(cvar);f = bound(m1, c->value, m2);if (c->value != f) Cvar_SetValueQuick(c, f);
481 void VID_UpdateGamma(qboolean force)
486 // LordHavoc: don't mess with gamma tables if running dedicated
487 if (cls.state == ca_dedicated)
491 && vid_usinghwgamma == (vid_allowhwgamma && v_hwgamma.integer)
492 && v_overbrightbits.integer == cacheoverbrightbits
493 && v_gamma.value == cachegamma
494 && v_contrast.value == cachecontrast
495 && v_brightness.value == cachebrightness
496 && cachecolorenable == v_color_enable.integer
497 && cacheblack[0] == v_color_black_r.value
498 && cacheblack[1] == v_color_black_g.value
499 && cacheblack[2] == v_color_black_b.value
500 && cachegrey[0] == v_color_grey_r.value
501 && cachegrey[1] == v_color_grey_g.value
502 && cachegrey[2] == v_color_grey_b.value
503 && cachewhite[0] == v_color_white_r.value
504 && cachewhite[1] == v_color_white_g.value
505 && cachewhite[2] == v_color_white_b.value)
508 if (vid_allowhwgamma && v_hwgamma.integer)
510 if (!vid_usinghwgamma)
512 vid_usinghwgamma = true;
513 vid_hardwaregammasupported = VID_GetGamma(vid_systemgammaramps);
516 BOUNDCVAR(v_gamma, 0.1, 5);cachegamma = v_gamma.value;
517 BOUNDCVAR(v_contrast, 1, 5);cachecontrast = v_contrast.value;
518 BOUNDCVAR(v_brightness, 0, 0.8);cachebrightness = v_brightness.value;
519 BOUNDCVAR(v_color_black_r, 0, 0.8);cacheblack[0] = v_color_black_r.value;
520 BOUNDCVAR(v_color_black_g, 0, 0.8);cacheblack[1] = v_color_black_g.value;
521 BOUNDCVAR(v_color_black_b, 0, 0.8);cacheblack[2] = v_color_black_b.value;
522 BOUNDCVAR(v_color_grey_r, 0, 0.95);cachegrey[0] = v_color_grey_r.value;
523 BOUNDCVAR(v_color_grey_g, 0, 0.95);cachegrey[1] = v_color_grey_g.value;
524 BOUNDCVAR(v_color_grey_b, 0, 0.95);cachegrey[2] = v_color_grey_b.value;
525 BOUNDCVAR(v_color_white_r, 1, 5);cachewhite[0] = v_color_white_r.value;
526 BOUNDCVAR(v_color_white_g, 1, 5);cachewhite[1] = v_color_white_g.value;
527 BOUNDCVAR(v_color_white_b, 1, 5);cachewhite[2] = v_color_white_b.value;
528 cachecolorenable = v_color_enable.integer;
529 cacheoverbrightbits = v_overbrightbits.integer;
530 cachehwgamma = v_hwgamma.integer;
532 if (cachecolorenable)
534 BuildGammaTable16((float) (1 << cacheoverbrightbits), invpow(0.5, 1 - cachegrey[0]), cachewhite[0], cacheblack[0], vid_gammaramps);
535 BuildGammaTable16((float) (1 << cacheoverbrightbits), invpow(0.5, 1 - cachegrey[1]), cachewhite[1], cacheblack[1], vid_gammaramps + 256);
536 BuildGammaTable16((float) (1 << cacheoverbrightbits), invpow(0.5, 1 - cachegrey[2]), cachewhite[2], cacheblack[2], vid_gammaramps + 512);
540 BuildGammaTable16((float) (1 << cacheoverbrightbits), cachegamma, cachecontrast, cachebrightness, vid_gammaramps);
541 BuildGammaTable16((float) (1 << cacheoverbrightbits), cachegamma, cachecontrast, cachebrightness, vid_gammaramps + 256);
542 BuildGammaTable16((float) (1 << cacheoverbrightbits), cachegamma, cachecontrast, cachebrightness, vid_gammaramps + 512);
545 vid_hardwaregammasupported = VID_SetGamma(vid_gammaramps);
549 if (vid_usinghwgamma)
551 vid_usinghwgamma = false;
552 vid_hardwaregammasupported = VID_SetGamma(vid_systemgammaramps);
557 void VID_RestoreSystemGamma(void)
559 if (vid_usinghwgamma)
561 vid_usinghwgamma = false;
562 VID_SetGamma(vid_systemgammaramps);
566 void VID_Shared_Init(void)
568 Cvar_RegisterVariable(&v_gamma);
569 Cvar_RegisterVariable(&v_brightness);
570 Cvar_RegisterVariable(&v_contrast);
572 Cvar_RegisterVariable(&v_color_enable);
573 Cvar_RegisterVariable(&v_color_black_r);
574 Cvar_RegisterVariable(&v_color_black_g);
575 Cvar_RegisterVariable(&v_color_black_b);
576 Cvar_RegisterVariable(&v_color_grey_r);
577 Cvar_RegisterVariable(&v_color_grey_g);
578 Cvar_RegisterVariable(&v_color_grey_b);
579 Cvar_RegisterVariable(&v_color_white_r);
580 Cvar_RegisterVariable(&v_color_white_g);
581 Cvar_RegisterVariable(&v_color_white_b);
583 Cvar_RegisterVariable(&v_hwgamma);
584 Cvar_RegisterVariable(&v_overbrightbits);
586 Cvar_RegisterVariable(&vid_fullscreen);
587 Cvar_RegisterVariable(&vid_width);
588 Cvar_RegisterVariable(&vid_height);
589 Cvar_RegisterVariable(&vid_bitsperpixel);
590 Cvar_RegisterVariable(&vid_stencil);
591 Cvar_RegisterVariable(&vid_mouse);
592 Cvar_RegisterVariable(&gl_combine);
593 Cvar_RegisterVariable(&in_pitch_min);
594 Cvar_RegisterVariable(&in_pitch_max);
595 Cvar_RegisterVariable(&m_filter);
596 Cmd_AddCommand("force_centerview", Force_CenterView_f);
597 Cmd_AddCommand("vid_restart", VID_Restart_f);
600 int current_vid_fullscreen;
601 int current_vid_width;
602 int current_vid_height;
603 int current_vid_bitsperpixel;
604 int current_vid_stencil;
605 extern int VID_InitMode (int fullscreen, int width, int height, int bpp, int stencil);
606 int VID_Mode(int fullscreen, int width, int height, int bpp, int stencil)
608 Con_Printf("Video: %s %dx%dx%d %s\n", fullscreen ? "fullscreen" : "window", width, height, bpp, stencil ? "with stencil" : "without stencil");
609 if (VID_InitMode(fullscreen, width, height, bpp, stencil))
611 current_vid_fullscreen = fullscreen;
612 current_vid_width = width;
613 current_vid_height = height;
614 current_vid_bitsperpixel = bpp;
615 current_vid_stencil = stencil;
616 Cvar_SetValueQuick(&vid_fullscreen, fullscreen);
617 Cvar_SetValueQuick(&vid_width, width);
618 Cvar_SetValueQuick(&vid_height, height);
619 Cvar_SetValueQuick(&vid_bitsperpixel, bpp);
620 Cvar_SetValueQuick(&vid_stencil, stencil);
627 static void VID_OpenSystems(void)
634 static void VID_CloseSystems(void)
638 R_Modules_Shutdown();
641 void VID_Restart_f(void)
643 Con_Printf("VID_Restart: changing from %s %dx%dx%dbpp %s, to %s %dx%dx%dbpp %s.\n",
644 current_vid_fullscreen ? "fullscreen" : "window", current_vid_width, current_vid_height, current_vid_bitsperpixel, current_vid_stencil ? "with stencil" : "without stencil",
645 vid_fullscreen.integer ? "fullscreen" : "window", vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_stencil.integer ? "with stencil" : "without stencil");
647 if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_stencil.integer))
649 Con_Printf("Video mode change failed\n");
650 if (!VID_Mode(current_vid_fullscreen, current_vid_width, current_vid_height, current_vid_bitsperpixel, current_vid_stencil))
651 Sys_Error("Unable to restore to last working video mode\n");
656 int vid_commandlinecheck = true;
659 int i, width, height;
660 if (vid_commandlinecheck)
662 // interpret command-line parameters
663 vid_commandlinecheck = false;
664 if ((i = COM_CheckParm("-window")) != 0)
665 Cvar_SetValueQuick(&vid_fullscreen, false);
666 if ((i = COM_CheckParm("-fullscreen")) != 0)
667 Cvar_SetValueQuick(&vid_fullscreen, true);
670 if ((i = COM_CheckParm("-width")) != 0)
671 width = atoi(com_argv[i+1]);
672 if ((i = COM_CheckParm("-height")) != 0)
673 height = atoi(com_argv[i+1]);
675 width = height * 4 / 3;
677 height = width * 3 / 4;
679 Cvar_SetValueQuick(&vid_width, width);
681 Cvar_SetValueQuick(&vid_height, height);
682 if ((i = COM_CheckParm("-bpp")) != 0)
683 Cvar_SetQuick(&vid_bitsperpixel, com_argv[i+1]);
684 if ((i = COM_CheckParm("-nostencil")) != 0)
685 Cvar_SetValueQuick(&vid_stencil, 0);
686 if ((i = COM_CheckParm("-stencil")) != 0)
687 Cvar_SetValueQuick(&vid_stencil, 1);
690 if (vid_stencil.integer && vid_bitsperpixel.integer != 32)
692 Con_Printf("vid_stencil not allowed without vid_bitsperpixel 32, turning off vid_stencil\n");
693 Cvar_SetValueQuick(&vid_stencil, 0);
696 Con_Printf("Starting video system\n");
697 if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, vid_stencil.integer))
699 Con_Printf("Desired video mode fail, trying fallbacks...\n");
700 if (!vid_stencil.integer || !VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer, false))
702 if (vid_fullscreen.integer)
704 if (!VID_Mode(true, 640, 480, 16, false))
705 if (!VID_Mode(false, 640, 480, 16, false))
706 Sys_Error("Video modes failed\n");
709 Sys_Error("Windowed video failed\n");