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 cvar_t vid_mode = {0, "vid_mode", "0"};
16 cvar_t vid_mouse = {CVAR_SAVE, "vid_mouse", "1"};
17 cvar_t vid_fullscreen = {0, "vid_fullscreen", "1"};
18 cvar_t gl_combine = {0, "gl_combine", "1"};
20 cvar_t in_pitch_min = {0, "in_pitch_min", "-90"};
21 cvar_t in_pitch_max = {0, "in_pitch_max", "90"};
23 cvar_t m_filter = {CVAR_SAVE, "m_filter","0"};
25 // GL_ARB_multitexture
26 void (GLAPIENTRY *qglMultiTexCoord2f) (GLenum, GLfloat, GLfloat);
27 void (GLAPIENTRY *qglActiveTexture) (GLenum);
28 void (GLAPIENTRY *qglClientActiveTexture) (GLenum);
30 // GL_EXT_compiled_vertex_array
31 void (GLAPIENTRY *qglLockArraysEXT) (GLint first, GLint count);
32 void (GLAPIENTRY *qglUnlockArraysEXT) (void);
35 // general GL functions
37 void (GLAPIENTRY *qglClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
39 void (GLAPIENTRY *qglClear)(GLbitfield mask);
41 //void (GLAPIENTRY *qglAlphaFunc)(GLenum func, GLclampf ref);
42 void (GLAPIENTRY *qglBlendFunc)(GLenum sfactor, GLenum dfactor);
43 void (GLAPIENTRY *qglCullFace)(GLenum mode);
45 void (GLAPIENTRY *qglDrawBuffer)(GLenum mode);
46 void (GLAPIENTRY *qglReadBuffer)(GLenum mode);
47 void (GLAPIENTRY *qglEnable)(GLenum cap);
48 void (GLAPIENTRY *qglDisable)(GLenum cap);
49 //GLboolean GLAPIENTRY *qglIsEnabled)(GLenum cap);
51 void (GLAPIENTRY *qglEnableClientState)(GLenum cap);
52 void (GLAPIENTRY *qglDisableClientState)(GLenum cap);
54 //void (GLAPIENTRY *qglGetBooleanv)(GLenum pname, GLboolean *params);
55 //void (GLAPIENTRY *qglGetDoublev)(GLenum pname, GLdouble *params);
56 //void (GLAPIENTRY *qglGetFloatv)(GLenum pname, GLfloat *params);
57 void (GLAPIENTRY *qglGetIntegerv)(GLenum pname, GLint *params);
59 GLenum (GLAPIENTRY *qglGetError)(void);
60 const GLubyte* (GLAPIENTRY *qglGetString)(GLenum name);
61 void (GLAPIENTRY *qglFinish)(void);
62 void (GLAPIENTRY *qglFlush)(void);
64 void (GLAPIENTRY *qglClearDepth)(GLclampd depth);
65 void (GLAPIENTRY *qglDepthFunc)(GLenum func);
66 void (GLAPIENTRY *qglDepthMask)(GLboolean flag);
67 void (GLAPIENTRY *qglDepthRange)(GLclampd near_val, GLclampd far_val);
69 void (GLAPIENTRY *qglDrawRangeElements)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
70 void (GLAPIENTRY *qglDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
71 void (GLAPIENTRY *qglVertexPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
72 //void (GLAPIENTRY *qglNormalPointer)(GLenum type, GLsizei stride, const GLvoid *ptr);
73 void (GLAPIENTRY *qglColorPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
74 void (GLAPIENTRY *qglTexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
75 void (GLAPIENTRY *qglArrayElement)(GLint i);
77 void (GLAPIENTRY *qglColor4ub)(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha);
78 void (GLAPIENTRY *qglTexCoord2f)(GLfloat s, GLfloat t);
79 void (GLAPIENTRY *qglVertex2f)(GLfloat x, GLfloat y);
80 void (GLAPIENTRY *qglVertex3f)(GLfloat x, GLfloat y, GLfloat z);
81 void (GLAPIENTRY *qglBegin)(GLenum mode);
82 void (GLAPIENTRY *qglEnd)(void);
84 void (GLAPIENTRY *qglMatrixMode)(GLenum mode);
85 void (GLAPIENTRY *qglOrtho)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val);
86 void (GLAPIENTRY *qglFrustum)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val);
87 void (GLAPIENTRY *qglViewport)(GLint x, GLint y, GLsizei width, GLsizei height);
88 //void (GLAPIENTRY *qglPushMatrix)(void);
89 //void (GLAPIENTRY *qglPopMatrix)(void);
90 void (GLAPIENTRY *qglLoadIdentity)(void);
91 //void (GLAPIENTRY *qglLoadMatrixd)(const GLdouble *m);
92 //void (GLAPIENTRY *qglLoadMatrixf)(const GLfloat *m);
93 //void (GLAPIENTRY *qglMultMatrixd)(const GLdouble *m);
94 //void (GLAPIENTRY *qglMultMatrixf)(const GLfloat *m);
95 //void (GLAPIENTRY *qglRotated)(GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
96 void (GLAPIENTRY *qglRotatef)(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
97 //void (GLAPIENTRY *qglScaled)(GLdouble x, GLdouble y, GLdouble z);
98 //void (GLAPIENTRY *qglScalef)(GLfloat x, GLfloat y, GLfloat z);
99 //void (GLAPIENTRY *qglTranslated)(GLdouble x, GLdouble y, GLdouble z);
100 void (GLAPIENTRY *qglTranslatef)(GLfloat x, GLfloat y, GLfloat z);
102 void (GLAPIENTRY *qglReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
104 //void (GLAPIENTRY *qglStencilFunc)(GLenum func, GLint ref, GLuint mask);
105 //void (GLAPIENTRY *qglStencilMask)(GLuint mask);
106 //void (GLAPIENTRY *qglStencilOp)(GLenum fail, GLenum zfail, GLenum zpass);
107 //void (GLAPIENTRY *qglClearStencil)(GLint s);
109 //void (GLAPIENTRY *qglTexEnvf)(GLenum target, GLenum pname, GLfloat param);
110 void (GLAPIENTRY *qglTexEnvi)(GLenum target, GLenum pname, GLint param);
112 //void (GLAPIENTRY *qglTexParameterf)(GLenum target, GLenum pname, GLfloat param);
113 void (GLAPIENTRY *qglTexParameteri)(GLenum target, GLenum pname, GLint param);
115 void (GLAPIENTRY *qglBindTexture)(GLenum target, GLuint texture);
116 void (GLAPIENTRY *qglTexImage2D)(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
117 void (GLAPIENTRY *qglTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
118 void (GLAPIENTRY *qglDeleteTextures)(GLsizei n, const GLuint *textures);
120 void (GLAPIENTRY *qglDrawRangeElementsEXT)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
122 //void (GLAPIENTRY *qglColorTableEXT)(int, int, int, int, int, const void *);
125 int (WINAPI *qwglChoosePixelFormat)(HDC, CONST PIXELFORMATDESCRIPTOR *);
126 int (WINAPI *qwglDescribePixelFormat)(HDC, int, UINT, LPPIXELFORMATDESCRIPTOR);
127 //int (WINAPI *qwglGetPixelFormat)(HDC);
128 BOOL (WINAPI *qwglSetPixelFormat)(HDC, int, CONST PIXELFORMATDESCRIPTOR *);
129 BOOL (WINAPI *qwglSwapBuffers)(HDC);
130 HGLRC (WINAPI *qwglCreateContext)(HDC);
131 BOOL (WINAPI *qwglDeleteContext)(HGLRC);
132 PROC (WINAPI *qwglGetProcAddress)(LPCSTR);
133 BOOL (WINAPI *qwglMakeCurrent)(HDC, HGLRC);
134 //BOOL (WINAPI *qwglSwapIntervalEXT)(int interval);
143 gl_extensionfunctionlist_t;
148 gl_extensionfunctionlist_t *funcs;
155 static gl_extensionfunctionlist_t wglfuncs[] =
157 {"wglChoosePixelFormat", (void **) &qwglChoosePixelFormat},
158 {"wglDescribePixelFormat", (void **) &qwglDescribePixelFormat},
159 // {"wglGetPixelFormat", (void **) &qwglGetPixelFormat},
160 {"wglSetPixelFormat", (void **) &qwglSetPixelFormat},
161 {"wglSwapBuffers", (void **) &qwglSwapBuffers},
162 {"wglCreateContext", (void **) &qwglCreateContext},
163 {"wglDeleteContext", (void **) &qwglDeleteContext},
164 {"wglGetProcAddress", (void **) &qwglGetProcAddress},
165 {"wglMakeCurrent", (void **) &qwglMakeCurrent},
170 static gl_extensionfunctionlist_t wglswapintervalfuncs[] =
172 {"wglSwapIntervalEXT", (void **) &qwglSwapIntervalEXT},
178 static gl_extensionfunctionlist_t opengl110funcs[] =
180 {"glClearColor", (void **) &qglClearColor},
181 {"glClear", (void **) &qglClear},
182 // {"glAlphaFunc", (void **) &qglAlphaFunc},
183 {"glBlendFunc", (void **) &qglBlendFunc},
184 {"glCullFace", (void **) &qglCullFace},
185 {"glDrawBuffer", (void **) &qglDrawBuffer},
186 {"glReadBuffer", (void **) &qglReadBuffer},
187 {"glEnable", (void **) &qglEnable},
188 {"glDisable", (void **) &qglDisable},
189 // {"glIsEnabled", (void **) &qglIsEnabled},
190 {"glEnableClientState", (void **) &qglEnableClientState},
191 {"glDisableClientState", (void **) &qglDisableClientState},
192 // {"glGetBooleanv", (void **) &qglGetBooleanv},
193 // {"glGetDoublev", (void **) &qglGetDoublev},
194 // {"glGetFloatv", (void **) &qglGetFloatv},
195 {"glGetIntegerv", (void **) &qglGetIntegerv},
196 {"glGetError", (void **) &qglGetError},
197 {"glGetString", (void **) &qglGetString},
198 {"glFinish", (void **) &qglFinish},
199 {"glFlush", (void **) &qglFlush},
200 {"glClearDepth", (void **) &qglClearDepth},
201 {"glDepthFunc", (void **) &qglDepthFunc},
202 {"glDepthMask", (void **) &qglDepthMask},
203 {"glDepthRange", (void **) &qglDepthRange},
204 {"glDrawElements", (void **) &qglDrawElements},
205 {"glVertexPointer", (void **) &qglVertexPointer},
206 // {"glNormalPointer", (void **) &qglNormalPointer},
207 {"glColorPointer", (void **) &qglColorPointer},
208 {"glTexCoordPointer", (void **) &qglTexCoordPointer},
209 {"glArrayElement", (void **) &qglArrayElement},
210 {"glColor4ub", (void **) &qglColor4ub},
211 {"glTexCoord2f", (void **) &qglTexCoord2f},
212 {"glVertex2f", (void **) &qglVertex2f},
213 {"glVertex3f", (void **) &qglVertex3f},
214 {"glBegin", (void **) &qglBegin},
215 {"glEnd", (void **) &qglEnd},
216 {"glMatrixMode", (void **) &qglMatrixMode},
217 {"glOrtho", (void **) &qglOrtho},
218 {"glFrustum", (void **) &qglFrustum},
219 {"glViewport", (void **) &qglViewport},
220 // {"glPushMatrix", (void **) &qglPushMatrix},
221 // {"glPopMatrix", (void **) &qglPopMatrix},
222 {"glLoadIdentity", (void **) &qglLoadIdentity},
223 // {"glLoadMatrixd", (void **) &qglLoadMatrixd},
224 // {"glLoadMatrixf", (void **) &qglLoadMatrixf},
225 // {"glMultMatrixd", (void **) &qglMultMatrixd},
226 // {"glMultMatrixf", (void **) &qglMultMatrixf},
227 // {"glRotated", (void **) &qglRotated},
228 {"glRotatef", (void **) &qglRotatef},
229 // {"glScaled", (void **) &qglScaled},
230 // {"glScalef", (void **) &qglScalef},
231 // {"glTranslated", (void **) &qglTranslated},
232 {"glTranslatef", (void **) &qglTranslatef},
233 {"glReadPixels", (void **) &qglReadPixels},
234 // {"glStencilFunc", (void **) &qglStencilFunc},
235 // {"glStencilMask", (void **) &qglStencilMask},
236 // {"glStencilOp", (void **) &qglStencilOp},
237 // {"glClearStencil", (void **) &qglClearStencil},
238 // {"glTexEnvf", (void **) &qglTexEnvf},
239 {"glTexEnvi", (void **) &qglTexEnvi},
240 // {"glTexParameterf", (void **) &qglTexParameterf},
241 {"glTexParameteri", (void **) &qglTexParameteri},
242 {"glBindTexture", (void **) &qglBindTexture},
243 {"glTexImage2D", (void **) &qglTexImage2D},
244 {"glTexSubImage2D", (void **) &qglTexSubImage2D},
245 {"glDeleteTextures", (void **) &qglDeleteTextures},
249 static gl_extensionfunctionlist_t drawrangeelementsfuncs[] =
251 {"glDrawRangeElements", (void **) &qglDrawRangeElements},
255 static gl_extensionfunctionlist_t drawrangeelementsextfuncs[] =
257 {"glDrawRangeElementsEXT", (void **) &qglDrawRangeElementsEXT},
261 static gl_extensionfunctionlist_t multitexturefuncs[] =
263 {"glMultiTexCoord2fARB", (void **) &qglMultiTexCoord2f},
264 {"glActiveTextureARB", (void **) &qglActiveTexture},
265 {"glClientActiveTextureARB", (void **) &qglClientActiveTexture},
269 static gl_extensionfunctionlist_t compiledvertexarrayfuncs[] =
271 {"glLockArraysEXT", (void **) &qglLockArraysEXT},
272 {"glUnlockArraysEXT", (void **) &qglUnlockArraysEXT},
281 static HINSTANCE gldll;
283 static void *prjobj = NULL;
286 static void gl_getfuncs_begin(void)
289 gldll = LoadLibrary("opengl32.dll");
294 prjobj = dlopen(NULL, RTLD_LAZY);
297 Con_Printf("Unable to open symbol list for main program.\n");
303 static void gl_getfuncs_end(void)
314 static void *gl_getfuncaddress(char *name)
318 if (qwglGetProcAddress != NULL)
319 p = (void *) qwglGetProcAddress(name);
321 p = (void *) GetProcAddress(gldll, name);
323 p = (void *) dlsym(prjobj, name);
328 static int gl_checkextension(char *name, gl_extensionfunctionlist_t *funcs, char *disableparm, int silent)
331 gl_extensionfunctionlist_t *func;
333 Con_Printf("checking for %s... ", name);
335 for (func = funcs;func && func->name;func++)
336 *func->funcvariable = NULL;
338 if (disableparm && COM_CheckParm(disableparm))
340 Con_Printf("disabled by commandline\n");
344 if (strncmp(name, "GL_", 3) || strstr(gl_extensions, name))
346 for (func = funcs;func && func->name != NULL;func++)
348 // functions are cleared before all the extensions are evaluated
349 if (!(*func->funcvariable = (void *) gl_getfuncaddress(func->name)))
352 Con_Printf("missing function \"%s\" - broken driver!\n", func->name);
356 // delay the return so it prints all missing functions
359 Con_Printf("enabled\n");
364 Con_Printf("not detected\n");
369 void VID_CheckExtensions(void)
371 Con_Printf("Checking OpenGL extensions...\n");
375 gl_combine_extension = false;
376 gl_supportslockarrays = false;
380 if (!gl_checkextension("wgl", wglfuncs, NULL, false))
381 Sys_Error("wgl functions not found\n");
382 //gl_checkextension("wglSwapIntervalEXT", wglswapintervalfuncs, NULL, false);
385 if (!gl_checkextension("OpenGL 1.1.0", opengl110funcs, NULL, false))
386 Sys_Error("OpenGL 1.1.0 functions not found\n");
388 if (!gl_checkextension("glDrawRangeElements", drawrangeelementsfuncs, "-nodrawrangeelements", true))
389 gl_checkextension("GL_EXT_draw_range_elements", drawrangeelementsextfuncs, "-nodrawrangeelements", true);
391 if (gl_checkextension("GL_ARB_multitexture", multitexturefuncs, "-nomtex", false))
393 qglGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_textureunits);
394 if (gl_textureunits > 1)
395 gl_combine_extension = gl_checkextension("GL_ARB_texture_env_combine", NULL, "-nocombine", false) || gl_checkextension("GL_EXT_texture_env_combine", NULL, "-nocombine", false);
398 Con_Printf("GL_ARB_multitexture with less than 2 units? - BROKEN DRIVER!\n");
399 gl_textureunits = 1; // for sanity sake, make sure it's not 0
403 gl_supportslockarrays = gl_checkextension("GL_EXT_compiled_vertex_array", compiledvertexarrayfuncs, "-nocva", false);
407 // we don't care if it's an extension or not, they are identical functions, so keep it simple in the rendering code
408 if (qglDrawRangeElements == NULL)
409 qglDrawRangeElements = qglDrawRangeElementsEXT;
412 void Force_CenterView_f (void)
414 cl.viewangles[PITCH] = 0;
417 void IN_PreMove(void)
421 void CL_AdjustAngles(void);
422 void IN_PostMove(void)
424 // clamp after the move as well to prevent messed up rendering angles
428 void IN_Mouse(usercmd_t *cmd, float mx, float my)
430 int mouselook = (in_mlook.state & 1) || freelook.integer;
431 float mouse_x, mouse_y;
432 static float old_mouse_x = 0, old_mouse_y = 0;
434 if (m_filter.integer)
436 mouse_x = (mx + old_mouse_x) * 0.5;
437 mouse_y = (my + old_mouse_y) * 0.5;
448 // LordHavoc: viewzoom affects mouse sensitivity for sniping
449 mouse_x *= sensitivity.value * cl.viewzoom;
450 mouse_y *= sensitivity.value * cl.viewzoom;
452 // Add mouse X/Y movement to cmd
453 if ((in_strafe.state & 1) || (lookstrafe.integer && mouselook))
454 cmd->sidemove += m_side.value * mouse_x;
456 cl.viewangles[YAW] -= m_yaw.value * mouse_x;
461 if (mouselook && !(in_strafe.state & 1))
462 cl.viewangles[PITCH] += m_pitch.value * mouse_y;
465 if ((in_strafe.state & 1) && noclip_anglehack)
466 cmd->upmove -= m_forward.value * mouse_y;
468 cmd->forwardmove -= m_forward.value * mouse_y;
472 void VID_InitCvars(void)
474 Cvar_RegisterVariable(&vid_mode);
475 Cvar_RegisterVariable(&vid_mouse);
476 Cvar_RegisterVariable(&vid_fullscreen);
477 Cvar_RegisterVariable(&gl_combine);
478 Cvar_RegisterVariable(&in_pitch_min);
479 Cvar_RegisterVariable(&in_pitch_max);
480 Cvar_RegisterVariable(&m_filter);
481 Cmd_AddCommand("force_centerview", Force_CenterView_f);