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 *qglTexImage2D)(GLenum target, GLint level, GLint internalFormat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels);
117 void (GLAPIENTRY *qglBindTexture)(GLenum target, GLuint texture);
119 void (GLAPIENTRY *qglTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels);
127 gl_extensionfunctionlist_t;
132 gl_extensionfunctionlist_t *funcs;
138 static gl_extensionfunctionlist_t opengl110funcs[] =
140 {"glClearColor", (void **) &qglClearColor},
141 {"glClear", (void **) &qglClear},
142 // {"glAlphaFunc", (void **) &qglAlphaFunc},
143 {"glBlendFunc", (void **) &qglBlendFunc},
144 {"glCullFace", (void **) &qglCullFace},
145 {"glDrawBuffer", (void **) &qglDrawBuffer},
146 {"glReadBuffer", (void **) &qglReadBuffer},
147 {"glEnable", (void **) &qglEnable},
148 {"glDisable", (void **) &qglDisable},
149 // {"glIsEnabled", (void **) &qglIsEnabled},
150 {"glEnableClientState", (void **) &qglEnableClientState},
151 {"glDisableClientState", (void **) &qglDisableClientState},
152 // {"glGetBooleanv", (void **) &qglGetBooleanv},
153 // {"glGetDoublev", (void **) &qglGetDoublev},
154 // {"glGetFloatv", (void **) &qglGetFloatv},
155 {"glGetIntegerv", (void **) &qglGetIntegerv},
156 {"glGetError", (void **) &qglGetError},
157 {"glGetString", (void **) &qglGetString},
158 {"glFinish", (void **) &qglFinish},
159 {"glFlush", (void **) &qglFlush},
160 {"glClearDepth", (void **) &qglClearDepth},
161 {"glDepthFunc", (void **) &qglDepthFunc},
162 {"glDepthMask", (void **) &qglDepthMask},
163 {"glDepthRange", (void **) &qglDepthRange},
164 {"glDrawElements", (void **) &qglDrawElements},
165 {"glVertexPointer", (void **) &qglVertexPointer},
166 // {"glNormalPointer", (void **) &qglNormalPointer},
167 {"glColorPointer", (void **) &qglColorPointer},
168 {"glTexCoordPointer", (void **) &qglTexCoordPointer},
169 {"glArrayElement", (void **) &qglArrayElement},
170 {"glColor4ub", (void **) &qglColor4ub},
171 {"glTexCoord2f", (void **) &qglTexCoord2f},
172 {"glVertex2f", (void **) &qglVertex2f},
173 {"glVertex3f", (void **) &qglVertex3f},
174 {"glBegin", (void **) &qglBegin},
175 {"glEnd", (void **) &qglEnd},
176 {"glMatrixMode", (void **) &qglMatrixMode},
177 {"glOrtho", (void **) &qglOrtho},
178 {"glFrustum", (void **) &qglFrustum},
179 {"glViewport", (void **) &qglViewport},
180 // {"glPushMatrix", (void **) &qglPushMatrix},
181 // {"glPopMatrix", (void **) &qglPopMatrix},
182 {"glLoadIdentity", (void **) &qglLoadIdentity},
183 // {"glLoadMatrixd", (void **) &qglLoadMatrixd},
184 // {"glLoadMatrixf", (void **) &qglLoadMatrixf},
185 // {"glMultMatrixd", (void **) &qglMultMatrixd},
186 // {"glMultMatrixf", (void **) &qglMultMatrixf},
187 // {"glRotated", (void **) &qglRotated},
188 {"glRotatef", (void **) &qglRotatef},
189 // {"glScaled", (void **) &qglScaled},
190 // {"glScalef", (void **) &qglScalef},
191 // {"glTranslated", (void **) &qglTranslated},
192 {"glTranslatef", (void **) &qglTranslatef},
193 {"glReadPixels", (void **) &qglReadPixels},
194 // {"glStencilFunc", (void **) &qglStencilFunc},
195 // {"glStencilMask", (void **) &qglStencilMask},
196 // {"glStencilOp", (void **) &qglStencilOp},
197 // {"glClearStencil", (void **) &qglClearStencil},
198 // {"glTexEnvf", (void **) &qglTexEnvf},
199 {"glTexEnvi", (void **) &qglTexEnvi},
200 // {"glTexParameterf", (void **) &qglTexParameterf},
201 {"glTexParameteri", (void **) &qglTexParameteri},
202 {"glTexImage2D", (void **) &qglTexImage2D},
203 {"glBindTexture", (void **) &qglBindTexture},
204 {"glTexSubImage2D", (void **) &qglTexSubImage2D},
208 static gl_extensionfunctionlist_t drawrangeelementsfuncs[] =
210 {"glDrawRangeElements", (void **) &qglDrawRangeElements},
214 static gl_extensionfunctionlist_t multitexturefuncs[] =
216 {"glMultiTexCoord2fARB", (void **) &qglMultiTexCoord2f},
217 {"glActiveTextureARB", (void **) &qglActiveTexture},
218 {"glClientActiveTextureARB", (void **) &qglClientActiveTexture},
222 static gl_extensionfunctionlist_t compiledvertexarrayfuncs[] =
224 {"glLockArraysEXT", (void **) &qglLockArraysEXT},
225 {"glUnlockArraysEXT", (void **) &qglUnlockArraysEXT},
234 static HINSTANCE gldll;
236 static void *prjobj = NULL;
239 static void gl_getfuncs_begin(void)
242 gldll = LoadLibrary("opengl32.dll");
247 prjobj = dlopen(NULL, RTLD_LAZY);
250 Con_Printf("Unable to open symbol list for main program.\n");
256 static void gl_getfuncs_end(void)
267 static void *gl_getfuncaddress(char *name)
270 // return (void *) wglGetProcAddress(name);
271 return (void *) GetProcAddress(gldll, name);
273 return (void *) dlsym(prjobj, name);
277 static int gl_checkextension(char *name, gl_extensionfunctionlist_t *funcs, char *disableparm)
280 gl_extensionfunctionlist_t *func;
282 Con_Printf("checking for %s... ", name);
284 for (func = funcs;func && func->name;func++)
285 *func->funcvariable = NULL;
287 if (disableparm && COM_CheckParm(disableparm))
289 Con_Printf("disabled by commandline\n");
293 if (!strstr(name, "GL_") || strstr(gl_extensions, name))
295 for (func = funcs;func && func->name != NULL;func++)
297 if (!(*func->funcvariable = (void *) gl_getfuncaddress(func->name)))
299 Con_Printf("missing function \"%s\"!\n", func->name);
303 // delay the return so it prints all missing functions
306 Con_Printf("enabled\n");
311 Con_Printf("not detected\n");
316 void VID_CheckExtensions(void)
318 Con_Printf("Checking OpenGL extensions...\n");
322 gl_combine_extension = false;
323 gl_supportslockarrays = false;
326 if (!gl_checkextension("OpenGL 1.1.0 or above", opengl110funcs, NULL))
327 Sys_Error("OpenGL 1.1.0 functions not found\n");
329 gl_checkextension("glDrawRangeElements", drawrangeelementsfuncs, "-nodrawrangeelements");
331 if (gl_checkextension("GL_ARB_multitexture", multitexturefuncs, "-nomtex"))
333 qglGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_textureunits);
334 if (gl_textureunits > 1)
335 gl_combine_extension = gl_checkextension("GL_ARB_texture_env_combine", NULL, "-nocombine") || gl_checkextension("GL_EXT_texture_env_combine", NULL, "-nocombine");
337 gl_textureunits = 1; // for sanity sake, make sure it's not 0
340 gl_supportslockarrays = gl_checkextension("GL_EXT_compiled_vertex_array", compiledvertexarrayfuncs, "-nocva");
345 void Force_CenterView_f (void)
347 cl.viewangles[PITCH] = 0;
350 void IN_PreMove(void)
354 void CL_AdjustAngles(void);
355 void IN_PostMove(void)
357 // clamp after the move as well to prevent messed up rendering angles
361 void IN_Mouse(usercmd_t *cmd, float mx, float my)
363 int mouselook = (in_mlook.state & 1) || freelook.integer;
364 float mouse_x, mouse_y;
365 static float old_mouse_x = 0, old_mouse_y = 0;
367 if (m_filter.integer)
369 mouse_x = (mx + old_mouse_x) * 0.5;
370 mouse_y = (my + old_mouse_y) * 0.5;
381 // LordHavoc: viewzoom affects mouse sensitivity for sniping
382 mouse_x *= sensitivity.value * cl.viewzoom;
383 mouse_y *= sensitivity.value * cl.viewzoom;
385 // Add mouse X/Y movement to cmd
386 if ((in_strafe.state & 1) || (lookstrafe.integer && mouselook))
387 cmd->sidemove += m_side.value * mouse_x;
389 cl.viewangles[YAW] -= m_yaw.value * mouse_x;
394 if (mouselook && !(in_strafe.state & 1))
395 cl.viewangles[PITCH] += m_pitch.value * mouse_y;
398 if ((in_strafe.state & 1) && noclip_anglehack)
399 cmd->upmove -= m_forward.value * mouse_y;
401 cmd->forwardmove -= m_forward.value * mouse_y;
405 void VID_InitCvars(void)
407 Cvar_RegisterVariable(&vid_mode);
408 Cvar_RegisterVariable(&vid_mouse);
409 Cvar_RegisterVariable(&vid_fullscreen);
410 Cvar_RegisterVariable(&gl_combine);
411 Cvar_RegisterVariable(&in_pitch_min);
412 Cvar_RegisterVariable(&in_pitch_max);
413 Cvar_RegisterVariable(&m_filter);
414 Cmd_AddCommand("force_centerview", Force_CenterView_f);