2 Copyright (C) 1996-1997 Id Software, Inc.
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.
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.
13 See the GNU General Public License for more details.
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.
24 entity_t r_worldentity;
26 qboolean r_cache_thrash; // compatability
28 vec3_t modelorg, r_entorigin;
29 entity_t *currententity;
31 int r_visframecount; // bumped when going to a new PVS
32 int r_framecount; // used for dlight push checking
36 int c_brush_polys, c_alias_polys;
38 qboolean envmap; // true during envmap command capture
40 // LordHavoc: moved all code related to particles into r_part.c
41 //int particletexture; // little dot for particles
42 int playertextures; // up to 16 color translated skins
44 extern qboolean isG200, isRagePro; // LordHavoc: special card hacks
54 float r_world_matrix[16];
55 float r_base_world_matrix[16];
62 mleaf_t *r_viewleaf, *r_oldviewleaf;
64 texture_t *r_notexture_mip;
66 int d_lightstylevalue[256]; // 8.8 fraction of base light value
69 void R_MarkLeaves (void);
71 //cvar_t r_norefresh = {"r_norefresh","0"};
72 cvar_t r_drawentities = {"r_drawentities","1"};
73 cvar_t r_drawviewmodel = {"r_drawviewmodel","1"};
74 cvar_t r_speeds = {"r_speeds","0"};
75 cvar_t r_speeds2 = {"r_speeds2","0"};
76 cvar_t r_fullbright = {"r_fullbright","0"};
77 //cvar_t r_lightmap = {"r_lightmap","0"};
78 //cvar_t r_shadows = {"r_shadows","0"};
79 cvar_t r_wateralpha = {"r_wateralpha","1"};
80 //cvar_t r_dynamic = {"r_dynamic","1"};
81 cvar_t r_novis = {"r_novis","0"};
82 cvar_t r_waterripple = {"r_waterripple","0"};
83 cvar_t r_fullbrights = {"r_fullbrights", "1"};
85 //cvar_t gl_cull = {"gl_cull","1"};
86 //cvar_t gl_affinemodels = {"gl_affinemodels","0"};
87 //cvar_t gl_polyblend = {"gl_polyblend","1"};
88 //cvar_t gl_flashblend = {"gl_flashblend","0"};
89 cvar_t gl_playermip = {"gl_playermip","0"};
90 //cvar_t gl_nocolors = {"gl_nocolors","0"};
91 //cvar_t gl_keeptjunctions = {"gl_keeptjunctions","1"};
92 //cvar_t gl_reporttjunctions = {"gl_reporttjunctions","0"};
93 cvar_t contrast = {"contrast", "1.0", TRUE}; // LordHavoc: a method of operating system independent color correction
94 cvar_t brightness = {"brightness", "1.0", TRUE}; // LordHavoc: a method of operating system independent color correction
95 cvar_t gl_lightmode = {"gl_lightmode", "1", TRUE}; // LordHavoc: overbright lighting
96 //cvar_t r_particles = {"r_particles", "1"};
97 //cvar_t r_dynamicwater = {"r_dynamicwater", "1"};
98 //cvar_t r_smokealpha = {"r_smokealpha", "0.25"};
99 //cvar_t r_dynamicbothsides = {"r_dynamicbothsides", "1"}; // LordHavoc: can disable dynamic lighting of backfaces, but quake maps are weird so it doesn't always work right...
101 cvar_t r_fogdensity = {"r_fogdensity", "0"};
102 cvar_t r_fogred = {"r_fogred","0.3"};
103 cvar_t r_foggreen = {"r_foggreen","0.3"};
104 cvar_t r_fogblue = {"r_fogblue","0.3"};
106 cvar_t gl_fogenable = {"gl_fogenable", "0"};
107 cvar_t gl_fogdensity = {"gl_fogdensity", "0.25"};
108 cvar_t gl_fogred = {"gl_fogred","0.3"};
109 cvar_t gl_foggreen = {"gl_foggreen","0.3"};
110 cvar_t gl_fogblue = {"gl_fogblue","0.3"};
111 cvar_t gl_fogstart = {"gl_fogstart", "0"};
112 cvar_t gl_fogend = {"gl_fogend","0"};
116 void makechrometextures()
118 int x, y, g, g2, amplitude, noise[64][64], min, max;
119 byte data[64][64][4];
123 chrometexture = texture_extension_number++;
124 glBindTexture(GL_TEXTURE_2D, chrometexture);
126 #define n(x,y) noise[(y)&63][(x)&63]
128 amplitude = 16777215;
131 for (;(g = g2 >> 1) >= 1;g2 >>= 1)
133 // subdivide, diamond-square algorythm (really this has little to do with squares)
135 for (y = 0;y < 64;y += g2)
136 for (x = 0;x < 64;x += g2)
137 n(x+g,y+g) = (n(x,y) + n(x+g2,y) + n(x,y+g2) + n(x+g2,y+g2)) >> 2;
139 for (y = 0;y < 64;y += g2)
140 for (x = 0;x < 64;x += g2)
142 n(x+g,y) = (n(x,y) + n(x+g2,y) + n(x+g,y-g) + n(x+g,y+g)) >> 2;
143 n(x,y+g) = (n(x,y) + n(x,y+g2) + n(x-g,y+g) + n(x+g,y+g)) >> 2;
145 // brownian motion theory
147 for (y = 0;y < 64;y += g)
148 for (x = 0;x < 64;x += g)
149 noise[y][x] += rand()&litude;
151 // normalize the noise range
153 for (y = 0;y < 64;y++)
154 for (x = 0;x < 64;x++)
156 if (n(x,y) < min) min = n(x,y);
157 if (n(x,y) > max) max = n(x,y);
160 for (y = 0;y < 64;y++)
161 for (x = 0;x < 64;x++)
162 n(x,y) = (n(x,y) - min) * 255 / max;
166 // convert to RGBA data
167 for (y = 0;y < 64;y++)
168 for (x = 0;x < 64;x++)
170 data[y][x][0] = data[y][x][1] = data[y][x][2] = (byte) noise[y][x];
174 glTexImage2D (GL_TEXTURE_2D, 0, 4, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
176 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
178 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
179 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
182 extern qboolean isRagePro;
189 qboolean oldgl_fogenable;
190 void FOG_framebegin()
192 if (gl_fogenable.value)
194 oldgl_fogenable = true;
195 r_fogdensity.value = gl_fogdensity.value;
196 r_fogred.value = gl_fogred.value;
197 r_foggreen.value = gl_foggreen.value;
198 r_fogblue.value = gl_fogblue.value;
200 else if (oldgl_fogenable)
202 oldgl_fogenable = false;
203 r_fogdensity.value = 0;
204 r_fogred.value = 0.3;
205 r_foggreen.value = 0.3;
206 r_fogblue.value = 0.3;
209 if(gl_fogdensity.value)
211 // LordHavoc: Borland C++ 5.0 was choking on this line, stupid compiler...
212 //GLfloat colors[4] = {(GLfloat) gl_fogred.value, (GLfloat) gl_foggreen.value, (GLfloat) gl_fogblue.value, (GLfloat) 1};
214 colors[0] = gl_fogred.value;
215 colors[1] = gl_foggreen.value;
216 colors[2] = gl_fogblue.value;
219 glFogi (GL_FOG_MODE, GL_EXP2);
220 glFogf (GL_FOG_DENSITY, (GLfloat) gl_fogdensity.value / 100);
221 glFogfv (GL_FOG_COLOR, colors);
227 if (r_fogdensity.value)
230 fogdensity = -6144.0f / (r_fogdensity.value * r_fogdensity.value);
231 fogcolor[0] = bound(0.0f, r_fogred.value, 1.0f);
232 fogcolor[1] = bound(0.0f, r_foggreen.value, 1.0f);
233 fogcolor[2] = bound(0.0f, r_fogblue.value, 1.0f);
247 // glDisable(GL_FOG);
252 gl_fogenable.value = 0;
253 r_fogdensity.value = 0;
254 r_fogred.value = 0.3;
255 r_fogblue.value = 0.3;
256 r_foggreen.value = 0.3;
259 void FOG_registercvars()
261 Cvar_RegisterVariable (&r_fogdensity);
262 Cvar_RegisterVariable (&r_fogred);
263 Cvar_RegisterVariable (&r_foggreen);
264 Cvar_RegisterVariable (&r_fogblue);
265 Cvar_RegisterVariable (&gl_fogenable);
266 Cvar_RegisterVariable (&gl_fogdensity);
267 Cvar_RegisterVariable (&gl_fogred);
268 Cvar_RegisterVariable (&gl_foggreen);
269 Cvar_RegisterVariable (&gl_fogblue);
270 Cvar_RegisterVariable (&gl_fogstart);
271 Cvar_RegisterVariable (&gl_fogend);
278 // LordHavoc: vertex array
280 float *aliasvertnorm;
281 byte *aliasvertcolor;
283 void rmain_registercvars()
285 // allocate vertex processing arrays
286 aliasvert = malloc(sizeof(float[MD2MAX_VERTS][3]));
287 aliasvertnorm = malloc(sizeof(float[MD2MAX_VERTS][3]));
288 aliasvertcolor = malloc(sizeof(byte[MD2MAX_VERTS][4]));
291 Cvar_RegisterVariable (&r_speeds2);
292 Cvar_RegisterVariable (&contrast);
293 Cvar_RegisterVariable (&brightness);
294 Cvar_RegisterVariable (&gl_lightmode);
295 // Cvar_RegisterVariable (&r_dynamicwater);
296 // Cvar_RegisterVariable (&r_particles);
297 // Cvar_RegisterVariable (&r_smokealpha);
298 // Cvar_RegisterVariable (&r_dynamicbothsides);
299 Cvar_RegisterVariable (&r_fullbrights);
301 Cvar_SetValue("r_fullbrights", 0);
302 // if (gl_vendor && strstr(gl_vendor, "3Dfx"))
303 // gl_lightmode.value = 0;
304 Cvar_RegisterVariable (&r_fullbright);
305 makechrometextures();
312 void R_RotateForEntity (entity_t *e)
314 glTranslatef (e->origin[0], e->origin[1], e->origin[2]);
316 glRotatef (e->angles[1], 0, 0, 1);
317 glRotatef (-e->angles[0], 0, 1, 0);
318 glRotatef (e->angles[2], 1, 0, 0);
320 glScalef (e->scale, e->scale, e->scale); // LordHavoc: model scale
324 // LordHavoc: if not for the fact BRIGHTFIELD particles require this, it would be removed...
325 #define NUMVERTEXNORMALS 162
327 float r_avertexnormals[NUMVERTEXNORMALS][3] = {
331 // LordHavoc: moved this shading stuff up because the sprites need shading stuff
337 void R_LightPoint (vec3_t color, vec3_t p);
338 void R_DynamicLightPoint(vec3_t color, vec3_t org, int *dlightbits);
339 void R_DynamicLightPointNoMask(vec3_t color, vec3_t org);
341 float R_CalcAnimLerp(int pose, float lerpscale)
343 if (currententity->draw_lastmodel == currententity->model && currententity->draw_lerpstart <= cl.time)
345 if (pose != currententity->draw_pose)
347 currententity->draw_lastpose = currententity->draw_pose;
348 currententity->draw_pose = pose;
349 currententity->draw_lerpstart = cl.time;
353 return ((cl.time - currententity->draw_lerpstart) * lerpscale);
355 else // uninitialized
357 currententity->draw_lastmodel = currententity->model;
358 currententity->draw_lastpose = currententity->draw_pose = pose;
359 currententity->draw_lerpstart = cl.time;
365 =============================================================
369 =============================================================
377 void R_GetSpriteFrame (entity_t *currententity, mspriteframe_t **oldframe, mspriteframe_t **newframe, float *framelerp)
380 mspritegroup_t *pspritegroup;
381 int i, j, numframes, frame;
382 float *pintervals, fullinterval, targettime, time, jtime, jinterval;
384 psprite = currententity->model->cache.data;
385 frame = currententity->frame;
387 if ((frame >= psprite->numframes) || (frame < 0))
389 Con_Printf ("R_DrawSprite: no such frame %d\n", frame);
393 if (psprite->frames[frame].type == SPR_SINGLE)
395 if (currententity->draw_lastmodel == currententity->model && currententity->draw_lerpstart < cl.time)
397 if (frame != currententity->draw_pose)
399 currententity->draw_lastpose = currententity->draw_pose;
400 currententity->draw_pose = frame;
401 currententity->draw_lerpstart = cl.time;
405 *framelerp = (cl.time - currententity->draw_lerpstart) * 10.0;
407 else // uninitialized
409 currententity->draw_lastmodel = currententity->model;
410 currententity->draw_lastpose = currententity->draw_pose = frame;
411 currententity->draw_lerpstart = cl.time;
414 *oldframe = psprite->frames[currententity->draw_lastpose].frameptr;
415 *newframe = psprite->frames[frame].frameptr;
419 pspritegroup = (mspritegroup_t *)psprite->frames[frame].frameptr;
420 pintervals = pspritegroup->intervals;
421 numframes = pspritegroup->numframes;
422 fullinterval = pintervals[numframes-1];
424 time = cl.time + currententity->syncbase;
426 // when loading in Mod_LoadSpriteGroup, we guaranteed all interval values
427 // are positive, so we don't have to worry about division by 0
428 targettime = time - ((int)(time / fullinterval)) * fullinterval;
430 // LordHavoc: since I can't measure the time properly when it loops from numframes-1 to 0,
431 // I instead measure the time of the first frame, hoping it is consistent
432 j = numframes-1;jtime = 0;jinterval = pintervals[1] - pintervals[0];
433 for (i=0 ; i<(numframes-1) ; i++)
435 if (pintervals[i] > targettime)
437 j = i;jinterval = pintervals[i] - jtime;jtime = pintervals[i];
439 *framelerp = (targettime - jtime) / jinterval;
441 *oldframe = pspritegroup->frames[j];
442 *newframe = pspritegroup->frames[i];
446 void GL_DrawSpriteImage (mspriteframe_t *frame, vec3_t origin, vec3_t up, vec3_t right, int red, int green, int blue, int alpha)
448 // LordHavoc: rewrote this to use the transparent poly system
449 // FIXME: need to use uncolored fog sprite
450 transpolybegin(frame->gl_texturenum, 0, frame->gl_fogtexturenum, currententity->effects & EF_ADDITIVE ? TPOLYTYPE_ADD : TPOLYTYPE_ALPHA);
451 transpolyvert(origin[0] + frame->down * up[0] + frame->left * right[0], origin[1] + frame->down * up[1] + frame->left * right[1], origin[2] + frame->down * up[2] + frame->left * right[2], 0, 1, red, green, blue, alpha);
452 transpolyvert(origin[0] + frame->up * up[0] + frame->left * right[0], origin[1] + frame->up * up[1] + frame->left * right[1], origin[2] + frame->up * up[2] + frame->left * right[2], 0, 0, red, green, blue, alpha);
453 transpolyvert(origin[0] + frame->up * up[0] + frame->right * right[0], origin[1] + frame->up * up[1] + frame->right * right[1], origin[2] + frame->up * up[2] + frame->right * right[2], 1, 0, red, green, blue, alpha);
454 transpolyvert(origin[0] + frame->down * up[0] + frame->right * right[0], origin[1] + frame->down * up[1] + frame->right * right[1], origin[2] + frame->down * up[2] + frame->right * right[2], 1, 1, red, green, blue, alpha);
458 extern qboolean isG200, isRagePro, lighthalf;
466 void R_DrawSpriteModel (entity_t *e)
468 mspriteframe_t *oldframe, *newframe;
469 float *up, *right, lerp, ilerp;
470 vec3_t v_forward, v_right, v_up, org;
473 // don't even bother culling, because it's just a single
474 // polygon without a surface cache
475 R_GetSpriteFrame (e, &oldframe, &newframe, &lerp);
476 if (lerp < 0) lerp = 0;
477 if (lerp > 1) lerp = 1;
478 if (isRagePro) // LordHavoc: no alpha scaling supported on per pixel alpha images on ATI Rage Pro... ACK!
481 psprite = e->model->cache.data;
483 if (psprite->type == SPR_ORIENTED)
484 { // bullet marks on walls
485 AngleVectors (e->angles, v_forward, v_right, v_up);
488 VectorSubtract(e->origin, vpn, org);
494 VectorCopy(e->origin, org);
498 VectorScale(up, e->scale, up);
499 VectorScale(right, e->scale, right);
502 if (e->model->flags & EF_FULLBRIGHT || e->effects & EF_FULLBRIGHT)
506 shadecolor[0] = e->colormod[0] * 128;
507 shadecolor[1] = e->colormod[1] * 128;
508 shadecolor[2] = e->colormod[2] * 128;
512 shadecolor[0] = e->colormod[0] * 255;
513 shadecolor[1] = e->colormod[1] * 255;
514 shadecolor[2] = e->colormod[2] * 255;
519 R_LightPoint (shadecolor, e->origin);
520 R_DynamicLightPointNoMask(shadecolor, e->origin);
523 shadecolor[0] *= e->colormod[0] * 0.5;
524 shadecolor[1] *= e->colormod[1] * 0.5;
525 shadecolor[2] *= e->colormod[2] * 0.5;
529 // LordHavoc: interpolated sprite rendering
531 GL_DrawSpriteImage(oldframe, org, up, right, shadecolor[0],shadecolor[1],shadecolor[2],e->alpha*255*ilerp);
533 GL_DrawSpriteImage(newframe, org, up, right, shadecolor[0],shadecolor[1],shadecolor[2],e->alpha*255*lerp);
537 =============================================================
541 =============================================================
544 extern vec3_t softwaretransform_x;
545 extern vec3_t softwaretransform_y;
546 extern vec3_t softwaretransform_z;
547 extern vec_t softwaretransform_scale;
548 extern vec3_t softwaretransform_offset;
549 void R_AliasLerpVerts(int vertcount, float lerp, trivert2 *verts1, vec3_t scale1, vec3_t translate1, trivert2 *verts2, vec3_t scale2, vec3_t translate2)
552 vec3_t point, matrix_x, matrix_y, matrix_z;
556 if (lerp < 0) lerp = 0;
557 if (lerp > 1) lerp = 1;
560 float ilerp, ilerp127, lerp127, scalex1, scalex2, translatex, scaley1, scaley2, translatey, scalez1, scalez2, translatez;
561 if (lerp < 0) lerp = 0;
562 if (lerp > 1) lerp = 1;
564 ilerp127 = ilerp * (1.0 / 127.0);
565 lerp127 = lerp * (1.0 / 127.0);
566 VectorScale(softwaretransform_x, softwaretransform_scale, matrix_x);
567 VectorScale(softwaretransform_y, softwaretransform_scale, matrix_y);
568 VectorScale(softwaretransform_z, softwaretransform_scale, matrix_z);
569 // calculate combined interpolation variables
570 scalex1 = scale1[0] * ilerp;scalex2 = scale2[0] * lerp;translatex = translate1[0] * ilerp + translate2[0] * lerp;
571 scaley1 = scale1[1] * ilerp;scaley2 = scale2[1] * lerp;translatey = translate1[1] * ilerp + translate2[1] * lerp;
572 scalez1 = scale1[2] * ilerp;scalez2 = scale2[2] * lerp;translatez = translate1[2] * ilerp + translate2[2] * lerp;
574 for (i = 0;i < vertcount;i++)
576 // rotate, scale, and translate the vertex locations
577 point[0] = verts1->v[0] * scalex1 + verts2->v[0] * scalex2 + translatex;
578 point[1] = verts1->v[1] * scaley1 + verts2->v[1] * scaley2 + translatey;
579 point[2] = verts1->v[2] * scalez1 + verts2->v[2] * scalez2 + translatez;
580 *av++ = point[0] * matrix_x[0] + point[1] * matrix_y[0] + point[2] * matrix_z[0] + softwaretransform_offset[0];
581 *av++ = point[0] * matrix_x[1] + point[1] * matrix_y[1] + point[2] * matrix_z[1] + softwaretransform_offset[1];
582 *av++ = point[0] * matrix_x[2] + point[1] * matrix_y[2] + point[2] * matrix_z[2] + softwaretransform_offset[2];
583 // rotate the normals
584 point[0] = verts1->n[0] * ilerp127 + verts2->n[0] * lerp127;
585 point[1] = verts1->n[1] * ilerp127 + verts2->n[1] * lerp127;
586 point[2] = verts1->n[2] * ilerp127 + verts2->n[2] * lerp127;
587 *avn++ = point[0] * softwaretransform_x[0] + point[1] * softwaretransform_y[0] + point[2] * softwaretransform_z[0];
588 *avn++ = point[0] * softwaretransform_x[1] + point[1] * softwaretransform_y[1] + point[2] * softwaretransform_z[1];
589 *avn++ = point[0] * softwaretransform_x[2] + point[1] * softwaretransform_y[2] + point[2] * softwaretransform_z[2];
596 i127 = 1.0f / 127.0f;
597 VectorScale(softwaretransform_x, softwaretransform_scale, matrix_x);
598 VectorScale(softwaretransform_y, softwaretransform_scale, matrix_y);
599 VectorScale(softwaretransform_z, softwaretransform_scale, matrix_z);
601 for (i = 0;i < vertcount;i++)
603 // rotate, scale, and translate the vertex locations
604 point[0] = verts1->v[0] * scale1[0] + translate1[0];
605 point[1] = verts1->v[1] * scale1[1] + translate1[1];
606 point[2] = verts1->v[2] * scale1[2] + translate1[2];
607 *av++ = point[0] * matrix_x[0] + point[1] * matrix_y[0] + point[2] * matrix_z[0] + softwaretransform_offset[0];
608 *av++ = point[0] * matrix_x[1] + point[1] * matrix_y[1] + point[2] * matrix_z[1] + softwaretransform_offset[1];
609 *av++ = point[0] * matrix_x[2] + point[1] * matrix_y[2] + point[2] * matrix_z[2] + softwaretransform_offset[2];
610 // rotate the normals
611 point[0] = verts1->n[0] * i127;
612 point[1] = verts1->n[1] * i127;
613 point[2] = verts1->n[2] * i127;
614 *avn++ = point[0] * softwaretransform_x[0] + point[1] * softwaretransform_y[0] + point[2] * softwaretransform_z[0];
615 *avn++ = point[0] * softwaretransform_x[1] + point[1] * softwaretransform_y[1] + point[2] * softwaretransform_z[1];
616 *avn++ = point[0] * softwaretransform_x[2] + point[1] * softwaretransform_y[2] + point[2] * softwaretransform_z[2];
628 extern vec3_t lightspot;
629 void R_LightModel(int numverts, vec3_t center);
630 extern cvar_t gl_vertexarrays;
631 void R_DrawAliasFrame (aliashdr_t *paliashdr)
633 int i, pose, frame = currententity->frame;
634 float lerpscale, lerp;
636 softwaretransformforentity(currententity);
638 if ((frame >= paliashdr->numframes) || (frame < 0))
640 Con_DPrintf ("R_AliasSetupFrame: no such frame %d\n", frame);
644 pose = paliashdr->frames[frame].firstpose;
646 if (paliashdr->frames[frame].numposes > 1)
648 lerpscale = 1.0 / paliashdr->frames[frame].interval;
649 pose += (int)(cl.time * lerpscale) % paliashdr->frames[frame].numposes;
654 lerp = R_CalcAnimLerp(pose, lerpscale);
656 R_AliasLerpVerts(paliashdr->numverts, lerp, (trivert2 *)((byte *)paliashdr + paliashdr->posedata) + currententity->draw_lastpose * paliashdr->numverts, paliashdr->scale, paliashdr->scale_origin, (trivert2 *)((byte *)paliashdr + paliashdr->posedata) + currententity->draw_pose * paliashdr->numverts, paliashdr->scale, paliashdr->scale_origin);
658 R_LightModel(paliashdr->numverts, currententity->origin);
660 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
661 glShadeModel(GL_SMOOTH);
662 if (currententity->effects & EF_ADDITIVE)
664 glBlendFunc(GL_SRC_ALPHA, GL_ONE); // additive rendering
668 else if (modelalpha != 1.0)
670 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
680 if (gl_vertexarrays.value)
682 // LordHavoc: I would use InterleavedArrays here,
683 // but the texture coordinates are a seperate array,
684 // and it would be wasteful to copy them into the main array...
685 // glColor4f(shadecolor[0], shadecolor[1], shadecolor[2], modelalpha);
686 qglVertexPointer(3, GL_FLOAT, 0, aliasvert);
687 qglColorPointer(4, GL_UNSIGNED_BYTE, 0, aliasvertcolor);
688 glEnableClientState(GL_VERTEX_ARRAY);
689 glEnableClientState(GL_COLOR_ARRAY);
691 // draw the front faces
692 qglTexCoordPointer(2, GL_FLOAT, 0, (void *)((int) paliashdr->texcoords + (int) paliashdr));
693 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
694 qglDrawElements(GL_TRIANGLES, paliashdr->frontfaces * 3, GL_UNSIGNED_SHORT, (void *)((int) paliashdr->vertindices + (int) paliashdr));
695 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
697 // draw the back faces
698 qglTexCoordPointer(2, GL_FLOAT, 0, (void *)((int) paliashdr->texcoords + sizeof(float[2]) * paliashdr->numverts + (int) paliashdr));
699 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
700 qglDrawElements(GL_TRIANGLES, paliashdr->backfaces * 3, GL_UNSIGNED_SHORT, (void *)((int) paliashdr->vertindices + sizeof(unsigned short[3]) * paliashdr->frontfaces + (int) paliashdr));
701 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
703 glDisableClientState(GL_COLOR_ARRAY);
704 glDisableClientState(GL_VERTEX_ARRAY);
708 unsigned short *in, index;
710 in = (void *)((int) paliashdr->vertindices + (int) paliashdr);
711 glBegin(GL_TRIANGLES);
712 // draw the front faces
713 tex = (void *)((int) paliashdr->texcoords + (int) paliashdr);
716 for (i = 0;i < paliashdr->frontfaces * 3;i++)
719 glTexCoord2f(tex[index*2], tex[index*2+1]);
720 glColor4f(aliasvertcolor[index*4] * (1.0f / 255.0f), aliasvertcolor[index*4+1] * (1.0f / 255.0f), aliasvertcolor[index*4+2] * (1.0f / 255.0f), aliasvertcolor[index*4+3] * (1.0f / 255.0f));
721 glVertex3fv(&aliasvert[index*3]);
727 for (i = 0;i < paliashdr->frontfaces * 3;i++)
730 glTexCoord2f(tex[index*2], tex[index*2+1]);
731 glColor4ub(aliasvertcolor[index*4], aliasvertcolor[index*4+1], aliasvertcolor[index*4+2], aliasvertcolor[index*4+3]);
732 glVertex3fv(&aliasvert[index*3]);
736 // draw the back faces
737 tex += 2 * paliashdr->numverts;
740 for (i = 0;i < paliashdr->backfaces * 3;i++)
743 glTexCoord2f(tex[index*2], tex[index*2+1]);
744 glColor4f(aliasvertcolor[index*4] * (1.0f / 255.0f), aliasvertcolor[index*4+1] * (1.0f / 255.0f), aliasvertcolor[index*4+2] * (1.0f / 255.0f), aliasvertcolor[index*4+3] * (1.0f / 255.0f));
745 glVertex3fv(&aliasvert[index*3]);
751 for (i = 0;i < paliashdr->backfaces * 3;i++)
754 glTexCoord2f(tex[index*2], tex[index*2+1]);
755 glColor4ub(aliasvertcolor[index*4], aliasvertcolor[index*4+1], aliasvertcolor[index*4+2], aliasvertcolor[index*4+3]);
756 glVertex3fv(&aliasvert[index*3]);
766 glDisable (GL_TEXTURE_2D);
767 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
769 glDepthMask(0); // disable zbuffer updates
771 VectorSubtract(currententity->origin, r_refdef.vieworg, diff);
772 glColor4f(fogcolor[0], fogcolor[1], fogcolor[2], exp(fogdensity/DotProduct(diff,diff)));
774 if (gl_vertexarrays.value)
776 qglVertexPointer(3, GL_FLOAT, 0, aliasvert);
777 glEnableClientState(GL_VERTEX_ARRAY);
778 qglDrawElements(GL_TRIANGLES, paliashdr->numtris * 3, GL_UNSIGNED_SHORT, (void *)((int) paliashdr->vertindices + (int) paliashdr));
779 glDisableClientState(GL_VERTEX_ARRAY);
784 in = (void *)((int) paliashdr->vertindices + (int) paliashdr);
785 glBegin(GL_TRIANGLES);
786 for (i = 0;i < paliashdr->numtris * 3;i++)
787 glVertex3fv(&aliasvert[*in++ * 3]);
791 glEnable (GL_TEXTURE_2D);
796 if (r_shadows.value && !(currententity->effects & EF_ADDITIVE) && currententity != &cl.viewent)
798 // flatten it to make a shadow
799 float *av = aliasvert + 2, l = lightspot[2] + 0.125;
801 for (i = 0;i < paliashdr->numverts;i++, av+=3)
804 glDisable (GL_TEXTURE_2D);
805 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
807 glDepthMask(0); // disable zbuffer updates
808 glColor4f (0,0,0,0.5 * modelalpha);
810 if (gl_vertexarrays.value)
812 qglVertexPointer(3, GL_FLOAT, 0, aliasvert);
813 glEnableClientState(GL_VERTEX_ARRAY);
814 qglDrawElements(GL_TRIANGLES, paliashdr->numtris * 3, GL_UNSIGNED_SHORT, (void *)((int) paliashdr->vertindices + (int) paliashdr));
815 glDisableClientState(GL_VERTEX_ARRAY);
820 in = (void *)((int) paliashdr->vertindices + (int) paliashdr);
821 glBegin(GL_TRIANGLES);
822 for (i = 0;i < paliashdr->numtris * 3;i++)
823 glVertex3fv(&aliasvert[*in++ * 3]);
827 glEnable (GL_TEXTURE_2D);
832 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
843 void R_DrawQ2AliasFrame (md2mem_t *pheader)
845 int *order, count, frame = currententity->frame;
847 md2memframe_t *frame1, *frame2;
849 softwaretransformforentity(currententity);
851 if ((frame >= pheader->num_frames) || (frame < 0))
853 Con_DPrintf ("R_SetupQ2AliasFrame: no such frame %d\n", frame);
857 lerp = R_CalcAnimLerp(frame, 10);
859 frame1 = (void *)((int) pheader + pheader->ofs_frames + (pheader->framesize * currententity->draw_lastpose));
860 frame2 = (void *)((int) pheader + pheader->ofs_frames + (pheader->framesize * currententity->draw_pose));
861 R_AliasLerpVerts(pheader->num_xyz, lerp, frame1->verts, frame1->scale, frame1->translate, frame2->verts, frame2->scale, frame2->translate);
863 R_LightModel(pheader->num_xyz, currententity->origin);
865 if (gl_vertexarrays.value)
867 // LordHavoc: big mess...
868 // using arrays only slightly, although it is enough to prevent duplicates
869 // (saving half the transforms)
870 //glColor4f(shadecolor[0], shadecolor[1], shadecolor[2], modelalpha);
871 qglVertexPointer(3, GL_FLOAT, 0, aliasvert);
872 qglColorPointer(4, GL_UNSIGNED_BYTE, 0, aliasvertcolor);
873 glEnableClientState(GL_VERTEX_ARRAY);
874 glEnableClientState(GL_COLOR_ARRAY);
876 order = (int *)((int)pheader + pheader->ofs_glcmds);
879 if (!(count = *order++))
882 glBegin(GL_TRIANGLE_STRIP);
885 glBegin(GL_TRIANGLE_FAN);
890 glTexCoord2f(((float *)order)[0], ((float *)order)[1]);
891 qglArrayElement(order[2]);
897 glDisableClientState(GL_COLOR_ARRAY);
898 glDisableClientState(GL_VERTEX_ARRAY);
902 order = (int *)((int)pheader + pheader->ofs_glcmds);
905 if (!(count = *order++))
908 glBegin(GL_TRIANGLE_STRIP);
911 glBegin(GL_TRIANGLE_FAN);
918 glTexCoord2f(((float *)order)[0], ((float *)order)[1]);
919 glColor4f(aliasvertcolor[order[2] * 4] * (1.0f / 255.0f), aliasvertcolor[order[2] * 4 + 1] * (1.0f / 255.0f), aliasvertcolor[order[2] * 4 + 2] * (1.0f / 255.0f), aliasvertcolor[order[2] * 4 + 3] * (1.0f / 255.0f));
920 glVertex3fv(&aliasvert[order[2] * 3]);
930 glTexCoord2f(((float *)order)[0], ((float *)order)[1]);
931 glColor4ub(aliasvertcolor[order[2] * 4], aliasvertcolor[order[2] * 4 + 1], aliasvertcolor[order[2] * 4 + 2], aliasvertcolor[order[2] * 4 + 3]);
932 glVertex3fv(&aliasvert[order[2] * 3]);
943 glDisable (GL_TEXTURE_2D);
944 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
946 glDepthMask(0); // disable zbuffer updates
949 VectorSubtract(currententity->origin, r_refdef.vieworg, diff);
950 glColor4f(fogcolor[0], fogcolor[1], fogcolor[2], exp(fogdensity/DotProduct(diff,diff)));
953 if (gl_vertexarrays.value)
955 // LordHavoc: big mess...
956 // using arrays only slightly, although it is enough to prevent duplicates
957 // (saving half the transforms)
958 //glColor4f(shadecolor[0], shadecolor[1], shadecolor[2], modelalpha);
959 qglVertexPointer(3, GL_FLOAT, 0, aliasvert);
960 glEnableClientState(GL_VERTEX_ARRAY);
962 order = (int *)((int)pheader + pheader->ofs_glcmds);
965 if (!(count = *order++))
968 glBegin(GL_TRIANGLE_STRIP);
971 glBegin(GL_TRIANGLE_FAN);
976 qglArrayElement(order[2]);
982 glDisableClientState(GL_VERTEX_ARRAY);
986 order = (int *)((int)pheader + pheader->ofs_glcmds);
989 if (!(count = *order++))
992 glBegin(GL_TRIANGLE_STRIP);
995 glBegin(GL_TRIANGLE_FAN);
1000 glVertex3fv(&aliasvert[order[2] * 3]);
1007 glEnable (GL_TEXTURE_2D);
1012 if (r_shadows.value && !(currententity->effects & EF_ADDITIVE) && currententity != &cl.viewent)
1015 float *av = aliasvert + 2, l = lightspot[2] + 0.125;
1017 for (i = 0;i < pheader->num_xyz;i++, av+=3)
1020 glDisable (GL_TEXTURE_2D);
1021 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1022 glEnable (GL_BLEND);
1023 glDepthMask(0); // disable zbuffer updates
1024 glColor4f (0,0,0,0.5 * modelalpha);
1026 if (gl_vertexarrays.value)
1028 qglVertexPointer(3, GL_FLOAT, 0, aliasvert);
1029 glEnableClientState(GL_VERTEX_ARRAY);
1033 if (!(count = *order++))
1036 glBegin(GL_TRIANGLE_STRIP);
1039 glBegin(GL_TRIANGLE_FAN);
1044 qglArrayElement(order[2]);
1050 glDisableClientState(GL_VERTEX_ARRAY);
1056 if (!(count = *order++))
1059 glBegin(GL_TRIANGLE_STRIP);
1062 glBegin(GL_TRIANGLE_FAN);
1067 glVertex3fv(&aliasvert[order[2] * 3]);
1074 glEnable (GL_TEXTURE_2D);
1079 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1080 glEnable (GL_BLEND);
1090 void R_DrawAliasModel (entity_t *e, int cull)
1095 aliashdr_t *paliashdr;
1099 if (modelalpha < (1.0 / 64.0))
1100 return; // basically completely transparent
1102 clmodel = currententity->model;
1104 VectorAdd (currententity->origin, clmodel->mins, mins);
1105 VectorAdd (currententity->origin, clmodel->maxs, maxs);
1107 if (cull && R_CullBox (mins, maxs))
1110 VectorCopy (currententity->origin, r_entorigin);
1111 VectorSubtract (r_origin, r_entorigin, modelorg);
1113 // get lighting information
1115 if (currententity->model->flags & EF_FULLBRIGHT || currententity->effects & EF_FULLBRIGHT)
1117 shadecolor[0] = currententity->colormod[0] * 256;
1118 shadecolor[1] = currententity->colormod[1] * 256;
1119 shadecolor[2] = currententity->colormod[2] * 256;
1123 R_LightPoint (shadecolor, currententity->origin);
1125 // HACK HACK HACK -- no fullbright colors, so make torches full light
1126 if (!strcmp (currententity->model->name, "progs/flame2.mdl") || !strcmp (currententity->model->name, "progs/flame.mdl") )
1127 shadecolor[0] = shadecolor[1] = shadecolor[2] = 128;
1129 shadecolor[0] *= currententity->colormod[0];
1130 shadecolor[1] *= currententity->colormod[1];
1131 shadecolor[2] *= currententity->colormod[2];
1134 // locate the proper data
1135 if (clmodel->aliastype == ALIASTYPE_MD2)
1137 pheader = (void *)Mod_Extradata (currententity->model);
1138 c_alias_polys += pheader->num_tris;
1142 paliashdr = (void *)Mod_Extradata (currententity->model);
1143 c_alias_polys += paliashdr->numtris;
1146 // draw all the triangles
1148 if (clmodel->aliastype == ALIASTYPE_MD2)
1150 if (currententity->skinnum < 0 || currententity->skinnum >= pheader->num_skins)
1152 currententity->skinnum = 0;
1153 Con_DPrintf("invalid skin number %d for model %s\n", currententity->skinnum, clmodel->name);
1155 glBindTexture(GL_TEXTURE_2D, pheader->gl_texturenum[currententity->skinnum]);
1159 if (currententity->skinnum < 0 || currententity->skinnum >= paliashdr->numskins)
1161 currententity->skinnum = 0;
1162 Con_DPrintf("invalid skin number %d for model %s\n", currententity->skinnum, clmodel->name);
1164 anim = (int)(cl.time*10) & 3;
1165 glBindTexture(GL_TEXTURE_2D, paliashdr->gl_texturenum[currententity->skinnum][anim]);
1167 glDisable(GL_ALPHA_TEST);
1168 glEnable (GL_TEXTURE_2D);
1170 // we can't dynamically colormap textures, so they are cached
1171 // seperately for the players. Heads are just uncolored.
1172 if (currententity->colormap != vid.colormap/* && !gl_nocolors.value*/)
1174 i = currententity - cl_entities;
1175 if (i >= 1 && i<=cl.maxclients /* && !strcmp (currententity->model->name, "progs/player.mdl") */)
1176 glBindTexture(GL_TEXTURE_2D, playertextures - 1 + i);
1179 // if (gl_affinemodels.value)
1180 // glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
1181 if (clmodel->aliastype == ALIASTYPE_MD2)
1182 R_DrawQ2AliasFrame (pheader);
1184 R_DrawAliasFrame (paliashdr);
1186 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1189 //==================================================================================
1191 void R_DrawBrushModel (entity_t *e);
1195 R_DrawEntitiesOnList
1198 // LordHavoc: split so bmodels are rendered before any other objects
1199 void R_DrawEntitiesOnList1 (void)
1203 if (!r_drawentities.value)
1206 for (i=0 ; i<cl_numvisedicts ; i++)
1208 if (cl_visedicts[i]->model->type != mod_brush)
1210 currententity = cl_visedicts[i];
1211 modelalpha = currententity->alpha;
1213 R_DrawBrushModel (currententity);
1217 void R_DrawEntitiesOnList2 (void)
1221 if (!r_drawentities.value)
1224 for (i=0 ; i<cl_numvisedicts ; i++)
1226 currententity = cl_visedicts[i];
1227 modelalpha = currententity->alpha;
1229 switch (currententity->model->type)
1232 R_DrawAliasModel (currententity, true);
1236 R_DrawSpriteModel (currententity);
1250 void R_DrawViewModel (void)
1252 if (!r_drawviewmodel.value || chase_active.value || envmap || !r_drawentities.value || cl.items & IT_INVISIBILITY || cl.stats[STAT_HEALTH] <= 0 || !cl.viewent.model)
1255 currententity = &cl.viewent;
1256 currententity->alpha = modelalpha = cl_entities[cl.viewentity].alpha; // LordHavoc: if the player is transparent, so is his gun
1257 currententity->effects = cl_entities[cl.viewentity].effects;
1258 currententity->scale = 1;
1259 VectorCopy(cl_entities[cl.viewentity].colormod, currententity->colormod);
1261 // hack the depth range to prevent view model from poking into walls
1262 glDepthRange (gldepthmin, gldepthmin + 0.3*(gldepthmax-gldepthmin));
1263 R_DrawAliasModel (currententity, FALSE);
1264 glDepthRange (gldepthmin, gldepthmax);
1267 void R_DrawBrushModel (entity_t *e);
1269 void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees );
1271 void R_SetFrustum (void)
1275 if (r_refdef.fov_x == 90)
1277 // front side is visible
1279 VectorAdd (vpn, vright, frustum[0].normal);
1280 VectorSubtract (vpn, vright, frustum[1].normal);
1282 VectorAdd (vpn, vup, frustum[2].normal);
1283 VectorSubtract (vpn, vup, frustum[3].normal);
1287 // rotate VPN right by FOV_X/2 degrees
1288 RotatePointAroundVector( frustum[0].normal, vup, vpn, -(90-r_refdef.fov_x / 2 ) );
1289 // rotate VPN left by FOV_X/2 degrees
1290 RotatePointAroundVector( frustum[1].normal, vup, vpn, 90-r_refdef.fov_x / 2 );
1291 // rotate VPN up by FOV_X/2 degrees
1292 RotatePointAroundVector( frustum[2].normal, vright, vpn, 90-r_refdef.fov_y / 2 );
1293 // rotate VPN down by FOV_X/2 degrees
1294 RotatePointAroundVector( frustum[3].normal, vright, vpn, -( 90 - r_refdef.fov_y / 2 ) );
1297 for (i=0 ; i<4 ; i++)
1299 frustum[i].type = PLANE_ANYZ;
1300 frustum[i].dist = DotProduct (r_origin, frustum[i].normal);
1301 // frustum[i].signbits = SignbitsForPlane (&frustum[i]);
1302 BoxOnPlaneSideClassify(&frustum[i]);
1306 void R_AnimateLight (void);
1307 void V_CalcBlend (void);
1314 void R_SetupFrame (void)
1316 // don't allow cheats in multiplayer
1317 if (cl.maxclients > 1)
1318 Cvar_Set ("r_fullbright", "0");
1324 // build the transformation matrix for the given view angles
1325 VectorCopy (r_refdef.vieworg, r_origin);
1327 AngleVectors (r_refdef.viewangles, vpn, vright, vup);
1330 r_oldviewleaf = r_viewleaf;
1331 r_viewleaf = Mod_PointInLeaf (r_origin, cl.worldmodel);
1333 V_SetContentsColor (r_viewleaf->contents);
1336 r_cache_thrash = false;
1344 void MYgluPerspective( GLdouble fovy, GLdouble aspect,
1345 GLdouble zNear, GLdouble zFar )
1347 GLdouble xmin, xmax, ymin, ymax;
1349 ymax = zNear * tan( fovy * M_PI / 360.0 );
1352 xmin = ymin * aspect;
1353 xmax = ymax * aspect;
1355 glFrustum( xmin, xmax, ymin, ymax, zNear, zFar );
1359 extern char skyname[];
1366 void R_SetupGL (void)
1369 extern int glwidth, glheight;
1370 int x, x2, y2, y, w, h;
1375 glMatrixMode(GL_PROJECTION);
1377 x = r_refdef.vrect.x * glwidth/vid.width;
1378 x2 = (r_refdef.vrect.x + r_refdef.vrect.width) * glwidth/vid.width;
1379 y = (vid.height-r_refdef.vrect.y) * glheight/vid.height;
1380 y2 = (vid.height - (r_refdef.vrect.y + r_refdef.vrect.height)) * glheight/vid.height;
1382 // fudge around because of frac screen scale
1401 glViewport (glx + x, gly + y2, w, h);
1402 screenaspect = (float)r_refdef.vrect.width/r_refdef.vrect.height;
1403 // yfov = 2*atan((float)r_refdef.vrect.height/r_refdef.vrect.width)*180/M_PI;
1404 // if (skyname[0]) // skybox enabled?
1405 // MYgluPerspective (r_refdef.fov_y, screenaspect, 4, r_skyboxsize.value*1.732050807569 + 256); // this is size*sqrt(3) + 256
1407 MYgluPerspective (r_refdef.fov_y, screenaspect, 4, 6144);
1409 glCullFace(GL_FRONT);
1411 glMatrixMode(GL_MODELVIEW);
1414 glRotatef (-90, 1, 0, 0); // put Z going up
1415 glRotatef (90, 0, 0, 1); // put Z going up
1416 glRotatef (-r_refdef.viewangles[2], 1, 0, 0);
1417 glRotatef (-r_refdef.viewangles[0], 0, 1, 0);
1418 glRotatef (-r_refdef.viewangles[1], 0, 0, 1);
1419 glTranslatef (-r_refdef.vieworg[0], -r_refdef.vieworg[1], -r_refdef.vieworg[2]);
1421 glGetFloatv (GL_MODELVIEW_MATRIX, r_world_matrix);
1424 // set drawing parms
1426 // if (gl_cull.value)
1427 glEnable(GL_CULL_FACE);
1429 // glDisable(GL_CULL_FACE);
1431 glEnable(GL_BLEND); // was Disable
1432 glDisable(GL_ALPHA_TEST);
1433 glAlphaFunc(GL_GREATER, 0.5);
1434 glEnable(GL_DEPTH_TEST);
1436 glShadeModel(GL_SMOOTH);
1439 void R_DrawWorld (void);
1440 //void R_RenderDlights (void);
1441 void R_DrawParticles (void);
1450 // glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // LordHavoc: moved to SCR_UpdateScreen
1453 glDepthFunc (GL_LEQUAL);
1455 glDepthRange (gldepthmin, gldepthmax);
1458 // LordHavoc: my trick to *FIX* GLQuake lighting once and for all :)
1461 glMatrixMode(GL_PROJECTION);
1463 glOrtho (0, vid.width, vid.height, 0, -99999, 99999);
1464 glMatrixMode(GL_MODELVIEW);
1466 glDisable (GL_DEPTH_TEST);
1467 glDisable (GL_CULL_FACE);
1468 glDisable(GL_TEXTURE_2D);
1470 glBlendFunc (GL_DST_COLOR, GL_ONE);
1471 glBegin (GL_TRIANGLES);
1472 glColor3f (1, 1, 1);
1473 glVertex2f (-5000, -5000);
1474 glVertex2f (10000, -5000);
1475 glVertex2f (-5000, 10000);
1477 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1478 glDisable(GL_BLEND);
1479 glEnable(GL_TEXTURE_2D);
1480 glEnable (GL_DEPTH_TEST);
1481 glEnable (GL_CULL_FACE);
1484 extern cvar_t contrast;
1485 extern cvar_t brightness;
1486 extern cvar_t gl_lightmode;
1490 glMatrixMode(GL_PROJECTION);
1492 glOrtho (0, vid.width, vid.height, 0, -99999, 99999);
1493 glMatrixMode(GL_MODELVIEW);
1495 glDisable (GL_DEPTH_TEST);
1496 glDisable (GL_CULL_FACE);
1497 glDisable(GL_TEXTURE_2D);
1501 glBlendFunc (GL_DST_COLOR, GL_ONE);
1502 glBegin (GL_TRIANGLES);
1503 glColor3f (1, 1, 1);
1504 glVertex2f (-5000, -5000);
1505 glVertex2f (10000, -5000);
1506 glVertex2f (-5000, 10000);
1509 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1510 contrast.value = bound(0.2, contrast.value, 1.0);
1511 if (/*gl_polyblend.value && */v_blend[3])
1513 glBegin (GL_TRIANGLES);
1514 glColor4fv (v_blend);
1515 glVertex2f (-5000, -5000);
1516 glVertex2f (10000, -5000);
1517 glVertex2f (-5000, 10000);
1521 glEnable (GL_CULL_FACE);
1522 glEnable (GL_DEPTH_TEST);
1523 glDisable(GL_BLEND);
1524 glEnable(GL_TEXTURE_2D);
1527 #define TIMEREPORT(DESC) \
1528 if (r_speeds2.value)\
1530 temptime = -currtime;\
1531 currtime = Sys_FloatTime();\
1532 temptime += currtime;\
1533 Con_Printf(DESC " %.4fms ", temptime * 1000.0);\
1540 r_refdef must be set before the first call
1543 void R_RenderView (void)
1545 double currtime, temptime;
1546 // if (r_norefresh.value)
1549 if (!r_worldentity.model || !cl.worldmodel)
1550 Sys_Error ("R_RenderView: NULL worldmodel");
1552 lighthalf = gl_lightmode.value;
1558 if (r_speeds2.value)
1560 currtime = Sys_FloatTime();
1561 Con_Printf("render time: ");
1564 TIMEREPORT("R_Clear")
1566 // render normal view
1569 TIMEREPORT("R_SetupFrame")
1571 TIMEREPORT("R_SetFrustum")
1573 TIMEREPORT("R_SetupGL")
1574 R_MarkLeaves (); // done here so we know if we're in water
1575 TIMEREPORT("R_MarkLeaves")
1576 R_DrawWorld (); // adds static entities to the list
1577 TIMEREPORT("R_DrawWorld")
1578 S_ExtraUpdate (); // don't let sound get messed up if going slow
1579 TIMEREPORT("S_ExtraUpdate")
1580 R_DrawEntitiesOnList1 (); // BSP models
1581 TIMEREPORT("R_DrawEntitiesOnList1")
1583 TIMEREPORT("wallpolyrender")
1584 R_DrawEntitiesOnList2 (); // other models
1585 TIMEREPORT("R_DrawEntitiesOnList2")
1586 // R_RenderDlights ();
1588 TIMEREPORT("R_DrawViewModel")
1590 TIMEREPORT("R_DrawParticles")
1592 TIMEREPORT("transpolyrender")
1596 TIMEREPORT("GL_BlendView")
1597 if (r_speeds2.value)