4 // Tell startup code that we have a client
5 int cl_available = true;
10 // LordHavoc: these are only set in wgl
11 qboolean isG200 = false; // LordHavoc: the Matrox G200 can't do per pixel alpha, and it uses a D3D driver for GL... ugh...
12 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.
14 // AK FIXME -> input_dest
15 qboolean in_client_mouse = true;
17 // AK where should it be placed ?
18 float in_mouse_x, in_mouse_y;
20 // GL_ARB_multitexture
21 int gl_textureunits = 0;
22 // GL_ARB_texture_env_combine or GL_EXT_texture_env_combine
23 int gl_combine_extension = false;
24 // GL_EXT_compiled_vertex_array
25 int gl_supportslockarrays = false;
26 // GLX_SGI_video_sync or WGL_EXT_swap_control
27 int gl_videosyncavailable = false;
29 int gl_stencil = false;
30 // 3D textures available
31 int gl_texture3d = false;
32 // GL_ARB_texture_cubemap
33 int gl_texturecubemap = false;
34 // GL_ARB_texture_env_dot3
35 int gl_dot3arb = false;
36 // GL_SGIS_texture_edge_clamp
37 int gl_support_clamptoedge = false;
38 // GL_NV_vertex_array_range
39 int gl_support_var = false;
40 // GL_NV_vertex_array_range2
41 int gl_support_var2 = false;
42 // GL_EXT_texture_filter_anisotropic
43 int gl_support_anisotropy = false;
44 // GL_NV_texture_shader
45 int gl_textureshader = false;
47 // LordHavoc: if window is hidden, don't update screen
48 int vid_hidden = true;
49 // LordHavoc: if window is not the active window, don't hog as much CPU time,
50 // let go of the mouse, turn off sound, and restore system gamma ramps...
51 int vid_activewindow = true;
53 // we don't know until we try it!
54 cvar_t vid_hardwaregammasupported = {CVAR_READONLY,"vid_hardwaregammasupported","1"};
55 // whether hardware gamma ramps are currently in effect
56 int vid_usinghwgamma = false;
58 unsigned short vid_gammaramps[768];
59 unsigned short vid_systemgammaramps[768];
61 cvar_t vid_fullscreen = {CVAR_SAVE, "vid_fullscreen", "1"};
62 cvar_t vid_width = {CVAR_SAVE, "vid_width", "640"};
63 cvar_t vid_height = {CVAR_SAVE, "vid_height", "480"};
64 cvar_t vid_bitsperpixel = {CVAR_SAVE, "vid_bitsperpixel", "32"};
66 cvar_t vid_mouse = {CVAR_SAVE, "vid_mouse", "1"};
67 cvar_t gl_combine = {CVAR_SAVE, "gl_combine", "1"};
69 cvar_t in_pitch_min = {0, "in_pitch_min", "-70"};
70 cvar_t in_pitch_max = {0, "in_pitch_max", "80"};
72 cvar_t m_filter = {CVAR_SAVE, "m_filter","0"};
74 cvar_t v_gamma = {CVAR_SAVE, "v_gamma", "1"};
75 cvar_t v_contrast = {CVAR_SAVE, "v_contrast", "1"};
76 cvar_t v_brightness = {CVAR_SAVE, "v_brightness", "0"};
77 cvar_t v_color_enable = {CVAR_SAVE, "v_color_enable", "0"};
78 cvar_t v_color_black_r = {CVAR_SAVE, "v_color_black_r", "0"};
79 cvar_t v_color_black_g = {CVAR_SAVE, "v_color_black_g", "0"};
80 cvar_t v_color_black_b = {CVAR_SAVE, "v_color_black_b", "0"};
81 cvar_t v_color_grey_r = {CVAR_SAVE, "v_color_grey_r", "0.5"};
82 cvar_t v_color_grey_g = {CVAR_SAVE, "v_color_grey_g", "0.5"};
83 cvar_t v_color_grey_b = {CVAR_SAVE, "v_color_grey_b", "0.5"};
84 cvar_t v_color_white_r = {CVAR_SAVE, "v_color_white_r", "1"};
85 cvar_t v_color_white_g = {CVAR_SAVE, "v_color_white_g", "1"};
86 cvar_t v_color_white_b = {CVAR_SAVE, "v_color_white_b", "1"};
87 cvar_t v_hwgamma = {CVAR_SAVE, "v_hwgamma", "1"};
88 cvar_t v_psycho = {0, "v_psycho", "0"};
90 // brand of graphics chip
91 const char *gl_vendor;
92 // graphics chip model and other information
93 const char *gl_renderer;
94 // begins with 1.0.0, 1.1.0, 1.2.0, 1.2.1, 1.3.0, 1.3.1, or 1.4.0
95 const char *gl_version;
96 // extensions list, space separated
97 const char *gl_extensions;
99 const char *gl_platform;
100 // another extensions list, containing platform-specific extensions that are
101 // not in the main list
102 const char *gl_platformextensions;
103 // name of driver library (opengl32.dll, libGL.so.1, or whatever)
106 // GL_ARB_multitexture
107 void (GLAPIENTRY *qglMultiTexCoord2f) (GLenum, GLfloat, GLfloat);
108 void (GLAPIENTRY *qglMultiTexCoord3f) (GLenum, GLfloat, GLfloat, GLfloat);
109 void (GLAPIENTRY *qglActiveTexture) (GLenum);
110 void (GLAPIENTRY *qglClientActiveTexture) (GLenum);
112 // GL_EXT_compiled_vertex_array
113 void (GLAPIENTRY *qglLockArraysEXT) (GLint first, GLint count);
114 void (GLAPIENTRY *qglUnlockArraysEXT) (void);
116 //GL_NV_vertex_array_range
117 GLvoid *(GLAPIENTRY *qglAllocateMemoryNV)(GLsizei size, GLfloat readFrequency, GLfloat writeFrequency, GLfloat priority);
118 GLvoid (GLAPIENTRY *qglFreeMemoryNV)(GLvoid *pointer);
119 GLvoid (GLAPIENTRY *qglVertexArrayRangeNV)(GLsizei length, GLvoid *pointer);
120 GLvoid (GLAPIENTRY *qglFlushVertexArrayRangeNV)(GLvoid);
122 // general GL functions
124 void (GLAPIENTRY *qglClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
126 void (GLAPIENTRY *qglClear)(GLbitfield mask);
128 //void (GLAPIENTRY *qglAlphaFunc)(GLenum func, GLclampf ref);
129 void (GLAPIENTRY *qglBlendFunc)(GLenum sfactor, GLenum dfactor);
130 void (GLAPIENTRY *qglCullFace)(GLenum mode);
132 //void (GLAPIENTRY *qglDrawBuffer)(GLenum mode);
133 //void (GLAPIENTRY *qglReadBuffer)(GLenum mode);
134 void (GLAPIENTRY *qglEnable)(GLenum cap);
135 void (GLAPIENTRY *qglDisable)(GLenum cap);
136 GLboolean (GLAPIENTRY *qglIsEnabled)(GLenum cap);
138 void (GLAPIENTRY *qglEnableClientState)(GLenum cap);
139 void (GLAPIENTRY *qglDisableClientState)(GLenum cap);
141 //void (GLAPIENTRY *qglGetBooleanv)(GLenum pname, GLboolean *params);
142 //void (GLAPIENTRY *qglGetDoublev)(GLenum pname, GLdouble *params);
143 //void (GLAPIENTRY *qglGetFloatv)(GLenum pname, GLfloat *params);
144 void (GLAPIENTRY *qglGetIntegerv)(GLenum pname, GLint *params);
146 GLenum (GLAPIENTRY *qglGetError)(void);
147 const GLubyte* (GLAPIENTRY *qglGetString)(GLenum name);
148 void (GLAPIENTRY *qglFinish)(void);
149 void (GLAPIENTRY *qglFlush)(void);
151 void (GLAPIENTRY *qglClearDepth)(GLclampd depth);
152 void (GLAPIENTRY *qglDepthFunc)(GLenum func);
153 void (GLAPIENTRY *qglDepthMask)(GLboolean flag);
154 void (GLAPIENTRY *qglDepthRange)(GLclampd near_val, GLclampd far_val);
155 void (GLAPIENTRY *qglColorMask)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
157 void (GLAPIENTRY *qglDrawRangeElements)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
158 void (GLAPIENTRY *qglDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
159 void (GLAPIENTRY *qglVertexPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
160 void (GLAPIENTRY *qglNormalPointer)(GLenum type, GLsizei stride, const GLvoid *ptr);
161 void (GLAPIENTRY *qglColorPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
162 void (GLAPIENTRY *qglTexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
163 void (GLAPIENTRY *qglArrayElement)(GLint i);
165 void (GLAPIENTRY *qglColor4f)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
166 void (GLAPIENTRY *qglTexCoord2f)(GLfloat s, GLfloat t);
167 void (GLAPIENTRY *qglTexCoord2f)(GLfloat s, GLfloat t);
168 void (GLAPIENTRY *qglTexCoord3f)(GLfloat s, GLfloat t, GLfloat r);
169 void (GLAPIENTRY *qglVertex2f)(GLfloat x, GLfloat y);
170 void (GLAPIENTRY *qglVertex3f)(GLfloat x, GLfloat y, GLfloat z);
171 void (GLAPIENTRY *qglBegin)(GLenum mode);
172 void (GLAPIENTRY *qglEnd)(void);
174 void (GLAPIENTRY *qglMatrixMode)(GLenum mode);
175 void (GLAPIENTRY *qglOrtho)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val);
176 void (GLAPIENTRY *qglFrustum)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val);
177 void (GLAPIENTRY *qglViewport)(GLint x, GLint y, GLsizei width, GLsizei height);
178 //void (GLAPIENTRY *qglPushMatrix)(void);
179 //void (GLAPIENTRY *qglPopMatrix)(void);
180 void (GLAPIENTRY *qglLoadIdentity)(void);
181 //void (GLAPIENTRY *qglLoadMatrixd)(const GLdouble *m);
182 void (GLAPIENTRY *qglLoadMatrixf)(const GLfloat *m);
183 //void (GLAPIENTRY *qglMultMatrixd)(const GLdouble *m);
184 //void (GLAPIENTRY *qglMultMatrixf)(const GLfloat *m);
185 //void (GLAPIENTRY *qglRotated)(GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
186 //void (GLAPIENTRY *qglRotatef)(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
187 //void (GLAPIENTRY *qglScaled)(GLdouble x, GLdouble y, GLdouble z);
188 //void (GLAPIENTRY *qglScalef)(GLfloat x, GLfloat y, GLfloat z);
189 //void (GLAPIENTRY *qglTranslated)(GLdouble x, GLdouble y, GLdouble z);
190 //void (GLAPIENTRY *qglTranslatef)(GLfloat x, GLfloat y, GLfloat z);
192 void (GLAPIENTRY *qglReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
194 void (GLAPIENTRY *qglStencilFunc)(GLenum func, GLint ref, GLuint mask);
195 void (GLAPIENTRY *qglStencilMask)(GLuint mask);
196 void (GLAPIENTRY *qglStencilOp)(GLenum fail, GLenum zfail, GLenum zpass);
197 void (GLAPIENTRY *qglClearStencil)(GLint s);
199 //void (GLAPIENTRY *qglTexEnvf)(GLenum target, GLenum pname, GLfloat param);
200 void (GLAPIENTRY *qglTexEnvfv)(GLenum target, GLenum pname, const GLfloat *params);
201 void (GLAPIENTRY *qglTexEnvi)(GLenum target, GLenum pname, GLint param);
202 void (GLAPIENTRY *qglTexParameterf)(GLenum target, GLenum pname, GLfloat param);
203 //void (GLAPIENTRY *qglTexParameterfv)(GLenum target, GLenum pname, GLfloat *params);
204 void (GLAPIENTRY *qglTexParameteri)(GLenum target, GLenum pname, GLint param);
206 void (GLAPIENTRY *qglGenTextures)(GLsizei n, GLuint *textures);
207 void (GLAPIENTRY *qglDeleteTextures)(GLsizei n, const GLuint *textures);
208 void (GLAPIENTRY *qglBindTexture)(GLenum target, GLuint texture);
209 //void (GLAPIENTRY *qglPrioritizeTextures)(GLsizei n, const GLuint *textures, const GLclampf *priorities);
210 //GLboolean (GLAPIENTRY *qglAreTexturesResident)(GLsizei n, const GLuint *textures, GLboolean *residences);
211 GLboolean (GLAPIENTRY *qglIsTexture)(GLuint texture);
212 //void (GLAPIENTRY *qglPixelStoref)(GLenum pname, GLfloat param);
213 void (GLAPIENTRY *qglPixelStorei)(GLenum pname, GLint param);
215 void (GLAPIENTRY *qglTexImage1D)(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
216 void (GLAPIENTRY *qglTexImage2D)(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
217 void (GLAPIENTRY *qglTexSubImage1D)(GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid *pixels);
218 void (GLAPIENTRY *qglTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
219 void (GLAPIENTRY *qglCopyTexImage1D)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border);
220 void (GLAPIENTRY *qglCopyTexImage2D)(GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
221 void (GLAPIENTRY *qglCopyTexSubImage1D)(GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
222 void (GLAPIENTRY *qglCopyTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
225 void (GLAPIENTRY *qglDrawRangeElementsEXT)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
227 //void (GLAPIENTRY *qglColorTableEXT)(int, int, int, int, int, const void *);
229 void (GLAPIENTRY *qglTexImage3D)(GLenum target, GLint level, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
230 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);
231 void (GLAPIENTRY *qglCopyTexSubImage3D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height);
233 void (GLAPIENTRY *qglScissor)(GLint x, GLint y, GLsizei width, GLsizei height);
235 void (GLAPIENTRY *qglPolygonOffset)(GLfloat factor, GLfloat units);
237 int GL_CheckExtension(const char *name, const dllfunction_t *funcs, const char *disableparm, int silent)
240 const dllfunction_t *func;
242 Con_DPrintf("checking for %s... ", name);
244 for (func = funcs;func && func->name;func++)
245 *func->funcvariable = NULL;
247 if (disableparm && COM_CheckParm(disableparm))
249 Con_DPrintf("disabled by commandline\n");
253 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)))
255 for (func = funcs;func && func->name != NULL;func++)
257 // functions are cleared before all the extensions are evaluated
258 if (!(*func->funcvariable = (void *) GL_GetProcAddress(func->name)))
261 Con_Printf("OpenGL extension \"%s\" is missing function \"%s\" - broken driver!\n", name, func->name);
265 // delay the return so it prints all missing functions
268 Con_DPrintf("enabled\n");
273 Con_DPrintf("not detected\n");
278 static dllfunction_t opengl110funcs[] =
280 {"glClearColor", (void **) &qglClearColor},
281 {"glClear", (void **) &qglClear},
282 // {"glAlphaFunc", (void **) &qglAlphaFunc},
283 {"glBlendFunc", (void **) &qglBlendFunc},
284 {"glCullFace", (void **) &qglCullFace},
285 // {"glDrawBuffer", (void **) &qglDrawBuffer},
286 // {"glReadBuffer", (void **) &qglReadBuffer},
287 {"glEnable", (void **) &qglEnable},
288 {"glDisable", (void **) &qglDisable},
289 {"glIsEnabled", (void **) &qglIsEnabled},
290 {"glEnableClientState", (void **) &qglEnableClientState},
291 {"glDisableClientState", (void **) &qglDisableClientState},
292 // {"glGetBooleanv", (void **) &qglGetBooleanv},
293 // {"glGetDoublev", (void **) &qglGetDoublev},
294 // {"glGetFloatv", (void **) &qglGetFloatv},
295 {"glGetIntegerv", (void **) &qglGetIntegerv},
296 {"glGetError", (void **) &qglGetError},
297 {"glGetString", (void **) &qglGetString},
298 {"glFinish", (void **) &qglFinish},
299 {"glFlush", (void **) &qglFlush},
300 {"glClearDepth", (void **) &qglClearDepth},
301 {"glDepthFunc", (void **) &qglDepthFunc},
302 {"glDepthMask", (void **) &qglDepthMask},
303 {"glDepthRange", (void **) &qglDepthRange},
304 {"glDrawElements", (void **) &qglDrawElements},
305 {"glColorMask", (void **) &qglColorMask},
306 {"glVertexPointer", (void **) &qglVertexPointer},
307 {"glNormalPointer", (void **) &qglNormalPointer},
308 {"glColorPointer", (void **) &qglColorPointer},
309 {"glTexCoordPointer", (void **) &qglTexCoordPointer},
310 {"glArrayElement", (void **) &qglArrayElement},
311 {"glColor4f", (void **) &qglColor4f},
312 {"glTexCoord2f", (void **) &qglTexCoord2f},
313 {"glTexCoord3f", (void **) &qglTexCoord3f},
314 {"glVertex2f", (void **) &qglVertex2f},
315 {"glVertex3f", (void **) &qglVertex3f},
316 {"glBegin", (void **) &qglBegin},
317 {"glEnd", (void **) &qglEnd},
318 {"glMatrixMode", (void **) &qglMatrixMode},
319 {"glOrtho", (void **) &qglOrtho},
320 {"glFrustum", (void **) &qglFrustum},
321 {"glViewport", (void **) &qglViewport},
322 // {"glPushMatrix", (void **) &qglPushMatrix},
323 // {"glPopMatrix", (void **) &qglPopMatrix},
324 {"glLoadIdentity", (void **) &qglLoadIdentity},
325 // {"glLoadMatrixd", (void **) &qglLoadMatrixd},
326 {"glLoadMatrixf", (void **) &qglLoadMatrixf},
327 // {"glMultMatrixd", (void **) &qglMultMatrixd},
328 // {"glMultMatrixf", (void **) &qglMultMatrixf},
329 // {"glRotated", (void **) &qglRotated},
330 // {"glRotatef", (void **) &qglRotatef},
331 // {"glScaled", (void **) &qglScaled},
332 // {"glScalef", (void **) &qglScalef},
333 // {"glTranslated", (void **) &qglTranslated},
334 // {"glTranslatef", (void **) &qglTranslatef},
335 {"glReadPixels", (void **) &qglReadPixels},
336 {"glStencilFunc", (void **) &qglStencilFunc},
337 {"glStencilMask", (void **) &qglStencilMask},
338 {"glStencilOp", (void **) &qglStencilOp},
339 {"glClearStencil", (void **) &qglClearStencil},
340 // {"glTexEnvf", (void **) &qglTexEnvf},
341 {"glTexEnvfv", (void **) &qglTexEnvfv},
342 {"glTexEnvi", (void **) &qglTexEnvi},
343 {"glTexParameterf", (void **) &qglTexParameterf},
344 // {"glTexParameterfv", (void **) &qglTexParameterfv},
345 {"glTexParameteri", (void **) &qglTexParameteri},
346 // {"glPixelStoref", (void **) &qglPixelStoref},
347 {"glPixelStorei", (void **) &qglPixelStorei},
348 {"glGenTextures", (void **) &qglGenTextures},
349 {"glDeleteTextures", (void **) &qglDeleteTextures},
350 {"glBindTexture", (void **) &qglBindTexture},
351 // {"glPrioritizeTextures", (void **) &qglPrioritizeTextures},
352 // {"glAreTexturesResident", (void **) &qglAreTexturesResident},
353 {"glIsTexture", (void **) &qglIsTexture},
354 {"glTexImage1D", (void **) &qglTexImage1D},
355 {"glTexImage2D", (void **) &qglTexImage2D},
356 {"glTexSubImage1D", (void **) &qglTexSubImage1D},
357 {"glTexSubImage2D", (void **) &qglTexSubImage2D},
358 {"glCopyTexImage1D", (void **) &qglCopyTexImage1D},
359 {"glCopyTexImage2D", (void **) &qglCopyTexImage2D},
360 {"glCopyTexSubImage1D", (void **) &qglCopyTexSubImage1D},
361 {"glCopyTexSubImage2D", (void **) &qglCopyTexSubImage2D},
362 {"glScissor", (void **) &qglScissor},
363 {"glPolygonOffset", (void **) &qglPolygonOffset},
367 static dllfunction_t drawrangeelementsfuncs[] =
369 {"glDrawRangeElements", (void **) &qglDrawRangeElements},
373 static dllfunction_t drawrangeelementsextfuncs[] =
375 {"glDrawRangeElementsEXT", (void **) &qglDrawRangeElementsEXT},
379 static dllfunction_t multitexturefuncs[] =
381 {"glMultiTexCoord2fARB", (void **) &qglMultiTexCoord2f},
382 {"glMultiTexCoord3fARB", (void **) &qglMultiTexCoord3f},
383 {"glActiveTextureARB", (void **) &qglActiveTexture},
384 {"glClientActiveTextureARB", (void **) &qglClientActiveTexture},
388 static dllfunction_t compiledvertexarrayfuncs[] =
390 {"glLockArraysEXT", (void **) &qglLockArraysEXT},
391 {"glUnlockArraysEXT", (void **) &qglUnlockArraysEXT},
395 static dllfunction_t texture3dextfuncs[] =
397 {"glTexImage3DEXT", (void **) &qglTexImage3D},
398 {"glTexSubImage3DEXT", (void **) &qglTexSubImage3D},
399 {"glCopyTexSubImage3DEXT", (void **) &qglCopyTexSubImage3D},
403 static dllfunction_t glxvarfuncs[] =
405 {"glXAllocateMemoryNV", (void **) &qglAllocateMemoryNV},
406 {"glXFreeMemoryNV", (void **) &qglFreeMemoryNV},
407 {"glVertexArrayRangeNV", (void **) &qglVertexArrayRangeNV},
408 {"glFlushVertexArrayRangeNV", (void **) &qglFlushVertexArrayRangeNV},
412 static dllfunction_t wglvarfuncs[] =
414 {"wglAllocateMemoryNV", (void **) &qglAllocateMemoryNV},
415 {"wglFreeMemoryNV", (void **) &qglFreeMemoryNV},
416 {"glVertexArrayRangeNV", (void **) &qglVertexArrayRangeNV},
417 {"glFlushVertexArrayRangeNV", (void **) &qglFlushVertexArrayRangeNV},
422 void VID_CheckExtensions(void)
424 gl_stencil = vid_bitsperpixel.integer == 32;
425 gl_combine_extension = false;
427 gl_supportslockarrays = false;
429 gl_support_clamptoedge = false;
430 gl_support_var = false;
431 gl_support_var2 = false;
433 if (!GL_CheckExtension("OpenGL 1.1.0", opengl110funcs, NULL, false))
434 Sys_Error("OpenGL 1.1.0 functions not found\n");
436 Con_DPrintf ("GL_VENDOR: %s\n", gl_vendor);
437 Con_DPrintf ("GL_RENDERER: %s\n", gl_renderer);
438 Con_DPrintf ("GL_VERSION: %s\n", gl_version);
439 Con_DPrintf ("GL_EXTENSIONS: %s\n", gl_extensions);
440 Con_DPrintf ("%s_EXTENSIONS: %s\n", gl_platform, gl_platformextensions);
442 Con_DPrintf("Checking OpenGL extensions...\n");
444 if (!GL_CheckExtension("glDrawRangeElements", drawrangeelementsfuncs, "-nodrawrangeelements", true))
445 GL_CheckExtension("GL_EXT_draw_range_elements", drawrangeelementsextfuncs, "-nodrawrangeelements", false);
447 if (GL_CheckExtension("GL_ARB_multitexture", multitexturefuncs, "-nomtex", false))
449 qglGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_textureunits);
450 gl_combine_extension = GL_CheckExtension("GL_ARB_texture_env_combine", NULL, "-nocombine", false) || GL_CheckExtension("GL_EXT_texture_env_combine", NULL, "-nocombine", false);
451 if (gl_combine_extension)
452 gl_dot3arb = GL_CheckExtension("GL_ARB_texture_env_dot3", NULL, "-nodot3", false);
455 gl_texture3d = GL_CheckExtension("GL_EXT_texture3D", texture3dextfuncs, "-notexture3d", false);
456 gl_texturecubemap = GL_CheckExtension("GL_ARB_texture_cube_map", NULL, "-nocubemap", false);
457 gl_supportslockarrays = GL_CheckExtension("GL_EXT_compiled_vertex_array", compiledvertexarrayfuncs, "-nocva", false);
458 gl_support_clamptoedge = GL_CheckExtension("GL_EXT_texture_edge_clamp", NULL, "-noedgeclamp", false) || GL_CheckExtension("GL_SGIS_texture_edge_clamp", NULL, "-noedgeclamp", false);
460 if (!strcmp(gl_platform, "GLX"))
461 gl_support_var = GL_CheckExtension("GL_NV_vertex_array_range", glxvarfuncs, "-novar", false);
462 else if (!strcmp(gl_platform, "WGL"))
463 gl_support_var = GL_CheckExtension("GL_NV_vertex_array_range", wglvarfuncs, "-novar", false);
465 gl_support_var2 = GL_CheckExtension("GL_NV_vertex_array_range2", NULL, "-novar2", false);
467 gl_support_anisotropy = GL_CheckExtension("GL_EXT_texture_filter_anisotropic", NULL, "-noanisotropy", false);
469 gl_textureshader = GL_CheckExtension("GL_NV_texture_shader", NULL, "-notextureshader", false);
471 // we don't care if it's an extension or not, they are identical functions, so keep it simple in the rendering code
472 if (qglDrawRangeElements == NULL)
473 qglDrawRangeElements = qglDrawRangeElementsEXT;
476 int vid_vertexarrays_are_var = false;
477 void *VID_AllocVertexArrays(mempool_t *pool, int size, int fast, float readfrequency, float writefrequency, float priority)
480 vid_vertexarrays_are_var = false;
481 if (fast && qglAllocateMemoryNV)
484 m = qglAllocateMemoryNV(size, readfrequency, writefrequency, priority);
488 vid_vertexarrays_are_var = true;
492 return Mem_Alloc(pool, size);
495 void VID_FreeVertexArrays(void *pointer)
497 if (vid_vertexarrays_are_var)
500 qglFreeMemoryNV(pointer);
505 vid_vertexarrays_are_var = false;
508 void Force_CenterView_f (void)
510 cl.viewangles[PITCH] = 0;
513 void IN_PreMove(void)
517 void CL_AdjustAngles(void);
518 void IN_PostMove(void)
520 // clamp after the move as well to prevent messed up rendering angles
529 void IN_ProcessMove(usercmd_t *cmd)
531 // get basic movement from keyboard
534 // OS independent code
537 // allow mice or other external controllers to add to the move
540 // OS independent code
545 void IN_Mouse(usercmd_t *cmd, float mx, float my)
547 int mouselook = (in_mlook.state & 1) || freelook.integer;
548 float mouse_x, mouse_y;
549 static float old_mouse_x = 0, old_mouse_y = 0;
551 if (m_filter.integer)
553 mouse_x = (mx + old_mouse_x) * 0.5;
554 mouse_y = (my + old_mouse_y) * 0.5;
565 in_mouse_x = (float) mouse_x * vid.conwidth / vid.realwidth;
566 in_mouse_y = (float) mouse_y * vid.conheight / vid.realheight;
568 // AK: eveything else is client stuff
569 // BTW, this should be seperated somewhen
573 // LordHavoc: viewzoom affects mouse sensitivity for sniping
574 mouse_x *= sensitivity.value * cl.viewzoom;
575 mouse_y *= sensitivity.value * cl.viewzoom;
577 // Add mouse X/Y movement to cmd
578 if ((in_strafe.state & 1) || (lookstrafe.integer && mouselook))
579 cmd->sidemove += m_side.value * mouse_x;
581 cl.viewangles[YAW] -= m_yaw.value * mouse_x;
586 if (mouselook && !(in_strafe.state & 1))
587 cl.viewangles[PITCH] += m_pitch.value * mouse_y;
590 if ((in_strafe.state & 1) && noclip_anglehack)
591 cmd->upmove -= m_forward.value * mouse_y;
593 cmd->forwardmove -= m_forward.value * mouse_y;
597 static float cachegamma, cachebrightness, cachecontrast, cacheblack[3], cachegrey[3], cachewhite[3];
598 static int cachecolorenable, cachehwgamma;
599 #define BOUNDCVAR(cvar, m1, m2) c = &(cvar);f = bound(m1, c->value, m2);if (c->value != f) Cvar_SetValueQuick(c, f);
600 void VID_UpdateGamma(qboolean force)
604 static int forcenextframe = false;
606 // LordHavoc: don't mess with gamma tables if running dedicated
607 if (cls.state == ca_dedicated)
613 && vid_usinghwgamma == (vid_activewindow && v_hwgamma.integer)
614 && v_gamma.value == cachegamma
615 && v_contrast.value == cachecontrast
616 && v_brightness.value == cachebrightness
617 && cachecolorenable == v_color_enable.integer
618 && cacheblack[0] == v_color_black_r.value
619 && cacheblack[1] == v_color_black_g.value
620 && cacheblack[2] == v_color_black_b.value
621 && cachegrey[0] == v_color_grey_r.value
622 && cachegrey[1] == v_color_grey_g.value
623 && cachegrey[2] == v_color_grey_b.value
624 && cachewhite[0] == v_color_white_r.value
625 && cachewhite[1] == v_color_white_g.value
626 && cachewhite[2] == v_color_white_b.value)
629 forcenextframe = false;
631 if (vid_activewindow && v_hwgamma.integer)
633 if (!vid_usinghwgamma)
635 vid_usinghwgamma = true;
636 Cvar_SetValueQuick(&vid_hardwaregammasupported, VID_GetGamma(vid_systemgammaramps));
639 BOUNDCVAR(v_gamma, 0.1, 5);cachegamma = v_gamma.value;
640 BOUNDCVAR(v_contrast, 1, 5);cachecontrast = v_contrast.value;
641 BOUNDCVAR(v_brightness, 0, 0.8);cachebrightness = v_brightness.value;
642 BOUNDCVAR(v_color_black_r, 0, 0.8);cacheblack[0] = v_color_black_r.value;
643 BOUNDCVAR(v_color_black_g, 0, 0.8);cacheblack[1] = v_color_black_g.value;
644 BOUNDCVAR(v_color_black_b, 0, 0.8);cacheblack[2] = v_color_black_b.value;
645 BOUNDCVAR(v_color_grey_r, 0, 0.95);cachegrey[0] = v_color_grey_r.value;
646 BOUNDCVAR(v_color_grey_g, 0, 0.95);cachegrey[1] = v_color_grey_g.value;
647 BOUNDCVAR(v_color_grey_b, 0, 0.95);cachegrey[2] = v_color_grey_b.value;
648 BOUNDCVAR(v_color_white_r, 1, 5);cachewhite[0] = v_color_white_r.value;
649 BOUNDCVAR(v_color_white_g, 1, 5);cachewhite[1] = v_color_white_g.value;
650 BOUNDCVAR(v_color_white_b, 1, 5);cachewhite[2] = v_color_white_b.value;
651 cachecolorenable = v_color_enable.integer;
652 cachehwgamma = v_hwgamma.integer;
654 if (cachecolorenable)
656 BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[0]), cachewhite[0], cacheblack[0], vid_gammaramps);
657 BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[1]), cachewhite[1], cacheblack[1], vid_gammaramps + 256);
658 BuildGammaTable16(1.0f, invpow(0.5, 1 - cachegrey[2]), cachewhite[2], cacheblack[2], vid_gammaramps + 512);
662 BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, vid_gammaramps);
663 BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, vid_gammaramps + 256);
664 BuildGammaTable16(1.0f, cachegamma, cachecontrast, cachebrightness, vid_gammaramps + 512);
667 // LordHavoc: this code came from Ben Winslow and Zinx Verituse, I have
668 // immensely butchered it to work with variable framerates and fit in with
669 // the rest of darkplaces.
670 if (v_psycho.integer)
674 static float n[3], nd[3], nt[3];
675 static int init = true;
676 unsigned short *ramp;
677 forcenextframe = true;
681 for (x = 0;x < 3;x++)
683 n[x] = lhrandom(0, 1);
684 nd[x] = (rand()&1)?-0.25:0.25;
685 nt[x] = lhrandom(1, 8.2);
689 for (x = 0;x < 3;x++)
691 nt[x] -= host_realframetime;
695 nt[x] += lhrandom(1, 8.2);
697 n[x] += nd[x] * host_realframetime;
701 for (x = 0, ramp = vid_gammaramps;x < 3;x++)
702 for (y = 0, t = n[x] - 0.75f;y < 256;y++, t += 0.75f * (2.0f / 256.0f))
703 *ramp++ = cos(t*(M_PI*2.0)) * 32767.0f + 32767.0f;
706 Cvar_SetValueQuick(&vid_hardwaregammasupported, VID_SetGamma(vid_gammaramps));
710 if (vid_usinghwgamma)
712 vid_usinghwgamma = false;
713 Cvar_SetValueQuick(&vid_hardwaregammasupported, VID_SetGamma(vid_systemgammaramps));
718 void VID_RestoreSystemGamma(void)
720 if (vid_usinghwgamma)
722 vid_usinghwgamma = false;
723 VID_SetGamma(vid_systemgammaramps);
727 void VID_Shared_Init(void)
729 Cvar_RegisterVariable(&vid_hardwaregammasupported);
730 Cvar_RegisterVariable(&v_gamma);
731 Cvar_RegisterVariable(&v_brightness);
732 Cvar_RegisterVariable(&v_contrast);
734 Cvar_RegisterVariable(&v_color_enable);
735 Cvar_RegisterVariable(&v_color_black_r);
736 Cvar_RegisterVariable(&v_color_black_g);
737 Cvar_RegisterVariable(&v_color_black_b);
738 Cvar_RegisterVariable(&v_color_grey_r);
739 Cvar_RegisterVariable(&v_color_grey_g);
740 Cvar_RegisterVariable(&v_color_grey_b);
741 Cvar_RegisterVariable(&v_color_white_r);
742 Cvar_RegisterVariable(&v_color_white_g);
743 Cvar_RegisterVariable(&v_color_white_b);
745 Cvar_RegisterVariable(&v_hwgamma);
747 Cvar_RegisterVariable(&v_psycho);
749 Cvar_RegisterVariable(&vid_fullscreen);
750 Cvar_RegisterVariable(&vid_width);
751 Cvar_RegisterVariable(&vid_height);
752 Cvar_RegisterVariable(&vid_bitsperpixel);
753 Cvar_RegisterVariable(&vid_mouse);
754 Cvar_RegisterVariable(&gl_combine);
755 Cvar_RegisterVariable(&in_pitch_min);
756 Cvar_RegisterVariable(&in_pitch_max);
757 Cvar_RegisterVariable(&m_filter);
758 Cmd_AddCommand("force_centerview", Force_CenterView_f);
759 Cmd_AddCommand("vid_restart", VID_Restart_f);
760 if (gamemode == GAME_GOODVSBAD2)
761 Cvar_Set("gl_combine", "0");
764 int current_vid_fullscreen;
765 int current_vid_width;
766 int current_vid_height;
767 int current_vid_bitsperpixel;
768 extern int VID_InitMode (int fullscreen, int width, int height, int bpp);
769 int VID_Mode(int fullscreen, int width, int height, int bpp)
771 Con_Printf("Video: %s %dx%dx%d\n", fullscreen ? "fullscreen" : "window", width, height, bpp);
772 if (VID_InitMode(fullscreen, width, height, bpp))
774 current_vid_fullscreen = fullscreen;
775 current_vid_width = width;
776 current_vid_height = height;
777 current_vid_bitsperpixel = bpp;
778 Cvar_SetValueQuick(&vid_fullscreen, fullscreen);
779 Cvar_SetValueQuick(&vid_width, width);
780 Cvar_SetValueQuick(&vid_height, height);
781 Cvar_SetValueQuick(&vid_bitsperpixel, bpp);
788 static void VID_OpenSystems(void)
795 static void VID_CloseSystems(void)
799 R_Modules_Shutdown();
802 int vid_commandlinecheck = true;
804 void VID_Restart_f(void)
806 // don't crash if video hasn't started yet
807 if (vid_commandlinecheck)
810 Con_Printf("VID_Restart: changing from %s %dx%dx%dbpp, to %s %dx%dx%dbpp.\n",
811 current_vid_fullscreen ? "fullscreen" : "window", current_vid_width, current_vid_height, current_vid_bitsperpixel,
812 vid_fullscreen.integer ? "fullscreen" : "window", vid_width.integer, vid_height.integer, vid_bitsperpixel.integer);
814 if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer))
816 Con_Printf("Video mode change failed\n");
817 if (!VID_Mode(current_vid_fullscreen, current_vid_width, current_vid_height, current_vid_bitsperpixel))
818 Sys_Error("Unable to restore to last working video mode\n");
825 int i, width, height;
826 if (vid_commandlinecheck)
828 // interpret command-line parameters
829 vid_commandlinecheck = false;
830 if ((i = COM_CheckParm("-window")) != 0)
831 Cvar_SetValueQuick(&vid_fullscreen, false);
832 if ((i = COM_CheckParm("-fullscreen")) != 0)
833 Cvar_SetValueQuick(&vid_fullscreen, true);
836 if ((i = COM_CheckParm("-width")) != 0)
837 width = atoi(com_argv[i+1]);
838 if ((i = COM_CheckParm("-height")) != 0)
839 height = atoi(com_argv[i+1]);
841 width = height * 4 / 3;
843 height = width * 3 / 4;
845 Cvar_SetValueQuick(&vid_width, width);
847 Cvar_SetValueQuick(&vid_height, height);
848 if ((i = COM_CheckParm("-bpp")) != 0)
849 Cvar_SetQuick(&vid_bitsperpixel, com_argv[i+1]);
852 Con_DPrintf("Starting video system\n");
853 if (!VID_Mode(vid_fullscreen.integer, vid_width.integer, vid_height.integer, vid_bitsperpixel.integer))
855 Con_Printf("Desired video mode fail, trying fallbacks...\n");
856 if (vid_fullscreen.integer)
858 if (!VID_Mode(true, 640, 480, 16))
859 if (!VID_Mode(false, 640, 480, 16))
860 Sys_Error("Video modes failed\n");
863 Sys_Error("Windowed video failed\n");