1 /*
2 Copyright (C) 2001-2002 Charles Hollemeersch
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 
19 PENTA: the whole file is freakin penta...
20 
21 All code conserning the drawing of bump mapped polygons.
22 Per vertex setup, shaders and the passes.
23 This is the general/gf2 approach for the gf3 code see gumpgf.c
24 */
25 
26 #include "quakedef.h"
27 
28 //view origin in object space
29 vec3_t object_vieworg;
30 
31 /**************************************************************
32 
33 	PART1: Gl state management
34 
35 ***************************************************************/
36 
37 
GL_EnableDiffuseShader()38 void GL_EnableDiffuseShader () {
39 	//ordinary combiners = compatible with everything
40 
41 	//texture coords for unit 0: Tangent space light vector
42 	//texture coords for unit 1: Normal map texture coords
43 	GL_SelectTexture(GL_TEXTURE0_ARB);
44 	glDisable(GL_TEXTURE_2D);
45 	glEnable(GL_TEXTURE_CUBE_MAP_ARB);
46 	glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, normcube_texture_object);
47 	glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
48     glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
49     glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
50     glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE);
51 
52 	GL_EnableMultitexture();
53 	glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
54     glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
55     glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
56     glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGBA_ARB);
57 }
58 
GL_DisableDiffuseShader()59 void GL_DisableDiffuseShader () {
60 	GL_DisableMultitexture();
61 	glEnable(GL_TEXTURE_2D);
62 	glDisable(GL_TEXTURE_CUBE_MAP_ARB);
63 }
64 
GL_EnableSpecularShader()65 void GL_EnableSpecularShader () {
66 
67 	vec3_t scaler = {0.75f, 0.75f, 0.75f};
68 
69 	if ( gl_cardtype == GEFORCE || gl_cardtype == GEFORCE3 ) {
70 		GL_SelectTexture(GL_TEXTURE0_ARB);
71 		glDisable(GL_TEXTURE_2D);
72 		glEnable(GL_TEXTURE_CUBE_MAP_ARB);
73 		//GL_Bind(normcube_texture_object);
74 		glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, normcube_texture_object);
75 		GL_EnableMultitexture();
76 
77 		//setup and enable the register combiners
78 		qglCombinerParameteriNV(GL_NUM_GENERAL_COMBINERS_NV, 2);
79 		qglCombinerParameterfvNV(GL_CONSTANT_COLOR0_NV, &scaler[0]);
80 
81 		//combiner0 RGB: calculate N'dotH -> store in Spare0 RGB
82 		qglCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_A_NV, GL_TEXTURE1_ARB, GL_EXPAND_NORMAL_NV, GL_RGB);
83 		qglCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_B_NV, GL_TEXTURE0_ARB, GL_EXPAND_NORMAL_NV, GL_RGB);
84 		qglCombinerOutputNV(GL_COMBINER0_NV, GL_RGB, GL_SPARE0_NV, GL_DISCARD_NV, GL_DISCARD_NV, GL_NONE, GL_NONE, GL_TRUE, GL_FALSE, GL_FALSE);
85 
86 		//combiner0 Alpha: ignore all
87 		qglCombinerOutputNV(GL_COMBINER0_NV, GL_ALPHA, GL_DISCARD_NV, GL_DISCARD_NV, GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE);
88 
89 		//combiner1 RGB: ignore all
90 		qglCombinerOutputNV(GL_COMBINER1_NV, GL_RGB, GL_DISCARD_NV, GL_DISCARD_NV, GL_DISCARD_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE);
91 
92 		//combiner1 Alpha: calculate 4*((N'dotH)^2 - 0.75f) -> store in Spare0 Alpha
93 		qglCombinerInputNV(GL_COMBINER1_NV, GL_ALPHA, GL_VARIABLE_A_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_BLUE);
94 		qglCombinerInputNV(GL_COMBINER1_NV, GL_ALPHA, GL_VARIABLE_B_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_BLUE);
95 		qglCombinerInputNV(GL_COMBINER1_NV, GL_ALPHA, GL_VARIABLE_C_NV, GL_CONSTANT_COLOR0_NV, GL_SIGNED_NEGATE_NV, GL_BLUE);
96 		qglCombinerInputNV(GL_COMBINER1_NV, GL_ALPHA, GL_VARIABLE_D_NV, GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_ALPHA);
97 		qglCombinerOutputNV(GL_COMBINER1_NV, GL_ALPHA, GL_DISCARD_NV, GL_DISCARD_NV, GL_SPARE0_NV, GL_SCALE_BY_FOUR_NV, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE);
98 
99 		//final combiner RGB: who cares
100 		//					Alpha: specular value of 4*((N'dotH)^2 - 0.75f)
101 		qglFinalCombinerInputNV(GL_VARIABLE_G_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
102 
103 		glEnable(GL_REGISTER_COMBINERS_NV);
104 	} else {
105 		GL_EnableDiffuseShader ();
106 	}
107 }
108 
GL_DisableSpecularShader()109 void GL_DisableSpecularShader () {
110 
111 	//not supported?
112 	if ( gl_cardtype == GEFORCE || gl_cardtype == GEFORCE3 ) {
113 		GL_DisableMultitexture();
114 		glDisable(GL_REGISTER_COMBINERS_NV);
115 		glEnable(GL_TEXTURE_2D);
116 		glDisable(GL_TEXTURE_CUBE_MAP_ARB);
117 	} else {
118 		GL_DisableDiffuseShader ();
119 	}
120 }
121 
GL_EnableColorShader(qboolean specular)122 void GL_EnableColorShader (qboolean specular) {
123 	//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
124 
125 	//primary color = light color
126 	//tu0 = light filter cube map
127 	//tu1 = material color map
128 	GL_SelectTexture(GL_TEXTURE0_ARB);
129 	glDisable(GL_TEXTURE_2D);
130 	glEnable(GL_TEXTURE_CUBE_MAP_ARB);
131 
132 	GL_SelectTexture(GL_TEXTURE0_ARB);
133 	glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, currentshadowlight->filtercube);
134 	glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
135     glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
136     glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
137     glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
138 
139 	if (!specular) {
140 		if (sh_colormaps.value) {
141 			GL_EnableMultitexture();
142 			glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
143 			glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
144 			glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
145 			glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
146 		} else {
147 			GL_DisableMultitexture();
148 		}
149 	} else {
150 		GL_EnableMultitexture();
151 		glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
152 		glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
153 		glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
154 		glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_ALPHA);
155 		glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
156 	}
157 
158 
159 
160 }
161 
GL_DisableColorShader(qboolean specular)162 void GL_DisableColorShader (qboolean specular) {
163 	if (!specular) {
164 		if (sh_colormaps.value) GL_DisableMultitexture();
165 	} else {
166 		glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
167 		GL_DisableMultitexture();
168 	}
169 
170 	glEnable(GL_TEXTURE_2D);
171 	glDisable(GL_TEXTURE_CUBE_MAP_ARB);
172 }
173 
GL_EnableAttShader()174 void GL_EnableAttShader() {
175 
176 	GL_Bind(glow_texture_object);
177 
178 	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
179 }
180 
GL_DisableAttShader()181 void GL_DisableAttShader() {
182 	//empty
183 	glDisable(GL_REGISTER_COMBINERS_NV);
184 }
185 
186 /*
187 Draw incoming fragment to destination alpha.
188 
189 Note: A fragment in the next comment means a pixel that will be drawn on the screen
190 (gl has some specific definition of it)
191 */
GL_DrawAlpha()192 void GL_DrawAlpha() {
193 	glColorMask(false, false, false, true);
194 	glDisable(GL_BLEND);
195 }
196 
197 /*
198 Draw incoming fragment by modulating it with destination alpha
199 */
GL_ModulateAlphaDrawAlpha()200 void GL_ModulateAlphaDrawAlpha() {
201 	glColorMask(false, false, false, true);
202 	glBlendFunc (GL_DST_ALPHA, GL_ZERO);
203 	glEnable (GL_BLEND);
204 }
205 
206 /*
207 Draw incoming fragment by adding it to destination alpha
208 */
GL_AddAlphaDrawAlpha()209 void GL_AddAlphaDrawAlpha() {
210 	glColorMask(false, false, false, true);
211 	glBlendFunc (GL_ONE, GL_ONE);
212 	glEnable (GL_BLEND);
213 }
214 
215 /*
216 Draw incoming fragment by modulation it with destination alpha
217 */
GL_ModulateAlphaDrawColor()218 void GL_ModulateAlphaDrawColor() {
219 	glColorMask(true, true, true, true);
220 	glBlendFunc (GL_DST_ALPHA, GL_ONE);
221 	glEnable (GL_BLEND);
222 }
223 
224 /*
225 Draw incoming alpha squared to destination alpha
226 */
GL_DrawSquareAlpha()227 void GL_DrawSquareAlpha() {
228 	glColorMask(false, false, false, true);
229 	glBlendFunc (GL_SRC_ALPHA, GL_ZERO);
230 	glEnable (GL_BLEND);
231 }
232 
233 /*
234 Square the destination alpha
235 */
GL_SquareAlpha()236 void GL_SquareAlpha() {
237 	glColorMask(false, false, false, true);
238 	glBlendFunc (GL_ZERO, GL_DST_ALPHA);
239 	glEnable (GL_BLEND);
240 }
241 
242 /*
243 Add incoming fragment to destination color
244 */
GL_AddColor()245 void GL_AddColor() {
246 	glColorMask(true, true, true, true);
247 	glBlendFunc (GL_ONE, GL_ONE);
248 	glEnable (GL_BLEND);
249 }
250 
251 /*
252 Ovewrite destination color with incoming fragment
253 */
GL_DrawColor()254 void GL_DrawColor() {
255 	glColorMask(true, true, true, true);
256 	glDisable (GL_BLEND);
257 }
258 
259 /*
260 =================
261 R_WorldToObjectMatrix
262 
263 Returns a world to object coordinate transformation matrix.
264 This is crap and I know it ;)
265 The problem is that quake does strange stuff with its angles
266 (look at R_RotateForEntity) so inverting the matrix will
267 certainly give the desired result.
268 Why I use the gl matrix? Well quake doesn't have build in matix
269 routines an I don't have any lying around in c (Lot's in Pascal
270 of course i'm a Delphi man)
271 
272 =================
273 */
274 
R_WorldToObjectMatrix(entity_t * e,matrix_4x4 result)275 void R_WorldToObjectMatrix(entity_t *e, matrix_4x4 result)
276 {
277 	matrix_4x4 world;
278 
279 	glPushMatrix();
280 	glLoadIdentity();
281 	R_RotateForEntity (e);
282 	glGetFloatv (GL_MODELVIEW_MATRIX, &world[0][0]);
283 	glPopMatrix();
284 	MatrixAffineInverse(world,result);
285 }
286 
287 /*
288 =============
289 GL_SetupCubeMapMatrix
290 
291 Loads the current matrix with a tranformation used for light filters
292 =============
293 */
294 
GL_SetupCubeMapMatrix(qboolean world)295 void GL_SetupCubeMapMatrix(qboolean world) {
296 
297 	glLoadIdentity();
298 
299 	glRotatef (-currentshadowlight->angles[0],  1, 0, 0);
300     glRotatef (-currentshadowlight->angles[1],  0, 1, 0);
301     glRotatef (-currentshadowlight->angles[2],  0, 0, 1);
302 
303 	glRotatef (currentshadowlight->rspeed*cl.time,0,0,1);
304 
305 	glTranslatef(-currentshadowlight->origin[0],
306 				-currentshadowlight->origin[1],
307 				-currentshadowlight->origin[2]);
308 
309 	if (!world)
310 		R_RotateForEntity(currententity);
311 
312 }
313 /**************************************************************
314 
315 	PART2: Geommety sending code
316 
317 	This parts containts code for sending different geommety
318 	types (brushes, alias, ...) with different per vertex
319 	options (light, H, att)
320 	Every method is the core of 1 pass during bump map rendering.
321 	This is all direct mode stuff, it should be put in vertex
322 	arrays.
323 
324 ***************************************************************/
325 
326 /*
327 =============
328 R_DrawWorldLLV
329 
330 -Draws the world sending the tangent space light vector as unit 0's texture coordinates.
331 -Sends as uni1t's texture coordinates the original texture coordinates.
332 -Rebinds unit1's texture if the surface material changes (binds the current surface's bump map)
333 =============
334 */
R_DrawWorldLLV(lightcmd_t * lightCmds)335 void R_DrawWorldLLV(lightcmd_t *lightCmds) {
336 
337 	int command, num, i;
338 	int lightPos = 0;
339 	vec3_t lightOr;
340 	msurface_t *surf;
341 	float		*v;
342 	texture_t	*t;//XYZ
343 
344 	//support flickering lights
345 	VectorCopy(currentshadowlight->origin,lightOr);
346 
347 	while (1) {
348 
349 		command = lightCmds[lightPos++].asInt;
350 		if (command == 0) break; //end of list
351 
352 		surf = lightCmds[lightPos++].asVoid;
353 
354 		if (surf->visframe != r_framecount) {
355 			lightPos+=(4+surf->polys->numverts*(2+3));
356 			continue;
357 		}
358 
359 		num = surf->polys->numverts;
360 		lightPos+=4;//skip color
361 
362 
363 		//XYZ
364 		t = R_TextureAnimation (surf->texinfo->texture);
365 		GL_Bind (t->gl_texturenum+1);
366 
367 		glBegin(command);
368 		//v = surf->polys->verts[0];
369 		v = (float *)(&globalVertexTable[surf->polys->firstvertex]);
370 		for (i=0; i<num; i++, v+= VERTEXSIZE) {
371 			//skip attent texture coord.
372 			lightPos+=2;
373 
374 			//calculate local light vector and put it into tangent space
375 			/*
376 			VectorSubtract(lightOr,cl.worldmodel->vertexes[ind].position,lightDir);
377 
378 			if (surf->flags & SURF_PLANEBACK)	{
379 				tsLightDir[2] = -DotProduct(lightDir,surf->plane->normal);
380 			} else {
381 				tsLightDir[2] = DotProduct(lightDir,surf->plane->normal);
382 			}
383 
384 			tsLightDir[1] = -DotProduct(lightDir,surf->texinfo->vecs[1]);
385 			tsLightDir[0] = DotProduct(lightDir,surf->texinfo->vecs[0]);
386 
387 			glTexCoord3fv(&tsLightDir[0]);
388 			*/
389 			glTexCoord3fv(&lightCmds[lightPos].asFloat);
390 			lightPos+=3;
391 
392 			qglMultiTexCoord2fARB(GL_TEXTURE1_ARB, v[3], v[4]);
393 			glVertex3fv(&v[0]);
394 		}
395 		glEnd();
396 	}
397 
398 }
399 
400 /*
401 =============
402 R_DrawWorldHAV
403 
404 -Draws the world sending the tangent space half angle vector as unit 0's texture coordinates.
405 -Sends as uni1t's texture coordinates the original texture coordinates.
406 -Rebinds unit1's texture if the surface material changes (binds the current surface's bump map)
407 =============
408 */
R_DrawWorldHAV(lightcmd_t * lightCmds)409 void R_DrawWorldHAV(lightcmd_t *lightCmds) {
410 
411 	int command, num, i;
412 	int lightPos = 0;
413 	vec3_t lightOr,tsH,H;
414 	msurface_t *surf;
415 	float		*v,*lightP;
416 	vec3_t		lightDir;
417 	texture_t	*t;//XYZ
418 
419 	//support flickering lights
420 	VectorCopy(currentshadowlight->origin,lightOr);
421 
422 	while (1) {
423 
424 		command = lightCmds[lightPos++].asInt;
425 		if (command == 0) break; //end of list
426 
427 		surf = lightCmds[lightPos++].asVoid;
428 
429 		if (surf->visframe != r_framecount) {
430 			lightPos+=(4+surf->polys->numverts*(2+3));
431 			continue;
432 		}
433 
434 		num = surf->polys->numverts;
435 		lightPos+=4;//skip color
436 
437 		//XYZ
438 		t = R_TextureAnimation (surf->texinfo->texture);
439 		GL_Bind (t->gl_texturenum+1);
440 
441 		glBegin(command);
442 		//v = surf->polys->verts[0];
443 		v = (float *)(&globalVertexTable[surf->polys->firstvertex]);
444 		for (i=0; i<num; i++, v+= VERTEXSIZE) {
445 			lightPos+=2;//skip texcoords
446 			lightP = &lightCmds[lightPos].asFloat;
447 			VectorCopy(lightP,lightDir);
448 			VectorNormalize(lightDir);
449 			lightPos+=3;//skip local light vector
450 
451 			//r_origin = camera position
452 			VectorSubtract(r_refdef.vieworg,v,H);
453 			VectorNormalize(H);
454 
455 			//put H in tangent space firste since lightDir (precalc) is already in tang space
456 			if (surf->flags & SURF_PLANEBACK)	{
457 				tsH[2] = -DotProduct(H,surf->plane->normal);
458 			} else {
459 				tsH[2] = DotProduct(H,surf->plane->normal);
460 			}
461 
462 			tsH[1] = -DotProduct(H,surf->texinfo->vecs[1]);
463 			tsH[0] = DotProduct(H,surf->texinfo->vecs[0]);
464 
465 			VectorAdd(lightDir,tsH,tsH);
466 
467 			glTexCoord3fv(&tsH[0]);
468 			qglMultiTexCoord2fARB(GL_TEXTURE1_ARB, v[3], v[4]);
469 			glVertex3fv(&v[0]);
470 		}
471 		glEnd();
472 	}
473 }
474 
475 /*
476 =============
477 R_DrawWorldATT
478 
479 Draw the world sending as texture unit 0's texture coordinates the precalcuated attenuation
480 coordinates.
481 As primary color the light color modulated by the current brightness (for flickering lights
482 this depends on t)
483 =============
484 */
R_DrawWorldATT(lightcmd_t * lightCmds)485 void R_DrawWorldATT(lightcmd_t *lightCmds) {
486 	int command, num, i;
487 	int lightPos = 0;
488 
489 	//edit: modulation of light maps
490 	msurface_t *surf;
491 	float		*v;
492 
493 	//support flickering lights
494 	float b = d_lightstylevalue[currentshadowlight->style]/255.0;
495 
496 	while (1) {
497 
498 		command = lightCmds[lightPos++].asInt;
499 		if (command == 0) break; //end of list
500 
501 		//edit: modulation of light maps
502 		surf = lightCmds[lightPos++].asVoid;
503 
504 		if (surf->visframe != r_framecount) {
505 			lightPos+=(4+surf->polys->numverts*(2+3));
506 			continue;
507 		}
508 
509 		num = surf->polys->numverts;
510 		//v = surf->polys->verts[0];
511 		v = (float *)(&globalVertexTable[surf->polys->firstvertex]);
512 
513 		glColor4f( (&lightCmds[lightPos].asFloat)[0] *b,
514 				   (&lightCmds[lightPos].asFloat)[1] *b,
515 				   (&lightCmds[lightPos].asFloat)[2] *b,
516 				   (&lightCmds[lightPos].asFloat)[3] *b );
517 
518 		lightPos+=4;
519 
520 		glBegin(command);
521 		for (i=0; i<num; i++, v+= VERTEXSIZE) {
522 
523 			glTexCoord2fv(&lightCmds[lightPos].asFloat);
524 			lightPos+=2;
525 			lightPos+=3;
526 			glVertex3fv(&v[0]);
527 		}
528 		glEnd();
529 	}
530 }
531 
532 /*
533 =============
534 R_DrawWorldWV
535 
536 -Draw the world sending as texture unit 0's coordinates the world space coordinates of the current vertex
537 -Sends as uni1t's texture coordinates the original texture coordinates.
538 -Rebinds unit1's texture if the surface material changes (binds the current surface's color map)
539 =============
540 */
R_DrawWorldWV(lightcmd_t * lightCmds,qboolean specular)541 void R_DrawWorldWV(lightcmd_t *lightCmds, qboolean specular) {
542 
543 	int command, num, i;
544 	int lightPos = 0;
545 
546 	//edit: modulation of light maps
547 	msurface_t *surf;
548 	float		*v;
549 	texture_t	*t;//XYZ
550 
551 	while (1) {
552 
553 		command = lightCmds[lightPos++].asInt;
554 		if (command == 0) break; //end of list
555 
556 		surf = lightCmds[lightPos++].asVoid;
557 
558 		if (surf->visframe != r_framecount) {
559 			lightPos+=(4+surf->polys->numverts*(2+3));
560 			continue;
561 		}
562 
563 		num = surf->polys->numverts;
564 		//v = surf->polys->verts[0];
565 		v = (float *)(&globalVertexTable[surf->polys->firstvertex]);
566 
567 		//XYZ
568 		t = R_TextureAnimation (surf->texinfo->texture);
569 		if ( specular )
570 		    GL_Bind (t->gl_texturenum+1);
571 		else
572 		    GL_Bind (t->gl_texturenum);
573 
574 		lightPos+=4;//no attent color
575 
576 		glBegin(command);
577 		for (i=0; i<num; i++, v+= VERTEXSIZE) {
578 			lightPos+=2;//no attent coords
579 			lightPos+=3;
580 			glTexCoord3fv(&v[0]);
581 			qglMultiTexCoord2fARB(GL_TEXTURE1_ARB, v[3], v[4]);
582 			glVertex3fv(&v[0]);
583 		}
584 		glEnd();
585 	}
586 
587 }
588 
589 
590 /*
591 =============
592 R_DrawBrushLLV
593 
594 -Draws the brush sending the tangent space light vector as unit 0's texture coordinates.
595 -Sends as uni1t's texture coordinates the original texture coordinates.
596 -Rebinds unit1's texture if the surface material changes (binds the current surface's bump map)
597 =============
598 */
R_DrawBrushLLV(entity_t * e)599 void R_DrawBrushLLV(entity_t *e) {
600 
601 	model_t	*model = e->model;
602 	msurface_t *surf;
603 	glpoly_t	*poly;
604 	int		i, j, count;
605 	brushlightinstant_t *ins = e->brushlightinstant;
606 	float	*v;
607 	texture_t	*t;
608 
609 	count = 0;
610 
611 	surf = &model->surfaces[model->firstmodelsurface];
612 	for (i=0; i<model->nummodelsurfaces; i++, surf++)
613 	{
614 		if (!ins->polygonVis[i]) continue;
615 
616 		poly = surf->polys;
617 
618 		//XYZ
619 		t = R_TextureAnimation (surf->texinfo->texture);
620 		GL_Bind (t->gl_texturenum+1);
621 
622 		glBegin(GL_TRIANGLE_FAN);
623 		//v = poly->verts[0];
624 		v = (float *)(&globalVertexTable[poly->firstvertex]);
625 		for (j=0 ; j<poly->numverts ; j++, v+= VERTEXSIZE)
626 		{
627 			glTexCoord3fv(&ins->tslights[count+j][0]);
628 			qglMultiTexCoord2fARB(GL_TEXTURE1_ARB, v[3], v[4]);
629 			glVertex3fv(v);
630 		}
631 		glEnd();
632 		count+=surf->numedges;
633 	}
634 }
635 
636 /*
637 =============
638 R_DrawBrushHAV
639 
640 -Draws the brush sending the tangent space half angle vector as unit 0's texture coordinates.
641 -Sends as uni1t's texture coordinates the original texture coordinates.
642 -Rebinds unit1's texture if the surface material changes (binds the current surface's bump map)
643 =============
644 */
R_DrawBrushHAV(entity_t * e)645 void R_DrawBrushHAV(entity_t *e) {
646 
647 	model_t	*model = e->model;
648 	msurface_t *surf;
649 	glpoly_t	*poly;
650 	int		i, j, count;
651 	brushlightinstant_t *ins = e->brushlightinstant;
652 	float	*v;
653 	texture_t	*t;//XYZ
654 
655 	count = 0;
656 
657 	surf = &model->surfaces[model->firstmodelsurface];
658 	for (i=0; i<model->nummodelsurfaces; i++, surf++)
659 	{
660 		if (!ins->polygonVis[i]) continue;
661 
662 		poly = surf->polys;
663 
664 		//XYZ
665 		t = R_TextureAnimation (surf->texinfo->texture);
666 		GL_Bind (t->gl_texturenum+1);
667 
668 		glBegin(GL_TRIANGLE_FAN);
669 		//v = poly->verts[0];
670 		v = (float *)(&globalVertexTable[poly->firstvertex]);
671 		for (j=0 ; j<poly->numverts ; j++, v+= VERTEXSIZE)
672 		{
673 			glTexCoord3fv(&ins->tshalfangles[count+j][0]);
674 			qglMultiTexCoord2fARB(GL_TEXTURE1_ARB, v[3], v[4]);
675 			glVertex3fv(v);
676 		}
677 		glEnd();
678 		count+=surf->numedges;
679 	}
680 }
681 /*
682 =============
683 R_DrawBrushATT
684 
685 Draw the brush sending as texture unit 0's texture coordinates the calcuated attentuation
686 coordinates.
687 As primary color the light color modulated by the current brightness (for flickering lights
688 this depends on t)
689 =============
690 */
R_DrawBrushATT(entity_t * e)691 void R_DrawBrushATT(entity_t *e) {
692 
693 	model_t	*model = e->model;
694 	msurface_t *surf;
695 	glpoly_t	*poly;
696 	int		i, j, count, countc;
697 	brushlightinstant_t *ins = e->brushlightinstant;
698 	float	*v, bright;
699 
700 	count = 0;
701 	countc = 0;
702 	surf = &model->surfaces[model->firstmodelsurface];
703 	for (i=0; i<model->nummodelsurfaces; i++, surf++)
704 	{
705 		if (!ins->polygonVis[i]) continue;
706 
707 		poly = surf->polys;
708 
709 		//GL_Bind(surf->texinfo->texture->gl_texturenum);
710 
711 		bright = ins->colorscales[countc];
712 		countc++;
713 
714 		glColor4f(bright,bright,bright,bright);
715 
716 		glBegin(GL_TRIANGLE_FAN);
717 		//v = poly->verts[0];
718 		v = (float *)(&globalVertexTable[poly->firstvertex]);
719 		for (j=0 ; j<poly->numverts ; j++, v+= VERTEXSIZE)
720 		{
721 			glTexCoord2fv(&ins->atencoords[count+j][0]);
722 			//qglMultiTexCoord2fARB(GL_TEXTURE1_ARB, v[3], v[4]);
723 			glVertex3fv(v);
724 		}
725 		glEnd();
726 		count+=surf->numedges;
727 	}
728 }
729 
730 /*
731 =============
732 R_DrawBrushWV
733 
734 =============
735 */
736 
R_DrawBrushWV(entity_t * e,qboolean specular)737 void R_DrawBrushWV(entity_t *e, qboolean specular) {
738 
739 	model_t	*model = e->model;
740 	msurface_t *surf;
741 	glpoly_t	*poly;
742 	int		i, j, count;
743 	brushlightinstant_t *ins = e->brushlightinstant;
744 	float	*v;
745 	texture_t	*t;
746 
747 	count = 0;
748 
749 	surf = &model->surfaces[model->firstmodelsurface];
750 	for (i=0; i<model->nummodelsurfaces; i++, surf++)
751 	{
752 		if (!ins->polygonVis[i]) continue;
753 
754 		poly = surf->polys;
755 
756 		//XYZ
757 		t = R_TextureAnimation (surf->texinfo->texture);
758 		if ( specular )
759 		    GL_Bind (t->gl_texturenum+1);
760 		else
761 		    GL_Bind (t->gl_texturenum);
762 
763 		glBegin(GL_TRIANGLE_FAN);
764 		//v = poly->verts[0];
765 		v = (float *)(&globalVertexTable[poly->firstvertex]);
766 		for (j=0 ; j<poly->numverts ; j++, v+= VERTEXSIZE)
767 		{
768 			glTexCoord3fv(v);
769 			qglMultiTexCoord2fARB(GL_TEXTURE1_ARB, v[3], v[4]);
770 			glVertex3fv(v);
771 		}
772 		glEnd();
773 		count+=surf->numedges;
774 	}
775 }
776 /*
777 =============
778 R_DrawBrushObjectLight
779 
780 Idea: Creepy object oriented programming by using function pointers.
781 Function: Puts the light into object space, adapts the world->eye matrix
782 and calls BrushGeoSender if all that has been done.
783 Cleans up afterwards so nothing has changed.
784 =============
785 */
R_DrawBrushObjectLight(entity_t * e,void (* BrushGeoSender)(entity_t * e))786 void R_DrawBrushObjectLight(entity_t *e,void (*BrushGeoSender) (entity_t *e)) {
787 
788 	model_t		*clmodel;
789 
790 	vec3_t oldlightorigin;
791 	//backup light origin since we will have to translate
792 	//light into model space
793 	VectorCopy (currentshadowlight->origin, oldlightorigin);
794 
795 	currententity = e;
796 	currenttexture = -1;
797 
798 	clmodel = e->model;
799 
800     glPushMatrix ();
801 	e->angles[0] = -e->angles[0];	// stupid quake bug
802 	R_RotateForEntity (e);
803 	e->angles[0] = -e->angles[0];	// stupid quake bug
804 
805 	BrushGeoSender(e);
806 
807 	VectorCopy(oldlightorigin,currentshadowlight->origin);
808 	glPopMatrix ();
809 }
810 
R_DrawAliasFrameLLV(aliashdr_t * paliashdr,aliasframeinstant_t * instant)811 void R_DrawAliasFrameLLV (aliashdr_t *paliashdr, aliasframeinstant_t *instant)
812 {
813 	fstvert_t	*texcoords;
814 	int *indecies, anim;
815 	aliaslightinstant_t *linstant = instant->lightinstant;
816 
817 	texcoords = (fstvert_t *)((byte *)paliashdr + paliashdr->texcoords);
818 	indecies = (int *)((byte *)paliashdr + paliashdr->indecies);
819 
820 	//bind normal map
821 	anim = (int)(cl.time*10) & 3;
822     GL_Bind(paliashdr->gl_texturenum[currententity->skinnum][anim]+1);
823 
824 	glVertexPointer(3, GL_FLOAT, 0, instant->vertices);
825 	glEnableClientState(GL_VERTEX_ARRAY);
826 
827 	qglClientActiveTextureARB(GL_TEXTURE0_ARB);
828 	glTexCoordPointer(3, GL_FLOAT, 0, linstant->tslights);
829 	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
830 
831 	qglClientActiveTextureARB(GL_TEXTURE1_ARB);
832 	glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
833 	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
834 
835 	glDrawElements(GL_TRIANGLES,linstant->numtris*3,GL_UNSIGNED_INT,&linstant->indecies[0]);
836 
837 	if (sh_noshadowpopping.value) {
838 		glStencilFunc(GL_LEQUAL, 1, 0xffffffff);
839 		glDrawElements(GL_TRIANGLES,(paliashdr->numtris*3)-(linstant->numtris*3),GL_UNSIGNED_INT,&linstant->indecies[linstant->numtris*3]);
840 		glStencilFunc(GL_EQUAL, 0, 0xffffffff);
841 	}
842 
843 	glDisableClientState(GL_VERTEX_ARRAY);
844 	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
845 	qglClientActiveTextureARB(GL_TEXTURE0_ARB);
846 	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
847 }
848 
R_DrawAliasFrameHAV(aliashdr_t * paliashdr,aliasframeinstant_t * instant)849 void R_DrawAliasFrameHAV (aliashdr_t *paliashdr, aliasframeinstant_t *instant)
850 {
851 	fstvert_t	*texcoords;
852 	int			*indecies, anim;
853 	aliaslightinstant_t *linstant = instant->lightinstant;
854 
855 	texcoords = (fstvert_t *)((byte *)paliashdr + paliashdr->texcoords);
856 	indecies = (int *)((byte *)paliashdr + paliashdr->indecies);
857 
858 	//bind normal map
859 	anim = (int)(cl.time*10) & 3;
860     GL_Bind(paliashdr->gl_texturenum[currententity->skinnum][anim]+1);
861 
862 	glVertexPointer(3, GL_FLOAT, 0, instant->vertices);
863 	glEnableClientState(GL_VERTEX_ARRAY);
864 
865 	qglClientActiveTextureARB(GL_TEXTURE0_ARB);
866 	glTexCoordPointer(3, GL_FLOAT, 0, linstant->tshalfangles);
867 	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
868 
869 	qglClientActiveTextureARB(GL_TEXTURE1_ARB);
870 	glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
871 	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
872 
873 	glDrawElements(GL_TRIANGLES,linstant->numtris*3,GL_UNSIGNED_INT,&linstant->indecies[0]);
874 
875 	if (sh_noshadowpopping.value) {
876 		glStencilFunc(GL_LEQUAL, 1, 0xffffffff);
877 		glDrawElements(GL_TRIANGLES,(paliashdr->numtris*3)-(linstant->numtris*3),GL_UNSIGNED_INT,&linstant->indecies[linstant->numtris*3]);
878 		glStencilFunc(GL_EQUAL, 0, 0xffffffff);
879 	}
880 
881 	glDisableClientState(GL_VERTEX_ARRAY);
882 	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
883 	qglClientActiveTextureARB(GL_TEXTURE0_ARB);
884 	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
885 
886 }
887 
888 
889 /*
890 =============
891 R_DrawAliasFrameWV
892 
893 Draw an alias model with the ojbect space vertex coordinates as texture coords
894 =============
895 */
R_DrawAliasFrameWV(aliashdr_t * paliashdr,aliasframeinstant_t * instant,qboolean specular)896 void R_DrawAliasFrameWV (aliashdr_t *paliashdr, aliasframeinstant_t *instant, qboolean specular) {
897 
898 	int *indecies, anim;
899 	fstvert_t *texcoords;
900 	aliaslightinstant_t *linstant = instant->lightinstant;
901 
902 	texcoords = (fstvert_t *)((byte *)paliashdr + paliashdr->texcoords);
903 	indecies = (int *)((byte *)paliashdr + paliashdr->indecies);
904 
905 	anim = (int)(cl.time*10) & 3;
906 	if ( specular )
907 	    GL_Bind(paliashdr->gl_texturenum[currententity->skinnum][anim]+1);
908 	else
909 	    GL_Bind(paliashdr->gl_texturenum[currententity->skinnum][anim]);
910 
911 	glVertexPointer(3, GL_FLOAT, 0, instant->vertices);
912 	glEnableClientState(GL_VERTEX_ARRAY);
913 
914 	qglClientActiveTextureARB(GL_TEXTURE0_ARB);
915 	glTexCoordPointer(3, GL_FLOAT, 0, instant->vertices);
916 	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
917 
918 	if ( gl_cardtype == GENERIC || gl_cardtype == GEFORCE ) {//PA:
919 
920 		qglClientActiveTextureARB(GL_TEXTURE1_ARB);
921 		glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
922 		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
923 
924 		glNormalPointer(GL_FLOAT, 0, instant->normals);
925 		glEnableClientState(GL_NORMAL_ARRAY);
926 
927 		glEnableClientState(GL_COLOR_ARRAY);
928 		glColorPointer(3, GL_FLOAT, 0, linstant->colors);
929 	}
930 
931 	glDrawElements(GL_TRIANGLES,linstant->numtris*3,GL_UNSIGNED_INT,&linstant->indecies[0]);
932 
933 	if (sh_noshadowpopping.value) {
934 		glStencilFunc(GL_LEQUAL, 1, 0xffffffff);
935 		glDrawElements(GL_TRIANGLES,(paliashdr->numtris*3)-(linstant->numtris*3),GL_UNSIGNED_INT,&linstant->indecies[linstant->numtris*3]);
936 		glStencilFunc(GL_EQUAL, 0, 0xffffffff);
937 	}
938 
939 	if ( gl_cardtype == GENERIC || gl_cardtype == GEFORCE ) {//PA:
940 		glDisableClientState(GL_NORMAL_ARRAY);
941 		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
942 		glDisableClientState(GL_COLOR_ARRAY);
943 	}
944 
945 	qglClientActiveTextureARB(GL_TEXTURE0_ARB);
946 	glDisableClientState(GL_VERTEX_ARRAY);
947 	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
948 }
949 
PrintScreenPos(vec3_t v)950 void PrintScreenPos(vec3_t v) {
951 
952 	double	Dproject_matrix[16];
953 	double	Dworld_matrix[16];
954 	GLint Iviewport[4];		// <AWE> changed from int to GLint.
955 	double px, py, pz;
956 
957 	glGetDoublev (GL_MODELVIEW_MATRIX, Dworld_matrix);
958 	glGetDoublev (GL_PROJECTION_MATRIX, Dproject_matrix);
959 	glGetIntegerv (GL_VIEWPORT, Iviewport);
960 	gluProject(v[0], v[1], v[2],
961 				   Dworld_matrix, Dproject_matrix, Iviewport, &px, &py, &pz);
962 	Con_Printf("Pos: %f %f %f\n", px, py, pz);
963 }
964 
965 /*
966 =================
967 R_DrawAliasObjectLight
968 
969 Same as R_DrawBrushObjectLight but with alias models
970 
971 =================
972 */
R_DrawAliasObjectLight(entity_t * e,void (* AliasGeoSender)(aliashdr_t * paliashdr,aliasframeinstant_t * instant))973 void R_DrawAliasObjectLight(entity_t *e,void (*AliasGeoSender) (aliashdr_t *paliashdr, aliasframeinstant_t* instant))
974 {
975 	int				pose, numposes;
976 	//matrix_4x4		transf;
977 	//float			org[4],res[4];
978 	aliashdr_t	*paliashdr;
979         alias3data_t    *data;
980 	vec3_t		oldlightpos;
981         aliasframeinstant_t *aliasframeinstant;
982         int i,maxnumsurf;
983 
984 	currententity = e;
985 
986 //	VectorCopy (currententity->origin, r_entorigin);
987 //	VectorSubtract (r_origin, r_entorigin, modelorg);
988 
989 	glPushMatrix ();
990 	R_RotateForEntity (e);
991 
992 	//
993 	// locate the proper data
994 	//
995 	data = (alias3data_t *)Mod_Extradata (e->model);
996 	maxnumsurf = data->numSurfaces;
997 	aliasframeinstant = e->aliasframeinstant;
998 
999 	for (i=0;i<maxnumsurf;++i){
1000 
1001 		paliashdr = (aliashdr_t *)((char*)data + data->ofsSurfaces[i]);
1002 
1003 		if (!aliasframeinstant) {
1004 			glPopMatrix();
1005 			Con_Printf("R_DrawAliasObjectLight: missing instant for ent %s\n", e->model->name);
1006 			return;
1007 		}
1008 
1009 		if (aliasframeinstant->shadowonly) continue;
1010 
1011 		if ((e->frame >= paliashdr->numframes) || (e->frame < 0))
1012 		{
1013 			glPopMatrix();
1014 			return;
1015 		}
1016 
1017 		VectorCopy(currentshadowlight->origin,oldlightpos);
1018 		VectorCopy(currentshadowlight->origin,currentshadowlight->oldlightorigin);
1019 
1020 		pose = paliashdr->frames[e->frame].firstpose;
1021 		numposes = paliashdr->frames[e->frame].numposes;
1022 
1023 		//Draw it!
1024 		AliasGeoSender(paliashdr,aliasframeinstant);
1025 
1026 		aliasframeinstant = aliasframeinstant->_next;
1027 
1028 	} /* for paliashdr */
1029 
1030 	glPopMatrix();
1031 }
1032 
1033 
1034 /*
1035 =================
1036 R_DrawSpriteModelWV
1037 
1038 Draw a sprite texture with as tex0 coordinates the world space position of it's vertexes.
1039 tex1 is the sprites texture coordinates.
1040 
1041 =================
1042 */
R_DrawSpriteModelWV(entity_t * e)1043 void R_DrawSpriteModelWV (entity_t *e)
1044 {
1045 	vec3_t	point;
1046 	mspriteframe_t	*frame;
1047 	float		*up, *right;
1048 	vec3_t		v_forward, v_right, v_up;
1049 	msprite_t		*psprite;
1050 
1051 	frame = R_GetSpriteFrame (e);
1052 	psprite = currententity->model->cache.data;
1053 
1054 	if (psprite->type == SPR_ORIENTED)
1055 	{	// bullet marks on walls PENTA: bulltet marks in quake 1? never seen one ;)
1056 		AngleVectors (currententity->angles, v_forward, v_right, v_up);
1057 		up = v_up;
1058 		right = v_right;
1059 	}
1060 	else
1061 	{	// normal sprite
1062 		up = vup;
1063 		right = vright;
1064 	}
1065 
1066     GL_Bind(frame->gl_texturenum);
1067 
1068 	glBegin (GL_QUADS);
1069 
1070 	qglMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0, 1);
1071 	VectorMA (e->origin, frame->down, up, point);
1072 	VectorMA (point, frame->left, right, point);
1073 	glTexCoord3fv(point);
1074 	glVertex3fv (point);
1075 
1076 	qglMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0, 0);
1077 	VectorMA (e->origin, frame->up, up, point);
1078 	VectorMA (point, frame->left, right, point);
1079 	glTexCoord3fv(point);
1080 	glVertex3fv (point);
1081 
1082 	qglMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1, 0);
1083 	VectorMA (e->origin, frame->up, up, point);
1084 	VectorMA (point, frame->right, right, point);
1085 	glTexCoord3fv(point);
1086 	glVertex3fv (point);
1087 
1088 	qglMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1, 1);
1089 	VectorMA (e->origin, frame->down, up, point);
1090 	VectorMA (point, frame->right, right, point);
1091 	glTexCoord3fv(point);
1092 	glVertex3fv (point);
1093 
1094 	glEnd ();
1095 
1096 }
1097 
1098 /**************************************************************
1099 
1100 	PART3: Abstraction
1101 
1102 ***************************************************************/
1103 
1104 /*
1105 =============
1106 GL_DrawWorldBumped
1107 
1108 Draws the world bumped how this is done you don't have to know!
1109 =============
1110 */
R_DrawWorldBumpedGF()1111 void R_DrawWorldBumpedGF() {
1112 
1113 	if (!currentshadowlight->visible)
1114 		return;
1115 
1116 	glDepthMask (0);
1117 	glShadeModel (GL_SMOOTH);
1118 
1119 /*
1120 	if (gl_geforce3) {
1121 
1122 		if (currentshadowlight->filtercube) {
1123 			//draw attent into dest alpha
1124 			GL_DrawAlpha();
1125 			GL_EnableAttentShaderGF3(NULL);
1126 			R_DrawWorldWV(currentshadowlight->lightCmds);
1127 			GL_DisableAttentShaderGF3();
1128 			GL_ModulateAlphaDrawColor();
1129 		} else {
1130 			GL_AddColor();
1131 		}
1132 		glColor3fv(&currentshadowlight->color[0]);
1133 
1134 		GL_EnableDiffuseShaderGF3(true,currentshadowlight->origin);
1135 		R_DrawWorldGF3Diffuse(currentshadowlight->lightCmds);
1136 		GL_DisableDiffuseShaderGF3();
1137 
1138 		GL_EnableSpecularShaderGF3(true,currentshadowlight->origin);
1139 		R_DrawWorldGF3Specular(currentshadowlight->lightCmds);
1140 		GL_DisableDiffuseShaderGF3();
1141 
1142 		glColor3f (1,1,1);
1143 		glDisable (GL_BLEND);
1144 		glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1145 		glDepthMask (1);
1146 		return;
1147 	}
1148 */
1149 	//	Diffuse bump mapping
1150 
1151 	GL_DrawAlpha();
1152 	GL_EnableDiffuseShader ();
1153 	if (!currentshadowlight->isStatic) {
1154 		R_DrawWorldLLV(&lightCmdsBuff[0]);
1155 	} else {
1156 		R_DrawWorldLLV(currentshadowlight->lightCmds);
1157 	}
1158 	GL_DisableDiffuseShader ();
1159 
1160 	//	Attenuation
1161 
1162 	GL_ModulateAlphaDrawAlpha();
1163 	GL_EnableAttShader();
1164 	R_DrawWorldATT(currentshadowlight->lightCmds);
1165 	GL_DisableAttShader();
1166 
1167 	//	Color map/light filter
1168 
1169 	glMatrixMode(GL_TEXTURE);
1170 	glPushMatrix();
1171 
1172 	GL_SetupCubeMapMatrix(true);
1173 
1174 	GL_ModulateAlphaDrawColor();
1175 	glColor3fv(&currentshadowlight->baseColor[0]);
1176 	GL_EnableColorShader (false);
1177 	R_DrawWorldWV(currentshadowlight->lightCmds, false);
1178 	GL_DisableColorShader (false);
1179 
1180 	glPopMatrix();
1181 
1182 	// Specular
1183 
1184 	if ( gl_cardtype == GEFORCE || gl_cardtype == GEFORCE3 )
1185 		GL_DrawAlpha();
1186 	else
1187 		GL_DrawSquareAlpha();
1188 
1189 	GL_EnableSpecularShader ();
1190 
1191 	R_DrawWorldHAV(currentshadowlight->lightCmds);
1192 
1193 	GL_DisableSpecularShader ();
1194 
1195 	if ( gl_cardtype == GENERIC ) {
1196 		int i;
1197 		//raise specular to a high exponent my multiplying it a few times
1198 		//this is evidently slow and we should use a better system for it
1199 		GL_SquareAlpha();
1200 		for (i=0; i<3; i++) {
1201 				//why draw world att?: 1) I dont want to write new code for this
1202 				//					   2) It uses the least bandwith/ setup
1203 			R_DrawWorldATT (currentshadowlight->lightCmds);
1204 		}
1205 	}
1206 
1207 
1208 
1209 	//	Attenttuation
1210 
1211 	GL_ModulateAlphaDrawAlpha();
1212 	GL_EnableAttShader();
1213 	R_DrawWorldATT(currentshadowlight->lightCmds);
1214 	GL_DisableAttShader();
1215 
1216 	//	Color map/light filter
1217 	glPushMatrix();
1218 
1219 	GL_SetupCubeMapMatrix(true);
1220 
1221 	GL_ModulateAlphaDrawColor();
1222 	glColor3fv(&currentshadowlight->baseColor[0]);
1223 	GL_EnableColorShader (true);
1224 	R_DrawWorldWV(currentshadowlight->lightCmds, true);
1225 
1226 	GL_DisableColorShader (true);
1227 
1228 
1229 //	End separate specular
1230 
1231 	glPopMatrix();
1232 	glMatrixMode(GL_MODELVIEW);
1233 
1234 	glColor3f (1,1,1);
1235 	glDisable (GL_BLEND);
1236 	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1237 	glDepthMask (1);
1238 }
1239 
R_DrawWorldBumpedGEN()1240 void R_DrawWorldBumpedGEN() {
1241 	R_DrawWorldBumpedGF();
1242 }
1243 /*
1244 =============
1245 GL_DrawBrushBumped
1246 
1247 Draw a brush entity with bump maps
1248 =============
1249 */
R_DrawBrushBumped(entity_t * e)1250 void R_DrawBrushBumped(entity_t *e) {
1251 
1252 	//	Diffuse bump mapping
1253 
1254         GL_DrawAlpha();
1255 	GL_EnableDiffuseShader ();
1256 	R_DrawBrushLLV(e);
1257 	GL_DisableDiffuseShader ();
1258 
1259 	//	Attenttuation
1260 
1261 	GL_ModulateAlphaDrawAlpha();
1262 	GL_EnableAttShader();
1263 	R_DrawBrushATT(e);
1264 	GL_DisableAttShader();
1265 
1266 	//	Color map/light filter
1267 
1268 	glMatrixMode(GL_TEXTURE);
1269 	glPushMatrix();
1270 
1271 	GL_SetupCubeMapMatrix(false);
1272 
1273 	GL_ModulateAlphaDrawColor();
1274 	glColor3fv(&currentshadowlight->baseColor[0]);
1275 	GL_EnableColorShader (false);
1276 	R_DrawBrushWV(e, false);
1277 	GL_DisableColorShader (false);
1278 
1279 	glPopMatrix();
1280 	glMatrixMode(GL_MODELVIEW);
1281 
1282 
1283 	//	Specular bump mapping
1284 
1285 	if ( gl_cardtype == GEFORCE || gl_cardtype == GEFORCE3 )
1286 		GL_DrawAlpha();
1287 	else
1288 		GL_DrawSquareAlpha();
1289 
1290 	GL_EnableSpecularShader ();
1291 	R_DrawBrushHAV(e);
1292 	GL_DisableSpecularShader ();
1293 
1294 	if ( gl_cardtype == GENERIC ) {
1295 		int i;
1296 		GL_SquareAlpha();
1297 		//Why R_DrawBrushWV?: Same as for world but not WV is better
1298 		for (i=0; i<3; i++) R_DrawBrushWV(e, false);
1299 	}
1300 
1301 
1302 
1303 	//	Attenttuation
1304 
1305 	GL_ModulateAlphaDrawAlpha();
1306 	GL_EnableAttShader();
1307 	R_DrawBrushATT(e);
1308 	GL_DisableAttShader();
1309 
1310 	//	Color map/light filter
1311 
1312 	glMatrixMode(GL_TEXTURE);
1313 	glPushMatrix();
1314 	GL_SetupCubeMapMatrix(false);
1315 
1316 	GL_ModulateAlphaDrawColor();
1317 	glColor3fv(&currentshadowlight->baseColor[0]);
1318 	GL_EnableColorShader (true);
1319 	R_DrawBrushWV(e, true);
1320 	GL_DisableColorShader (true);
1321 
1322 	glPopMatrix();
1323 	glMatrixMode(GL_MODELVIEW);
1324 
1325 }
1326 
1327 /*
1328 =============
1329 R_DrawAliasBumped
1330 
1331 Draw a alias entity with bump maps
1332 =============
1333 */
R_DrawAliasBumped(aliashdr_t * paliashdr,aliasframeinstant_t * instant)1334 void R_DrawAliasBumped(aliashdr_t *paliashdr, aliasframeinstant_t *instant) {
1335 
1336 
1337 	//Diffuse bump mapping
1338 	GL_DrawAlpha();
1339 	GL_EnableDiffuseShader ();
1340 	R_DrawAliasFrameLLV(paliashdr,instant);
1341 	GL_DisableDiffuseShader ();
1342 
1343 	//	Color map/light filter
1344 
1345 glMatrixMode(GL_TEXTURE);
1346 	glPushMatrix();
1347 	GL_SetupCubeMapMatrix(false);
1348 
1349 	GL_ModulateAlphaDrawColor();
1350 
1351 	glEnable(GL_LIGHTING);
1352 
1353 	GL_EnableColorShader (false);
1354 	R_DrawAliasFrameWV(paliashdr,instant, false);
1355 	GL_DisableColorShader (false);
1356 
1357 	glDisable(GL_LIGHTING);
1358 
1359 	glPopMatrix();
1360 	glMatrixMode(GL_MODELVIEW);
1361 
1362 	//Specular bump mapping
1363 	if ( gl_cardtype == GEFORCE )
1364 		GL_DrawAlpha();
1365 	else
1366 		GL_DrawSquareAlpha();
1367 
1368 	GL_EnableSpecularShader ();
1369 	R_DrawAliasFrameHAV(paliashdr,instant);
1370 	GL_DisableSpecularShader ();
1371 
1372 	if ( gl_cardtype == GENERIC ) {
1373 		int i;
1374 		GL_SquareAlpha();
1375 		for (i=0; i<3; i++) R_DrawAliasFrameWV(paliashdr,instant, false);
1376 	}
1377 
1378 
1379 	//	Color map/light filter
1380 
1381 	glMatrixMode(GL_TEXTURE);
1382 	glPushMatrix();
1383 	GL_SetupCubeMapMatrix(false);
1384 
1385 	GL_ModulateAlphaDrawColor();
1386 
1387 	glEnable(GL_LIGHTING);
1388 
1389 	GL_EnableColorShader (true);
1390 	R_DrawAliasFrameWV(paliashdr,instant, true);
1391 	GL_DisableColorShader (true);
1392 
1393 	glDisable(GL_LIGHTING);
1394 
1395 	glPopMatrix();
1396 	glMatrixMode(GL_MODELVIEW);
1397 
1398 }
1399