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 // LordHavoc: if window is hidden, don't update screen
16 int vid_hidden = false;
17 // LordHavoc: if window is not the active window, don't hog as much CPU time,
18 // let go of the mouse, turn off sound, and restore system gamma ramps...
19 int vid_activewindow = true;
21 cvar_t vid_mode = {0, "vid_mode", "0"};
22 cvar_t vid_mouse = {CVAR_SAVE, "vid_mouse", "1"};
23 cvar_t vid_fullscreen = {0, "vid_fullscreen", "1"};
24 cvar_t gl_combine = {0, "gl_combine", "1"};
26 cvar_t in_pitch_min = {0, "in_pitch_min", "-90"};
27 cvar_t in_pitch_max = {0, "in_pitch_max", "90"};
29 cvar_t m_filter = {CVAR_SAVE, "m_filter","0"};
31 const char *gl_vendor;
32 const char *gl_renderer;
33 const char *gl_version;
34 const char *gl_extensions;
36 // GL_ARB_multitexture
37 void (GLAPIENTRY *qglMultiTexCoord2f) (GLenum, GLfloat, GLfloat);
38 void (GLAPIENTRY *qglActiveTexture) (GLenum);
39 void (GLAPIENTRY *qglClientActiveTexture) (GLenum);
41 // GL_EXT_compiled_vertex_array
42 void (GLAPIENTRY *qglLockArraysEXT) (GLint first, GLint count);
43 void (GLAPIENTRY *qglUnlockArraysEXT) (void);
46 // general GL functions
48 void (GLAPIENTRY *qglClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
50 void (GLAPIENTRY *qglClear)(GLbitfield mask);
52 //void (GLAPIENTRY *qglAlphaFunc)(GLenum func, GLclampf ref);
53 void (GLAPIENTRY *qglBlendFunc)(GLenum sfactor, GLenum dfactor);
54 void (GLAPIENTRY *qglCullFace)(GLenum mode);
56 void (GLAPIENTRY *qglDrawBuffer)(GLenum mode);
57 void (GLAPIENTRY *qglReadBuffer)(GLenum mode);
58 void (GLAPIENTRY *qglEnable)(GLenum cap);
59 void (GLAPIENTRY *qglDisable)(GLenum cap);
60 //GLboolean GLAPIENTRY *qglIsEnabled)(GLenum cap);
62 void (GLAPIENTRY *qglEnableClientState)(GLenum cap);
63 void (GLAPIENTRY *qglDisableClientState)(GLenum cap);
65 //void (GLAPIENTRY *qglGetBooleanv)(GLenum pname, GLboolean *params);
66 //void (GLAPIENTRY *qglGetDoublev)(GLenum pname, GLdouble *params);
67 //void (GLAPIENTRY *qglGetFloatv)(GLenum pname, GLfloat *params);
68 void (GLAPIENTRY *qglGetIntegerv)(GLenum pname, GLint *params);
70 GLenum (GLAPIENTRY *qglGetError)(void);
71 const GLubyte* (GLAPIENTRY *qglGetString)(GLenum name);
72 void (GLAPIENTRY *qglFinish)(void);
73 void (GLAPIENTRY *qglFlush)(void);
75 void (GLAPIENTRY *qglClearDepth)(GLclampd depth);
76 void (GLAPIENTRY *qglDepthFunc)(GLenum func);
77 void (GLAPIENTRY *qglDepthMask)(GLboolean flag);
78 void (GLAPIENTRY *qglDepthRange)(GLclampd near_val, GLclampd far_val);
80 void (GLAPIENTRY *qglDrawRangeElements)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
81 void (GLAPIENTRY *qglDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices);
82 void (GLAPIENTRY *qglVertexPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
83 //void (GLAPIENTRY *qglNormalPointer)(GLenum type, GLsizei stride, const GLvoid *ptr);
84 void (GLAPIENTRY *qglColorPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
85 void (GLAPIENTRY *qglTexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
86 void (GLAPIENTRY *qglArrayElement)(GLint i);
88 void (GLAPIENTRY *qglColor4ub)(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha);
89 void (GLAPIENTRY *qglTexCoord2f)(GLfloat s, GLfloat t);
90 void (GLAPIENTRY *qglVertex2f)(GLfloat x, GLfloat y);
91 void (GLAPIENTRY *qglVertex3f)(GLfloat x, GLfloat y, GLfloat z);
92 void (GLAPIENTRY *qglBegin)(GLenum mode);
93 void (GLAPIENTRY *qglEnd)(void);
95 void (GLAPIENTRY *qglMatrixMode)(GLenum mode);
96 void (GLAPIENTRY *qglOrtho)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val);
97 void (GLAPIENTRY *qglFrustum)(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near_val, GLdouble far_val);
98 void (GLAPIENTRY *qglViewport)(GLint x, GLint y, GLsizei width, GLsizei height);
99 //void (GLAPIENTRY *qglPushMatrix)(void);
100 //void (GLAPIENTRY *qglPopMatrix)(void);
101 void (GLAPIENTRY *qglLoadIdentity)(void);
102 //void (GLAPIENTRY *qglLoadMatrixd)(const GLdouble *m);
103 //void (GLAPIENTRY *qglLoadMatrixf)(const GLfloat *m);
104 //void (GLAPIENTRY *qglMultMatrixd)(const GLdouble *m);
105 //void (GLAPIENTRY *qglMultMatrixf)(const GLfloat *m);
106 //void (GLAPIENTRY *qglRotated)(GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
107 void (GLAPIENTRY *qglRotatef)(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
108 //void (GLAPIENTRY *qglScaled)(GLdouble x, GLdouble y, GLdouble z);
109 //void (GLAPIENTRY *qglScalef)(GLfloat x, GLfloat y, GLfloat z);
110 //void (GLAPIENTRY *qglTranslated)(GLdouble x, GLdouble y, GLdouble z);
111 void (GLAPIENTRY *qglTranslatef)(GLfloat x, GLfloat y, GLfloat z);
113 void (GLAPIENTRY *qglReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
115 //void (GLAPIENTRY *qglStencilFunc)(GLenum func, GLint ref, GLuint mask);
116 //void (GLAPIENTRY *qglStencilMask)(GLuint mask);
117 //void (GLAPIENTRY *qglStencilOp)(GLenum fail, GLenum zfail, GLenum zpass);
118 //void (GLAPIENTRY *qglClearStencil)(GLint s);
120 //void (GLAPIENTRY *qglTexEnvf)(GLenum target, GLenum pname, GLfloat param);
121 void (GLAPIENTRY *qglTexEnvi)(GLenum target, GLenum pname, GLint param);
123 //void (GLAPIENTRY *qglTexParameterf)(GLenum target, GLenum pname, GLfloat param);
124 void (GLAPIENTRY *qglTexParameteri)(GLenum target, GLenum pname, GLint param);
126 void (GLAPIENTRY *qglBindTexture)(GLenum target, GLuint texture);
127 void (GLAPIENTRY *qglTexImage2D)(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
128 void (GLAPIENTRY *qglTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
129 void (GLAPIENTRY *qglDeleteTextures)(GLsizei n, const GLuint *textures);
131 void (GLAPIENTRY *qglDrawRangeElementsEXT)(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices);
133 //void (GLAPIENTRY *qglColorTableEXT)(int, int, int, int, int, const void *);
136 int (WINAPI *qwglChoosePixelFormat)(HDC, CONST PIXELFORMATDESCRIPTOR *);
137 int (WINAPI *qwglDescribePixelFormat)(HDC, int, UINT, LPPIXELFORMATDESCRIPTOR);
138 //int (WINAPI *qwglGetPixelFormat)(HDC);
139 BOOL (WINAPI *qwglSetPixelFormat)(HDC, int, CONST PIXELFORMATDESCRIPTOR *);
140 BOOL (WINAPI *qwglSwapBuffers)(HDC);
141 HGLRC (WINAPI *qwglCreateContext)(HDC);
142 BOOL (WINAPI *qwglDeleteContext)(HGLRC);
143 PROC (WINAPI *qwglGetProcAddress)(LPCSTR);
144 BOOL (WINAPI *qwglMakeCurrent)(HDC, HGLRC);
145 //BOOL (WINAPI *qwglSwapIntervalEXT)(int interval);
154 gl_extensionfunctionlist_t;
159 gl_extensionfunctionlist_t *funcs;
166 static gl_extensionfunctionlist_t wglfuncs[] =
168 {"wglChoosePixelFormat", (void **) &qwglChoosePixelFormat},
169 {"wglDescribePixelFormat", (void **) &qwglDescribePixelFormat},
170 // {"wglGetPixelFormat", (void **) &qwglGetPixelFormat},
171 {"wglSetPixelFormat", (void **) &qwglSetPixelFormat},
172 {"wglSwapBuffers", (void **) &qwglSwapBuffers},
173 {"wglCreateContext", (void **) &qwglCreateContext},
174 {"wglDeleteContext", (void **) &qwglDeleteContext},
175 {"wglGetProcAddress", (void **) &qwglGetProcAddress},
176 {"wglMakeCurrent", (void **) &qwglMakeCurrent},
181 static gl_extensionfunctionlist_t wglswapintervalfuncs[] =
183 {"wglSwapIntervalEXT", (void **) &qwglSwapIntervalEXT},
189 static gl_extensionfunctionlist_t opengl110funcs[] =
191 {"glClearColor", (void **) &qglClearColor},
192 {"glClear", (void **) &qglClear},
193 // {"glAlphaFunc", (void **) &qglAlphaFunc},
194 {"glBlendFunc", (void **) &qglBlendFunc},
195 {"glCullFace", (void **) &qglCullFace},
196 {"glDrawBuffer", (void **) &qglDrawBuffer},
197 {"glReadBuffer", (void **) &qglReadBuffer},
198 {"glEnable", (void **) &qglEnable},
199 {"glDisable", (void **) &qglDisable},
200 // {"glIsEnabled", (void **) &qglIsEnabled},
201 {"glEnableClientState", (void **) &qglEnableClientState},
202 {"glDisableClientState", (void **) &qglDisableClientState},
203 // {"glGetBooleanv", (void **) &qglGetBooleanv},
204 // {"glGetDoublev", (void **) &qglGetDoublev},
205 // {"glGetFloatv", (void **) &qglGetFloatv},
206 {"glGetIntegerv", (void **) &qglGetIntegerv},
207 {"glGetError", (void **) &qglGetError},
208 {"glGetString", (void **) &qglGetString},
209 {"glFinish", (void **) &qglFinish},
210 {"glFlush", (void **) &qglFlush},
211 {"glClearDepth", (void **) &qglClearDepth},
212 {"glDepthFunc", (void **) &qglDepthFunc},
213 {"glDepthMask", (void **) &qglDepthMask},
214 {"glDepthRange", (void **) &qglDepthRange},
215 {"glDrawElements", (void **) &qglDrawElements},
216 {"glVertexPointer", (void **) &qglVertexPointer},
217 // {"glNormalPointer", (void **) &qglNormalPointer},
218 {"glColorPointer", (void **) &qglColorPointer},
219 {"glTexCoordPointer", (void **) &qglTexCoordPointer},
220 {"glArrayElement", (void **) &qglArrayElement},
221 {"glColor4ub", (void **) &qglColor4ub},
222 {"glTexCoord2f", (void **) &qglTexCoord2f},
223 {"glVertex2f", (void **) &qglVertex2f},
224 {"glVertex3f", (void **) &qglVertex3f},
225 {"glBegin", (void **) &qglBegin},
226 {"glEnd", (void **) &qglEnd},
227 {"glMatrixMode", (void **) &qglMatrixMode},
228 {"glOrtho", (void **) &qglOrtho},
229 {"glFrustum", (void **) &qglFrustum},
230 {"glViewport", (void **) &qglViewport},
231 // {"glPushMatrix", (void **) &qglPushMatrix},
232 // {"glPopMatrix", (void **) &qglPopMatrix},
233 {"glLoadIdentity", (void **) &qglLoadIdentity},
234 // {"glLoadMatrixd", (void **) &qglLoadMatrixd},
235 // {"glLoadMatrixf", (void **) &qglLoadMatrixf},
236 // {"glMultMatrixd", (void **) &qglMultMatrixd},
237 // {"glMultMatrixf", (void **) &qglMultMatrixf},
238 // {"glRotated", (void **) &qglRotated},
239 {"glRotatef", (void **) &qglRotatef},
240 // {"glScaled", (void **) &qglScaled},
241 // {"glScalef", (void **) &qglScalef},
242 // {"glTranslated", (void **) &qglTranslated},
243 {"glTranslatef", (void **) &qglTranslatef},
244 {"glReadPixels", (void **) &qglReadPixels},
245 // {"glStencilFunc", (void **) &qglStencilFunc},
246 // {"glStencilMask", (void **) &qglStencilMask},
247 // {"glStencilOp", (void **) &qglStencilOp},
248 // {"glClearStencil", (void **) &qglClearStencil},
249 // {"glTexEnvf", (void **) &qglTexEnvf},
250 {"glTexEnvi", (void **) &qglTexEnvi},
251 // {"glTexParameterf", (void **) &qglTexParameterf},
252 {"glTexParameteri", (void **) &qglTexParameteri},
253 {"glBindTexture", (void **) &qglBindTexture},
254 {"glTexImage2D", (void **) &qglTexImage2D},
255 {"glTexSubImage2D", (void **) &qglTexSubImage2D},
256 {"glDeleteTextures", (void **) &qglDeleteTextures},
260 static gl_extensionfunctionlist_t drawrangeelementsfuncs[] =
262 {"glDrawRangeElements", (void **) &qglDrawRangeElements},
266 static gl_extensionfunctionlist_t drawrangeelementsextfuncs[] =
268 {"glDrawRangeElementsEXT", (void **) &qglDrawRangeElementsEXT},
272 static gl_extensionfunctionlist_t multitexturefuncs[] =
274 {"glMultiTexCoord2fARB", (void **) &qglMultiTexCoord2f},
275 {"glActiveTextureARB", (void **) &qglActiveTexture},
276 {"glClientActiveTextureARB", (void **) &qglClientActiveTexture},
280 static gl_extensionfunctionlist_t compiledvertexarrayfuncs[] =
282 {"glLockArraysEXT", (void **) &qglLockArraysEXT},
283 {"glUnlockArraysEXT", (void **) &qglUnlockArraysEXT},
292 static HINSTANCE gldll;
294 static void *prjobj = NULL;
297 void GL_OpenLibrary(void)
302 if (!(gldll = LoadLibrary("opengl32.dll")))
303 Sys_Error("Unable to LoadLibrary opengl32.dll\n");
307 if (!(prjobj = dlopen("libGL.so.1", RTLD_LAZY)))
308 Sys_Error("Unable to open symbol list for libGL.so.1\n");
312 void GL_CloseLibrary(void)
324 void *GL_GetProcAddress(char *name)
328 if (qwglGetProcAddress != NULL)
329 p = (void *) qwglGetProcAddress(name);
331 p = (void *) GetProcAddress(gldll, name);
333 p = (void *) dlsym(prjobj, name);
338 static int gl_checkextension(char *name, gl_extensionfunctionlist_t *funcs, char *disableparm, int silent)
341 gl_extensionfunctionlist_t *func;
343 Con_Printf("checking for %s... ", name);
345 for (func = funcs;func && func->name;func++)
346 *func->funcvariable = NULL;
348 if (disableparm && COM_CheckParm(disableparm))
350 Con_Printf("disabled by commandline\n");
354 if (strncmp(name, "GL_", 3) || strstr(gl_extensions, name))
356 for (func = funcs;func && func->name != NULL;func++)
358 // functions are cleared before all the extensions are evaluated
359 if (!(*func->funcvariable = (void *) GL_GetProcAddress(func->name)))
362 Con_Printf("missing function \"%s\" - broken driver!\n", func->name);
366 // delay the return so it prints all missing functions
369 Con_Printf("enabled\n");
374 Con_Printf("not detected\n");
379 void VID_CheckExtensions(void)
384 gl_extensions = NULL;
386 Con_Printf("Opening OpenGL library to retrieve functions\n");
388 gl_combine_extension = false;
389 gl_supportslockarrays = false;
393 if (!gl_checkextension("wgl", wglfuncs, NULL, false))
394 Sys_Error("wgl functions not found\n");
395 //gl_checkextension("wglSwapIntervalEXT", wglswapintervalfuncs, NULL, false);
398 if (!gl_checkextension("OpenGL 1.1.0", opengl110funcs, NULL, false))
399 Sys_Error("OpenGL 1.1.0 functions not found\n");
401 gl_vendor = qglGetString (GL_VENDOR);
402 gl_renderer = qglGetString (GL_RENDERER);
403 gl_version = qglGetString (GL_VERSION);
404 gl_extensions = qglGetString (GL_EXTENSIONS);
406 Con_Printf ("GL_VENDOR: %s\n", gl_vendor);
407 Con_Printf ("GL_RENDERER: %s\n", gl_renderer);
408 Con_Printf ("GL_VERSION: %s\n", gl_version);
409 Con_Printf ("GL_EXTENSIONS: %s\n", gl_extensions);
411 Con_Printf("Checking OpenGL extensions...\n");
413 if (!gl_checkextension("glDrawRangeElements", drawrangeelementsfuncs, "-nodrawrangeelements", true))
414 gl_checkextension("GL_EXT_draw_range_elements", drawrangeelementsextfuncs, "-nodrawrangeelements", false);
416 if (gl_checkextension("GL_ARB_multitexture", multitexturefuncs, "-nomtex", false))
418 qglGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_textureunits);
419 if (gl_textureunits > 1)
420 gl_combine_extension = gl_checkextension("GL_ARB_texture_env_combine", NULL, "-nocombine", false) || gl_checkextension("GL_EXT_texture_env_combine", NULL, "-nocombine", false);
423 Con_Printf("GL_ARB_multitexture with less than 2 units? - BROKEN DRIVER!\n");
424 gl_textureunits = 1; // for sanity sake, make sure it's not 0
428 gl_supportslockarrays = gl_checkextension("GL_EXT_compiled_vertex_array", compiledvertexarrayfuncs, "-nocva", false);
430 // we don't care if it's an extension or not, they are identical functions, so keep it simple in the rendering code
431 if (qglDrawRangeElements == NULL)
432 qglDrawRangeElements = qglDrawRangeElementsEXT;
435 void Force_CenterView_f (void)
437 cl.viewangles[PITCH] = 0;
440 void IN_PreMove(void)
444 void CL_AdjustAngles(void);
445 void IN_PostMove(void)
447 // clamp after the move as well to prevent messed up rendering angles
451 void IN_Mouse(usercmd_t *cmd, float mx, float my)
453 int mouselook = (in_mlook.state & 1) || freelook.integer;
454 float mouse_x, mouse_y;
455 static float old_mouse_x = 0, old_mouse_y = 0;
457 if (m_filter.integer)
459 mouse_x = (mx + old_mouse_x) * 0.5;
460 mouse_y = (my + old_mouse_y) * 0.5;
471 // LordHavoc: viewzoom affects mouse sensitivity for sniping
472 mouse_x *= sensitivity.value * cl.viewzoom;
473 mouse_y *= sensitivity.value * cl.viewzoom;
475 // Add mouse X/Y movement to cmd
476 if ((in_strafe.state & 1) || (lookstrafe.integer && mouselook))
477 cmd->sidemove += m_side.value * mouse_x;
479 cl.viewangles[YAW] -= m_yaw.value * mouse_x;
484 if (mouselook && !(in_strafe.state & 1))
485 cl.viewangles[PITCH] += m_pitch.value * mouse_y;
488 if ((in_strafe.state & 1) && noclip_anglehack)
489 cmd->upmove -= m_forward.value * mouse_y;
491 cmd->forwardmove -= m_forward.value * mouse_y;
495 void VID_InitCvars(void)
497 Cvar_RegisterVariable(&vid_mode);
498 Cvar_RegisterVariable(&vid_mouse);
499 Cvar_RegisterVariable(&vid_fullscreen);
500 Cvar_RegisterVariable(&gl_combine);
501 Cvar_RegisterVariable(&in_pitch_min);
502 Cvar_RegisterVariable(&in_pitch_max);
503 Cvar_RegisterVariable(&m_filter);
504 Cmd_AddCommand("force_centerview", Force_CenterView_f);