4 // LordHavoc: these are only set in wgl
5 qboolean isG200 = false; // LordHavoc: the Matrox G200 can't do per pixel alpha, and it uses a D3D driver for GL... ugh...
6 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.
8 // LordHavoc: GL_ARB_multitexture support
10 // LordHavoc: GL_ARB_texture_env_combine or GL_EXT_texture_env_combine support
11 int gl_combine_extension = false;
12 // LordHavoc: GL_EXT_compiled_vertex_array support
13 int gl_supportslockarrays = false;
15 int gl_maxdrawrangeelementsvertices;
16 int gl_maxdrawrangeelementsindices;
18 cvar_t vid_mode = {0, "vid_mode", "0"};
19 cvar_t vid_mouse = {CVAR_SAVE, "vid_mouse", "1"};
20 cvar_t vid_fullscreen = {0, "vid_fullscreen", "1"};
21 cvar_t gl_combine = {0, "gl_combine", "1"};
23 cvar_t in_pitch_min = {0, "in_pitch_min", "-90"};
24 cvar_t in_pitch_max = {0, "in_pitch_max", "90"};
26 cvar_t m_filter = {CVAR_SAVE, "m_filter","0"};
28 // GL_ARB_multitexture
29 void (GLAPIENTRY *qglMultiTexCoord2f) (GLenum, GLfloat, GLfloat);
30 void (GLAPIENTRY *qglActiveTexture) (GLenum);
31 void (GLAPIENTRY *qglClientActiveTexture) (GLenum);
33 // GL_EXT_compiled_vertex_array
34 void (GLAPIENTRY *qglLockArraysEXT) (GLint first, GLint count);
35 void (GLAPIENTRY *qglUnlockArraysEXT) (void);
38 // general GL functions
40 void (GLAPIENTRY *qglClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
42 void (GLAPIENTRY *qglClear)(GLbitfield mask);
44 //void (GLAPIENTRY *qglAlphaFunc)(GLenum func, GLclampf ref);
45 void (GLAPIENTRY *qglBlendFunc)(GLenum sfactor, GLenum dfactor);
46 void (GLAPIENTRY *qglCullFace)(GLenum mode);
48 void (GLAPIENTRY *qglDrawBuffer)(GLenum mode);
49 void (GLAPIENTRY *qglReadBuffer)(GLenum mode);
50 void (GLAPIENTRY *qglEnable)(GLenum cap);
51 void (GLAPIENTRY *qglDisable)(GLenum cap);
52 //GLboolean GLAPIENTRY *qglIsEnabled)(GLenum cap);
54 void (GLAPIENTRY *qglEnableClientState)(GLenum cap);
55 void (GLAPIENTRY *qglDisableClientState)(GLenum cap);
57 //void (GLAPIENTRY *qglGetBooleanv)(GLenum pname, GLboolean *params);
58 //void (GLAPIENTRY *qglGetDoublev)(GLenum pname, GLdouble *params);
59 //void (GLAPIENTRY *qglGetFloatv)(GLenum pname, GLfloat *params);
60 void (GLAPIENTRY *qglGetIntegerv)(GLenum pname, GLint *params);
62 GLenum (GLAPIENTRY *qglGetError)(void);
63 const GLubyte* (GLAPIENTRY *qglGetString)(GLenum name);
64 void (GLAPIENTRY *qglFinish)(void);
65 void (GLAPIENTRY *qglFlush)(void);
67 void (GLAPIENTRY *qglClearDepth)(GLclampd depth);
68 void (GLAPIENTRY *qglDepthFunc)(GLenum func);
69 void (GLAPIENTRY *qglDepthMask)(GLboolean flag);
70 void (GLAPIENTRY *qglDepthRange)(GLclampd near_val, GLclampd far_val);
72 void (GLAPIENTRY *qglDrawRangeElements)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
73 void (GLAPIENTRY *qglDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
74 void (GLAPIENTRY *qglVertexPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
75 //void (GLAPIENTRY *qglNormalPointer)(GLenum type, GLsizei stride, const GLvoid *ptr);
76 void (GLAPIENTRY *qglColorPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
77 void (GLAPIENTRY *qglTexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
78 void (GLAPIENTRY *qglArrayElement)(GLint i);
80 void (GLAPIENTRY *qglColor4ub)(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha);
81 void (GLAPIENTRY *qglTexCoord2f)(GLfloat s, GLfloat t);
82 void (GLAPIENTRY *qglVertex2f)(GLfloat x, GLfloat y);
83 void (GLAPIENTRY *qglVertex3f)(GLfloat x, GLfloat y, GLfloat z);
84 void (GLAPIENTRY *qglBegin)(GLenum mode);
85 void (GLAPIENTRY *qglEnd)(void);
87 void (GLAPIENTRY *qglMatrixMode)(GLenum mode);
88 void (GLAPIENTRY *qglOrtho)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val);
89 void (GLAPIENTRY *qglFrustum)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val);
90 void (GLAPIENTRY *qglViewport)(GLint x, GLint y, GLsizei width, GLsizei height);
91 //void (GLAPIENTRY *qglPushMatrix)(void);
92 //void (GLAPIENTRY *qglPopMatrix)(void);
93 void (GLAPIENTRY *qglLoadIdentity)(void);
94 //void (GLAPIENTRY *qglLoadMatrixd)(const GLdouble *m);
95 //void (GLAPIENTRY *qglLoadMatrixf)(const GLfloat *m);
96 //void (GLAPIENTRY *qglMultMatrixd)(const GLdouble *m);
97 //void (GLAPIENTRY *qglMultMatrixf)(const GLfloat *m);
98 //void (GLAPIENTRY *qglRotated)(GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
99 void (GLAPIENTRY *qglRotatef)(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
100 //void (GLAPIENTRY *qglScaled)(GLdouble x, GLdouble y, GLdouble z);
101 //void (GLAPIENTRY *qglScalef)(GLfloat x, GLfloat y, GLfloat z);
102 //void (GLAPIENTRY *qglTranslated)(GLdouble x, GLdouble y, GLdouble z);
103 void (GLAPIENTRY *qglTranslatef)(GLfloat x, GLfloat y, GLfloat z);
105 void (GLAPIENTRY *qglReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
107 //void (GLAPIENTRY *qglStencilFunc)(GLenum func, GLint ref, GLuint mask);
108 //void (GLAPIENTRY *qglStencilMask)(GLuint mask);
109 //void (GLAPIENTRY *qglStencilOp)(GLenum fail, GLenum zfail, GLenum zpass);
110 //void (GLAPIENTRY *qglClearStencil)(GLint s);
112 //void (GLAPIENTRY *qglTexEnvf)(GLenum target, GLenum pname, GLfloat param);
113 void (GLAPIENTRY *qglTexEnvi)(GLenum target, GLenum pname, GLint param);
115 //void (GLAPIENTRY *qglTexParameterf)(GLenum target, GLenum pname, GLfloat param);
116 void (GLAPIENTRY *qglTexParameteri)(GLenum target, GLenum pname, GLint param);
118 void (GLAPIENTRY *qglBindTexture)(GLenum target, GLuint texture);
119 void (GLAPIENTRY *qglTexImage2D)(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
120 void (GLAPIENTRY *qglTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
121 void (GLAPIENTRY *qglDeleteTextures)(GLsizei n, const GLuint *textures);
123 void (GLAPIENTRY *qglDrawRangeElementsEXT)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
125 //void (GLAPIENTRY *qglColorTableEXT)(int, int, int, int, int, const void *);
128 int (WINAPI *qwglChoosePixelFormat)(HDC, CONST PIXELFORMATDESCRIPTOR *);
129 int (WINAPI *qwglDescribePixelFormat)(HDC, int, UINT, LPPIXELFORMATDESCRIPTOR);
130 //int (WINAPI *qwglGetPixelFormat)(HDC);
131 BOOL (WINAPI *qwglSetPixelFormat)(HDC, int, CONST PIXELFORMATDESCRIPTOR *);
132 BOOL (WINAPI *qwglSwapBuffers)(HDC);
133 HGLRC (WINAPI *qwglCreateContext)(HDC);
134 BOOL (WINAPI *qwglDeleteContext)(HGLRC);
135 PROC (WINAPI *qwglGetProcAddress)(LPCSTR);
136 BOOL (WINAPI *qwglMakeCurrent)(HDC, HGLRC);
137 //BOOL (WINAPI *qwglSwapIntervalEXT)(int interval);
146 gl_extensionfunctionlist_t;
151 gl_extensionfunctionlist_t *funcs;
158 static gl_extensionfunctionlist_t wglfuncs[] =
160 {"wglChoosePixelFormat", (void **) &qwglChoosePixelFormat},
161 {"wglDescribePixelFormat", (void **) &qwglDescribePixelFormat},
162 // {"wglGetPixelFormat", (void **) &qwglGetPixelFormat},
163 {"wglSetPixelFormat", (void **) &qwglSetPixelFormat},
164 {"wglSwapBuffers", (void **) &qwglSwapBuffers},
165 {"wglCreateContext", (void **) &qwglCreateContext},
166 {"wglDeleteContext", (void **) &qwglDeleteContext},
167 {"wglGetProcAddress", (void **) &qwglGetProcAddress},
168 {"wglMakeCurrent", (void **) &qwglMakeCurrent},
173 static gl_extensionfunctionlist_t wglswapintervalfuncs[] =
175 {"wglSwapIntervalEXT", (void **) &qwglSwapIntervalEXT},
181 static gl_extensionfunctionlist_t opengl110funcs[] =
183 {"glClearColor", (void **) &qglClearColor},
184 {"glClear", (void **) &qglClear},
185 // {"glAlphaFunc", (void **) &qglAlphaFunc},
186 {"glBlendFunc", (void **) &qglBlendFunc},
187 {"glCullFace", (void **) &qglCullFace},
188 {"glDrawBuffer", (void **) &qglDrawBuffer},
189 {"glReadBuffer", (void **) &qglReadBuffer},
190 {"glEnable", (void **) &qglEnable},
191 {"glDisable", (void **) &qglDisable},
192 // {"glIsEnabled", (void **) &qglIsEnabled},
193 {"glEnableClientState", (void **) &qglEnableClientState},
194 {"glDisableClientState", (void **) &qglDisableClientState},
195 // {"glGetBooleanv", (void **) &qglGetBooleanv},
196 // {"glGetDoublev", (void **) &qglGetDoublev},
197 // {"glGetFloatv", (void **) &qglGetFloatv},
198 {"glGetIntegerv", (void **) &qglGetIntegerv},
199 {"glGetError", (void **) &qglGetError},
200 {"glGetString", (void **) &qglGetString},
201 {"glFinish", (void **) &qglFinish},
202 {"glFlush", (void **) &qglFlush},
203 {"glClearDepth", (void **) &qglClearDepth},
204 {"glDepthFunc", (void **) &qglDepthFunc},
205 {"glDepthMask", (void **) &qglDepthMask},
206 {"glDepthRange", (void **) &qglDepthRange},
207 {"glDrawElements", (void **) &qglDrawElements},
208 {"glVertexPointer", (void **) &qglVertexPointer},
209 // {"glNormalPointer", (void **) &qglNormalPointer},
210 {"glColorPointer", (void **) &qglColorPointer},
211 {"glTexCoordPointer", (void **) &qglTexCoordPointer},
212 {"glArrayElement", (void **) &qglArrayElement},
213 {"glColor4ub", (void **) &qglColor4ub},
214 {"glTexCoord2f", (void **) &qglTexCoord2f},
215 {"glVertex2f", (void **) &qglVertex2f},
216 {"glVertex3f", (void **) &qglVertex3f},
217 {"glBegin", (void **) &qglBegin},
218 {"glEnd", (void **) &qglEnd},
219 {"glMatrixMode", (void **) &qglMatrixMode},
220 {"glOrtho", (void **) &qglOrtho},
221 {"glFrustum", (void **) &qglFrustum},
222 {"glViewport", (void **) &qglViewport},
223 // {"glPushMatrix", (void **) &qglPushMatrix},
224 // {"glPopMatrix", (void **) &qglPopMatrix},
225 {"glLoadIdentity", (void **) &qglLoadIdentity},
226 // {"glLoadMatrixd", (void **) &qglLoadMatrixd},
227 // {"glLoadMatrixf", (void **) &qglLoadMatrixf},
228 // {"glMultMatrixd", (void **) &qglMultMatrixd},
229 // {"glMultMatrixf", (void **) &qglMultMatrixf},
230 // {"glRotated", (void **) &qglRotated},
231 {"glRotatef", (void **) &qglRotatef},
232 // {"glScaled", (void **) &qglScaled},
233 // {"glScalef", (void **) &qglScalef},
234 // {"glTranslated", (void **) &qglTranslated},
235 {"glTranslatef", (void **) &qglTranslatef},
236 {"glReadPixels", (void **) &qglReadPixels},
237 // {"glStencilFunc", (void **) &qglStencilFunc},
238 // {"glStencilMask", (void **) &qglStencilMask},
239 // {"glStencilOp", (void **) &qglStencilOp},
240 // {"glClearStencil", (void **) &qglClearStencil},
241 // {"glTexEnvf", (void **) &qglTexEnvf},
242 {"glTexEnvi", (void **) &qglTexEnvi},
243 // {"glTexParameterf", (void **) &qglTexParameterf},
244 {"glTexParameteri", (void **) &qglTexParameteri},
245 {"glBindTexture", (void **) &qglBindTexture},
246 {"glTexImage2D", (void **) &qglTexImage2D},
247 {"glTexSubImage2D", (void **) &qglTexSubImage2D},
248 {"glDeleteTextures", (void **) &qglDeleteTextures},
252 static gl_extensionfunctionlist_t drawrangeelementsfuncs[] =
254 {"glDrawRangeElements", (void **) &qglDrawRangeElements},
258 static gl_extensionfunctionlist_t drawrangeelementsextfuncs[] =
260 {"glDrawRangeElementsEXT", (void **) &qglDrawRangeElementsEXT},
264 static gl_extensionfunctionlist_t multitexturefuncs[] =
266 {"glMultiTexCoord2fARB", (void **) &qglMultiTexCoord2f},
267 {"glActiveTextureARB", (void **) &qglActiveTexture},
268 {"glClientActiveTextureARB", (void **) &qglClientActiveTexture},
272 static gl_extensionfunctionlist_t compiledvertexarrayfuncs[] =
274 {"glLockArraysEXT", (void **) &qglLockArraysEXT},
275 {"glUnlockArraysEXT", (void **) &qglUnlockArraysEXT},
284 static HINSTANCE gldll;
286 static void *prjobj = NULL;
289 static void gl_getfuncs_begin(void)
292 gldll = LoadLibrary("opengl32.dll");
297 prjobj = dlopen(NULL, RTLD_LAZY);
300 Con_Printf("Unable to open symbol list for main program.\n");
306 static void gl_getfuncs_end(void)
317 static void *gl_getfuncaddress(char *name)
321 if (qwglGetProcAddress != NULL)
322 p = (void *) qwglGetProcAddress(name);
324 p = (void *) GetProcAddress(gldll, name);
326 p = (void *) dlsym(prjobj, name);
331 static int gl_checkextension(char *name, gl_extensionfunctionlist_t *funcs, char *disableparm, int silent)
334 gl_extensionfunctionlist_t *func;
336 Con_Printf("checking for %s... ", name);
338 for (func = funcs;func && func->name;func++)
339 *func->funcvariable = NULL;
341 if (disableparm && COM_CheckParm(disableparm))
343 Con_Printf("disabled by commandline\n");
347 if (strncmp(name, "GL_", 3) || strstr(gl_extensions, name))
349 for (func = funcs;func && func->name != NULL;func++)
351 // functions are cleared before all the extensions are evaluated
352 if (!(*func->funcvariable = (void *) gl_getfuncaddress(func->name)))
355 Con_Printf("missing function \"%s\" - broken driver!\n", func->name);
359 // delay the return so it prints all missing functions
362 Con_Printf("enabled\n");
367 Con_Printf("not detected\n");
372 void VID_CheckExtensions(void)
374 Con_Printf("Checking OpenGL extensions...\n");
378 gl_combine_extension = false;
379 gl_supportslockarrays = false;
383 if (!gl_checkextension("wgl", wglfuncs, NULL, false))
384 Sys_Error("wgl functions not found\n");
385 //gl_checkextension("wglSwapIntervalEXT", wglswapintervalfuncs, NULL, false);
388 if (!gl_checkextension("OpenGL 1.1.0", opengl110funcs, NULL, false))
389 Sys_Error("OpenGL 1.1.0 functions not found\n");
391 if (gl_checkextension("glDrawRangeElements", drawrangeelementsfuncs, "-nodrawrangeelements", true)
392 || gl_checkextension("GL_EXT_draw_range_elements", drawrangeelementsextfuncs, "-nodrawrangeelements", true))
394 qglGetIntegerv(GL_MAX_ELEMENTS_VERTICES, &gl_maxdrawrangeelementsvertices);
395 qglGetIntegerv(GL_MAX_ELEMENTS_INDICES, &gl_maxdrawrangeelementsindices);
397 if (gl_maxdrawrangeelementsvertices < 1 || gl_maxdrawrangeelementsindices < 1)
399 Con_Printf("invalid GL_MAX_ELEMENTS_VERTICES (%i) and/or GL_MAX_ELEMENTS_INDICES (%i)\n", gl_maxdrawrangeelementsvertices, gl_maxdrawrangeelementsindices);
400 qglDrawRangeElements = qglDrawRangeElementsEXT = NULL;
404 if (gl_checkextension("GL_ARB_multitexture", multitexturefuncs, "-nomtex", false))
406 qglGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_textureunits);
407 if (gl_textureunits > 1)
408 gl_combine_extension = gl_checkextension("GL_ARB_texture_env_combine", NULL, "-nocombine", false) || gl_checkextension("GL_EXT_texture_env_combine", NULL, "-nocombine", false);
411 Con_Printf("GL_ARB_multitexture with less than 2 units? - BROKEN DRIVER!\n");
412 gl_textureunits = 1; // for sanity sake, make sure it's not 0
416 gl_supportslockarrays = gl_checkextension("GL_EXT_compiled_vertex_array", compiledvertexarrayfuncs, "-nocva", false);
420 // we don't care if it's an extension or not, they are identical functions, so keep it simple in the rendering code
421 if (qglDrawRangeElements == NULL)
422 qglDrawRangeElements = qglDrawRangeElementsEXT;
425 void Force_CenterView_f (void)
427 cl.viewangles[PITCH] = 0;
430 void IN_PreMove(void)
434 void CL_AdjustAngles(void);
435 void IN_PostMove(void)
437 // clamp after the move as well to prevent messed up rendering angles
441 void IN_Mouse(usercmd_t *cmd, float mx, float my)
443 int mouselook = (in_mlook.state & 1) || freelook.integer;
444 float mouse_x, mouse_y;
445 static float old_mouse_x = 0, old_mouse_y = 0;
447 if (m_filter.integer)
449 mouse_x = (mx + old_mouse_x) * 0.5;
450 mouse_y = (my + old_mouse_y) * 0.5;
461 // LordHavoc: viewzoom affects mouse sensitivity for sniping
462 mouse_x *= sensitivity.value * cl.viewzoom;
463 mouse_y *= sensitivity.value * cl.viewzoom;
465 // Add mouse X/Y movement to cmd
466 if ((in_strafe.state & 1) || (lookstrafe.integer && mouselook))
467 cmd->sidemove += m_side.value * mouse_x;
469 cl.viewangles[YAW] -= m_yaw.value * mouse_x;
474 if (mouselook && !(in_strafe.state & 1))
475 cl.viewangles[PITCH] += m_pitch.value * mouse_y;
478 if ((in_strafe.state & 1) && noclip_anglehack)
479 cmd->upmove -= m_forward.value * mouse_y;
481 cmd->forwardmove -= m_forward.value * mouse_y;
485 void VID_InitCvars(void)
487 Cvar_RegisterVariable(&vid_mode);
488 Cvar_RegisterVariable(&vid_mouse);
489 Cvar_RegisterVariable(&vid_fullscreen);
490 Cvar_RegisterVariable(&gl_combine);
491 Cvar_RegisterVariable(&in_pitch_min);
492 Cvar_RegisterVariable(&in_pitch_max);
493 Cvar_RegisterVariable(&m_filter);
494 Cmd_AddCommand("force_centerview", Force_CenterView_f);