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, c_light_polys, c_nodes, c_leafs;
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_playermip = {"gl_playermip","0"};
89 //cvar_t gl_nocolors = {"gl_nocolors","0"};
90 //cvar_t gl_keeptjunctions = {"gl_keeptjunctions","1"};
91 //cvar_t gl_reporttjunctions = {"gl_reporttjunctions","0"};
92 cvar_t contrast = {"contrast", "1.0", TRUE}; // LordHavoc: a method of operating system independent color correction
93 cvar_t brightness = {"brightness", "1.0", TRUE}; // LordHavoc: a method of operating system independent color correction
94 cvar_t gl_lightmode = {"gl_lightmode", "1", TRUE}; // LordHavoc: overbright lighting
95 //cvar_t r_dynamicwater = {"r_dynamicwater", "1"};
96 //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...
97 cvar_t r_farclip = {"r_farclip", "6144"};
99 cvar_t gl_fogenable = {"gl_fogenable", "0"};
100 cvar_t gl_fogdensity = {"gl_fogdensity", "0.25"};
101 cvar_t gl_fogred = {"gl_fogred","0.3"};
102 cvar_t gl_foggreen = {"gl_foggreen","0.3"};
103 cvar_t gl_fogblue = {"gl_fogblue","0.3"};
104 cvar_t gl_fogstart = {"gl_fogstart", "0"};
105 cvar_t gl_fogend = {"gl_fogend","0"};
106 cvar_t glfog = {"glfog", "0"};
110 void makechrometextures()
112 int x, y, g, g2, amplitude, noise[64][64], min, max;
113 byte data[64][64][4];
117 chrometexture = texture_extension_number++;
118 glBindTexture(GL_TEXTURE_2D, chrometexture);
120 #define n(x,y) noise[(y)&63][(x)&63]
122 amplitude = 16777215;
125 for (;(g = g2 >> 1) >= 1;g2 >>= 1)
127 // subdivide, diamond-square algorythm (really this has little to do with squares)
129 for (y = 0;y < 64;y += g2)
130 for (x = 0;x < 64;x += g2)
131 n(x+g,y+g) = (n(x,y) + n(x+g2,y) + n(x,y+g2) + n(x+g2,y+g2)) >> 2;
133 for (y = 0;y < 64;y += g2)
134 for (x = 0;x < 64;x += g2)
136 n(x+g,y) = (n(x,y) + n(x+g2,y) + n(x+g,y-g) + n(x+g,y+g)) >> 2;
137 n(x,y+g) = (n(x,y) + n(x,y+g2) + n(x-g,y+g) + n(x+g,y+g)) >> 2;
139 // brownian motion theory
141 for (y = 0;y < 64;y += g)
142 for (x = 0;x < 64;x += g)
143 noise[y][x] += rand()&litude;
145 // normalize the noise range
147 for (y = 0;y < 64;y++)
148 for (x = 0;x < 64;x++)
150 if (n(x,y) < min) min = n(x,y);
151 if (n(x,y) > max) max = n(x,y);
154 for (y = 0;y < 64;y++)
155 for (x = 0;x < 64;x++)
156 n(x,y) = (n(x,y) - min) * 255 / max;
160 // convert to RGBA data
161 for (y = 0;y < 64;y++)
162 for (x = 0;x < 64;x++)
164 data[y][x][0] = data[y][x][1] = data[y][x][2] = (byte) noise[y][x];
168 glTexImage2D (GL_TEXTURE_2D, 0, 4, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
170 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
172 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
173 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
176 extern qboolean isRagePro;
182 float fog_density, fog_red, fog_green, fog_blue;
184 qboolean oldgl_fogenable;
185 void FOG_framebegin()
189 // if (!Nehahrademcompatibility)
190 // gl_fogenable.value = 0;
191 if (gl_fogenable.value)
193 oldgl_fogenable = true;
194 fog_density = gl_fogdensity.value;
195 fog_red = gl_fogred.value;
196 fog_green = gl_foggreen.value;
197 fog_blue = gl_fogblue.value;
199 else if (oldgl_fogenable)
201 oldgl_fogenable = false;
212 // LordHavoc: Borland C++ 5.0 was choking on this line, stupid compiler...
213 //GLfloat colors[4] = {(GLfloat) gl_fogred.value, (GLfloat) gl_foggreen.value, (GLfloat) gl_fogblue.value, (GLfloat) 1};
216 colors[1] = fog_green;
217 colors[2] = fog_blue;
226 glFogi (GL_FOG_MODE, GL_EXP2);
227 glFogf (GL_FOG_DENSITY, (GLfloat) fog_density / 100);
228 glFogfv (GL_FOG_COLOR, colors);
239 fogdensity = -4000.0f / (fog_density * fog_density);
240 fogcolor[0] = fog_red = bound(0.0f, fog_red , 1.0f);
241 fogcolor[1] = fog_green = bound(0.0f, fog_green, 1.0f);
242 fogcolor[2] = fog_blue = bound(0.0f, fog_blue , 1.0f);
265 Cvar_Set("gl_fogenable", "0");
266 Cvar_Set("gl_fogdensity", "0.2");
267 Cvar_Set("gl_fogred", "0.3");
268 Cvar_Set("gl_foggreen", "0.3");
269 Cvar_Set("gl_fogblue", "0.3");
271 fog_density = fog_red = fog_green = fog_blue = 0.0f;
274 void FOG_registercvars()
276 Cvar_RegisterVariable (&glfog);
279 Cvar_RegisterVariable (&gl_fogenable);
280 Cvar_RegisterVariable (&gl_fogdensity);
281 Cvar_RegisterVariable (&gl_fogred);
282 Cvar_RegisterVariable (&gl_foggreen);
283 Cvar_RegisterVariable (&gl_fogblue);
284 Cvar_RegisterVariable (&gl_fogstart);
285 Cvar_RegisterVariable (&gl_fogend);
293 // LordHavoc: vertex array
295 float *aliasvertnorm;
296 byte *aliasvertcolor;
298 void rmain_registercvars()
300 // allocate vertex processing arrays
301 aliasvert = malloc(sizeof(float[MD2MAX_VERTS][3]));
302 aliasvertnorm = malloc(sizeof(float[MD2MAX_VERTS][3]));
303 aliasvertcolor = malloc(sizeof(byte[MD2MAX_VERTS][4]));
306 Cvar_RegisterVariable (&r_speeds2);
307 Cvar_RegisterVariable (&contrast);
308 Cvar_RegisterVariable (&brightness);
309 Cvar_RegisterVariable (&gl_lightmode);
310 // Cvar_RegisterVariable (&r_dynamicwater);
311 // Cvar_RegisterVariable (&r_dynamicbothsides);
312 Cvar_RegisterVariable (&r_fullbrights);
314 Cvar_SetValue("r_fullbrights", 0);
315 // if (gl_vendor && strstr(gl_vendor, "3Dfx"))
316 // gl_lightmode.value = 0;
317 Cvar_RegisterVariable (&r_fullbright);
318 makechrometextures();
325 void R_RotateForEntity (entity_t *e)
327 glTranslatef (e->origin[0], e->origin[1], e->origin[2]);
329 glRotatef (e->angles[1], 0, 0, 1);
330 glRotatef (-e->angles[0], 0, 1, 0);
331 glRotatef (e->angles[2], 1, 0, 0);
333 glScalef (e->scale, e->scale, e->scale); // LordHavoc: model scale
337 // LordHavoc: if not for the fact BRIGHTFIELD particles require this, it would be removed...
338 #define NUMVERTEXNORMALS 162
340 float r_avertexnormals[NUMVERTEXNORMALS][3] = {
344 // LordHavoc: moved this shading stuff up because the sprites need shading stuff
350 void R_LightPoint (vec3_t color, vec3_t p);
351 void R_DynamicLightPoint(vec3_t color, vec3_t org, int *dlightbits);
352 void R_DynamicLightPointNoMask(vec3_t color, vec3_t org);
354 float R_CalcAnimLerp(int pose, float lerpscale)
356 if (currententity->draw_lastmodel == currententity->model && currententity->draw_lerpstart <= cl.time)
358 if (pose != currententity->draw_pose)
360 currententity->draw_lastpose = currententity->draw_pose;
361 currententity->draw_pose = pose;
362 currententity->draw_lerpstart = cl.time;
366 return ((cl.time - currententity->draw_lerpstart) * lerpscale);
368 else // uninitialized
370 currententity->draw_lastmodel = currententity->model;
371 currententity->draw_lastpose = currententity->draw_pose = pose;
372 currententity->draw_lerpstart = cl.time;
378 =============================================================
382 =============================================================
390 void R_GetSpriteFrame (entity_t *currententity, mspriteframe_t **oldframe, mspriteframe_t **newframe, float *framelerp)
393 mspritegroup_t *pspritegroup;
394 int i, j, numframes, frame;
395 float *pintervals, fullinterval, targettime, time, jtime, jinterval;
397 psprite = currententity->model->cache.data;
398 frame = currententity->frame;
400 if ((frame >= psprite->numframes) || (frame < 0))
402 Con_Printf ("R_DrawSprite: no such frame %d\n", frame);
406 if (psprite->frames[frame].type == SPR_SINGLE)
408 if (currententity->draw_lastmodel == currententity->model && currententity->draw_lerpstart < cl.time)
410 if (frame != currententity->draw_pose)
412 currententity->draw_lastpose = currententity->draw_pose;
413 currententity->draw_pose = frame;
414 currententity->draw_lerpstart = cl.time;
418 *framelerp = (cl.time - currententity->draw_lerpstart) * 10.0;
420 else // uninitialized
422 currententity->draw_lastmodel = currententity->model;
423 currententity->draw_lastpose = currententity->draw_pose = frame;
424 currententity->draw_lerpstart = cl.time;
427 *oldframe = psprite->frames[currententity->draw_lastpose].frameptr;
428 *newframe = psprite->frames[frame].frameptr;
432 pspritegroup = (mspritegroup_t *)psprite->frames[frame].frameptr;
433 pintervals = pspritegroup->intervals;
434 numframes = pspritegroup->numframes;
435 fullinterval = pintervals[numframes-1];
437 time = cl.time + currententity->syncbase;
439 // when loading in Mod_LoadSpriteGroup, we guaranteed all interval values
440 // are positive, so we don't have to worry about division by 0
441 targettime = time - ((int)(time / fullinterval)) * fullinterval;
443 // LordHavoc: since I can't measure the time properly when it loops from numframes-1 to 0,
444 // I instead measure the time of the first frame, hoping it is consistent
445 j = numframes-1;jtime = 0;jinterval = pintervals[1] - pintervals[0];
446 for (i=0 ; i<(numframes-1) ; i++)
448 if (pintervals[i] > targettime)
450 j = i;jinterval = pintervals[i] - jtime;jtime = pintervals[i];
452 *framelerp = (targettime - jtime) / jinterval;
454 *oldframe = pspritegroup->frames[j];
455 *newframe = pspritegroup->frames[i];
459 void GL_DrawSpriteImage (mspriteframe_t *frame, vec3_t origin, vec3_t up, vec3_t right, int red, int green, int blue, int alpha)
461 // LordHavoc: rewrote this to use the transparent poly system
462 transpolybegin(frame->gl_texturenum, 0, frame->gl_fogtexturenum, currententity->effects & EF_ADDITIVE ? TPOLYTYPE_ADD : TPOLYTYPE_ALPHA);
463 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);
464 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);
465 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);
466 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);
470 extern qboolean isG200, isRagePro, lighthalf;
478 void R_DrawSpriteModel (entity_t *e)
480 mspriteframe_t *oldframe, *newframe;
481 float *up, *right, lerp, ilerp;
482 vec3_t v_forward, v_right, v_up, org;
485 // don't even bother culling, because it's just a single
486 // polygon without a surface cache
487 R_GetSpriteFrame (e, &oldframe, &newframe, &lerp);
488 if (lerp < 0) lerp = 0;
489 if (lerp > 1) lerp = 1;
490 if (isRagePro) // LordHavoc: no alpha scaling supported on per pixel alpha images on ATI Rage Pro... ACK!
493 psprite = e->model->cache.data;
495 if (psprite->type == SPR_ORIENTED)
496 { // bullet marks on walls
497 AngleVectors (e->angles, v_forward, v_right, v_up);
500 VectorSubtract(e->origin, vpn, org);
506 VectorCopy(e->origin, org);
510 VectorScale(up, e->scale, up);
511 VectorScale(right, e->scale, right);
514 if (e->model->flags & EF_FULLBRIGHT || e->effects & EF_FULLBRIGHT)
518 shadecolor[0] = e->colormod[0] * 128;
519 shadecolor[1] = e->colormod[1] * 128;
520 shadecolor[2] = e->colormod[2] * 128;
524 shadecolor[0] = e->colormod[0] * 255;
525 shadecolor[1] = e->colormod[1] * 255;
526 shadecolor[2] = e->colormod[2] * 255;
531 R_LightPoint (shadecolor, e->origin);
532 R_DynamicLightPointNoMask(shadecolor, e->origin);
535 shadecolor[0] *= e->colormod[0] * 0.5;
536 shadecolor[1] *= e->colormod[1] * 0.5;
537 shadecolor[2] *= e->colormod[2] * 0.5;
541 // LordHavoc: interpolated sprite rendering
543 GL_DrawSpriteImage(oldframe, org, up, right, shadecolor[0],shadecolor[1],shadecolor[2],e->alpha*255*ilerp);
545 GL_DrawSpriteImage(newframe, org, up, right, shadecolor[0],shadecolor[1],shadecolor[2],e->alpha*255*lerp);
549 =============================================================
553 =============================================================
556 extern vec3_t softwaretransform_x;
557 extern vec3_t softwaretransform_y;
558 extern vec3_t softwaretransform_z;
559 extern vec_t softwaretransform_scale;
560 extern vec3_t softwaretransform_offset;
561 void R_AliasLerpVerts(int vertcount, float lerp, trivert2 *verts1, vec3_t scale1, vec3_t translate1, trivert2 *verts2, vec3_t scale2, vec3_t translate2)
564 vec3_t point, matrix_x, matrix_y, matrix_z;
568 if (lerp < 0) lerp = 0;
569 if (lerp > 1) lerp = 1;
572 float ilerp, ilerp127, lerp127, scalex1, scalex2, translatex, scaley1, scaley2, translatey, scalez1, scalez2, translatez;
573 if (lerp < 0) lerp = 0;
574 if (lerp > 1) lerp = 1;
576 ilerp127 = ilerp * (1.0 / 127.0);
577 lerp127 = lerp * (1.0 / 127.0);
578 VectorScale(softwaretransform_x, softwaretransform_scale, matrix_x);
579 VectorScale(softwaretransform_y, softwaretransform_scale, matrix_y);
580 VectorScale(softwaretransform_z, softwaretransform_scale, matrix_z);
581 // calculate combined interpolation variables
582 scalex1 = scale1[0] * ilerp;scalex2 = scale2[0] * lerp;translatex = translate1[0] * ilerp + translate2[0] * lerp;
583 scaley1 = scale1[1] * ilerp;scaley2 = scale2[1] * lerp;translatey = translate1[1] * ilerp + translate2[1] * lerp;
584 scalez1 = scale1[2] * ilerp;scalez2 = scale2[2] * lerp;translatez = translate1[2] * ilerp + translate2[2] * lerp;
586 for (i = 0;i < vertcount;i++)
588 // rotate, scale, and translate the vertex locations
589 point[0] = verts1->v[0] * scalex1 + verts2->v[0] * scalex2 + translatex;
590 point[1] = verts1->v[1] * scaley1 + verts2->v[1] * scaley2 + translatey;
591 point[2] = verts1->v[2] * scalez1 + verts2->v[2] * scalez2 + translatez;
592 *av++ = point[0] * matrix_x[0] + point[1] * matrix_y[0] + point[2] * matrix_z[0] + softwaretransform_offset[0];
593 *av++ = point[0] * matrix_x[1] + point[1] * matrix_y[1] + point[2] * matrix_z[1] + softwaretransform_offset[1];
594 *av++ = point[0] * matrix_x[2] + point[1] * matrix_y[2] + point[2] * matrix_z[2] + softwaretransform_offset[2];
595 // rotate the normals
596 point[0] = verts1->n[0] * ilerp127 + verts2->n[0] * lerp127;
597 point[1] = verts1->n[1] * ilerp127 + verts2->n[1] * lerp127;
598 point[2] = verts1->n[2] * ilerp127 + verts2->n[2] * lerp127;
599 *avn++ = point[0] * softwaretransform_x[0] + point[1] * softwaretransform_y[0] + point[2] * softwaretransform_z[0];
600 *avn++ = point[0] * softwaretransform_x[1] + point[1] * softwaretransform_y[1] + point[2] * softwaretransform_z[1];
601 *avn++ = point[0] * softwaretransform_x[2] + point[1] * softwaretransform_y[2] + point[2] * softwaretransform_z[2];
608 i127 = 1.0f / 127.0f;
609 VectorScale(softwaretransform_x, softwaretransform_scale, matrix_x);
610 VectorScale(softwaretransform_y, softwaretransform_scale, matrix_y);
611 VectorScale(softwaretransform_z, softwaretransform_scale, matrix_z);
613 for (i = 0;i < vertcount;i++)
615 // rotate, scale, and translate the vertex locations
616 point[0] = verts1->v[0] * scale1[0] + translate1[0];
617 point[1] = verts1->v[1] * scale1[1] + translate1[1];
618 point[2] = verts1->v[2] * scale1[2] + translate1[2];
619 *av++ = point[0] * matrix_x[0] + point[1] * matrix_y[0] + point[2] * matrix_z[0] + softwaretransform_offset[0];
620 *av++ = point[0] * matrix_x[1] + point[1] * matrix_y[1] + point[2] * matrix_z[1] + softwaretransform_offset[1];
621 *av++ = point[0] * matrix_x[2] + point[1] * matrix_y[2] + point[2] * matrix_z[2] + softwaretransform_offset[2];
622 // rotate the normals
623 point[0] = verts1->n[0] * i127;
624 point[1] = verts1->n[1] * i127;
625 point[2] = verts1->n[2] * i127;
626 *avn++ = point[0] * softwaretransform_x[0] + point[1] * softwaretransform_y[0] + point[2] * softwaretransform_z[0];
627 *avn++ = point[0] * softwaretransform_x[1] + point[1] * softwaretransform_y[1] + point[2] * softwaretransform_z[1];
628 *avn++ = point[0] * softwaretransform_x[2] + point[1] * softwaretransform_y[2] + point[2] * softwaretransform_z[2];
640 extern vec3_t lightspot;
641 void R_LightModel(int numverts, vec3_t center);
642 extern cvar_t gl_vertexarrays;
643 void R_DrawAliasFrame (aliashdr_t *paliashdr)
645 int i, pose, frame = currententity->frame;
646 float lerpscale, lerp;
648 softwaretransformforentity(currententity);
650 if ((frame >= paliashdr->numframes) || (frame < 0))
652 Con_DPrintf ("R_AliasSetupFrame: no such frame %d\n", frame);
656 pose = paliashdr->frames[frame].firstpose;
658 if (paliashdr->frames[frame].numposes > 1)
660 lerpscale = 1.0 / paliashdr->frames[frame].interval;
661 pose += (int)(cl.time * lerpscale) % paliashdr->frames[frame].numposes;
666 lerp = R_CalcAnimLerp(pose, lerpscale);
668 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);
670 R_LightModel(paliashdr->numverts, currententity->origin);
672 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
673 glShadeModel(GL_SMOOTH);
674 if (currententity->effects & EF_ADDITIVE)
676 glBlendFunc(GL_SRC_ALPHA, GL_ONE); // additive rendering
680 else if (modelalpha != 1.0)
682 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
692 if (gl_vertexarrays.value)
694 // LordHavoc: I would use InterleavedArrays here,
695 // but the texture coordinates are a seperate array,
696 // and it would be wasteful to copy them into the main array...
697 // glColor4f(shadecolor[0], shadecolor[1], shadecolor[2], modelalpha);
698 qglVertexPointer(3, GL_FLOAT, 0, aliasvert);
699 qglColorPointer(4, GL_UNSIGNED_BYTE, 0, aliasvertcolor);
700 glEnableClientState(GL_VERTEX_ARRAY);
701 glEnableClientState(GL_COLOR_ARRAY);
703 // draw the front faces
704 qglTexCoordPointer(2, GL_FLOAT, 0, (void *)((int) paliashdr->texcoords + (int) paliashdr));
705 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
706 qglDrawElements(GL_TRIANGLES, paliashdr->frontfaces * 3, GL_UNSIGNED_SHORT, (void *)((int) paliashdr->vertindices + (int) paliashdr));
707 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
709 // draw the back faces
710 qglTexCoordPointer(2, GL_FLOAT, 0, (void *)((int) paliashdr->texcoords + sizeof(float[2]) * paliashdr->numverts + (int) paliashdr));
711 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
712 qglDrawElements(GL_TRIANGLES, paliashdr->backfaces * 3, GL_UNSIGNED_SHORT, (void *)((int) paliashdr->vertindices + sizeof(unsigned short[3]) * paliashdr->frontfaces + (int) paliashdr));
713 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
715 glDisableClientState(GL_COLOR_ARRAY);
716 glDisableClientState(GL_VERTEX_ARRAY);
720 unsigned short *in, index;
722 in = (void *)((int) paliashdr->vertindices + (int) paliashdr);
723 glBegin(GL_TRIANGLES);
724 // draw the front faces
725 tex = (void *)((int) paliashdr->texcoords + (int) paliashdr);
728 for (i = 0;i < paliashdr->frontfaces * 3;i++)
731 glTexCoord2f(tex[index*2], tex[index*2+1]);
732 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));
733 glVertex3fv(&aliasvert[index*3]);
739 for (i = 0;i < paliashdr->frontfaces * 3;i++)
742 glTexCoord2f(tex[index*2], tex[index*2+1]);
743 glColor4ub(aliasvertcolor[index*4], aliasvertcolor[index*4+1], aliasvertcolor[index*4+2], aliasvertcolor[index*4+3]);
744 glVertex3fv(&aliasvert[index*3]);
748 // draw the back faces
749 tex += 2 * paliashdr->numverts;
752 for (i = 0;i < paliashdr->backfaces * 3;i++)
755 glTexCoord2f(tex[index*2], tex[index*2+1]);
756 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));
757 glVertex3fv(&aliasvert[index*3]);
763 for (i = 0;i < paliashdr->backfaces * 3;i++)
766 glTexCoord2f(tex[index*2], tex[index*2+1]);
767 glColor4ub(aliasvertcolor[index*4], aliasvertcolor[index*4+1], aliasvertcolor[index*4+2], aliasvertcolor[index*4+3]);
768 glVertex3fv(&aliasvert[index*3]);
778 glDisable (GL_TEXTURE_2D);
779 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
781 glDepthMask(0); // disable zbuffer updates
783 VectorSubtract(currententity->origin, r_refdef.vieworg, diff);
784 glColor4f(fogcolor[0], fogcolor[1], fogcolor[2], exp(fogdensity/DotProduct(diff,diff)));
786 if (gl_vertexarrays.value)
788 qglVertexPointer(3, GL_FLOAT, 0, aliasvert);
789 glEnableClientState(GL_VERTEX_ARRAY);
790 qglDrawElements(GL_TRIANGLES, paliashdr->numtris * 3, GL_UNSIGNED_SHORT, (void *)((int) paliashdr->vertindices + (int) paliashdr));
791 glDisableClientState(GL_VERTEX_ARRAY);
796 in = (void *)((int) paliashdr->vertindices + (int) paliashdr);
797 glBegin(GL_TRIANGLES);
798 for (i = 0;i < paliashdr->numtris * 3;i++)
799 glVertex3fv(&aliasvert[*in++ * 3]);
803 glEnable (GL_TEXTURE_2D);
807 if (!fogenabled && r_shadows.value && !(currententity->effects & EF_ADDITIVE) && currententity != &cl.viewent)
809 // flatten it to make a shadow
810 float *av = aliasvert + 2, l = lightspot[2] + 0.125;
812 for (i = 0;i < paliashdr->numverts;i++, av+=3)
815 glDisable (GL_TEXTURE_2D);
816 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
818 glDepthMask(0); // disable zbuffer updates
819 glColor4f (0,0,0,0.5 * modelalpha);
821 if (gl_vertexarrays.value)
823 qglVertexPointer(3, GL_FLOAT, 0, aliasvert);
824 glEnableClientState(GL_VERTEX_ARRAY);
825 qglDrawElements(GL_TRIANGLES, paliashdr->numtris * 3, GL_UNSIGNED_SHORT, (void *)((int) paliashdr->vertindices + (int) paliashdr));
826 glDisableClientState(GL_VERTEX_ARRAY);
831 in = (void *)((int) paliashdr->vertindices + (int) paliashdr);
832 glBegin(GL_TRIANGLES);
833 for (i = 0;i < paliashdr->numtris * 3;i++)
834 glVertex3fv(&aliasvert[*in++ * 3]);
838 glEnable (GL_TEXTURE_2D);
842 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
853 void R_DrawQ2AliasFrame (md2mem_t *pheader)
855 int *order, count, frame = currententity->frame;
857 md2memframe_t *frame1, *frame2;
859 softwaretransformforentity(currententity);
861 if ((frame >= pheader->num_frames) || (frame < 0))
863 Con_DPrintf ("R_SetupQ2AliasFrame: no such frame %d\n", frame);
867 lerp = R_CalcAnimLerp(frame, 10);
869 frame1 = (void *)((int) pheader + pheader->ofs_frames + (pheader->framesize * currententity->draw_lastpose));
870 frame2 = (void *)((int) pheader + pheader->ofs_frames + (pheader->framesize * currententity->draw_pose));
871 R_AliasLerpVerts(pheader->num_xyz, lerp, frame1->verts, frame1->scale, frame1->translate, frame2->verts, frame2->scale, frame2->translate);
873 R_LightModel(pheader->num_xyz, currententity->origin);
875 if (gl_vertexarrays.value)
877 // LordHavoc: big mess...
878 // using arrays only slightly, although it is enough to prevent duplicates
879 // (saving half the transforms)
880 //glColor4f(shadecolor[0], shadecolor[1], shadecolor[2], modelalpha);
881 qglVertexPointer(3, GL_FLOAT, 0, aliasvert);
882 qglColorPointer(4, GL_UNSIGNED_BYTE, 0, aliasvertcolor);
883 glEnableClientState(GL_VERTEX_ARRAY);
884 glEnableClientState(GL_COLOR_ARRAY);
886 order = (int *)((int)pheader + pheader->ofs_glcmds);
889 if (!(count = *order++))
892 glBegin(GL_TRIANGLE_STRIP);
895 glBegin(GL_TRIANGLE_FAN);
900 glTexCoord2f(((float *)order)[0], ((float *)order)[1]);
901 qglArrayElement(order[2]);
907 glDisableClientState(GL_COLOR_ARRAY);
908 glDisableClientState(GL_VERTEX_ARRAY);
912 order = (int *)((int)pheader + pheader->ofs_glcmds);
915 if (!(count = *order++))
918 glBegin(GL_TRIANGLE_STRIP);
921 glBegin(GL_TRIANGLE_FAN);
928 glTexCoord2f(((float *)order)[0], ((float *)order)[1]);
929 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));
930 glVertex3fv(&aliasvert[order[2] * 3]);
940 glTexCoord2f(((float *)order)[0], ((float *)order)[1]);
941 glColor4ub(aliasvertcolor[order[2] * 4], aliasvertcolor[order[2] * 4 + 1], aliasvertcolor[order[2] * 4 + 2], aliasvertcolor[order[2] * 4 + 3]);
942 glVertex3fv(&aliasvert[order[2] * 3]);
953 glDisable (GL_TEXTURE_2D);
954 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
956 glDepthMask(0); // disable zbuffer updates
959 VectorSubtract(currententity->origin, r_refdef.vieworg, diff);
960 glColor4f(fogcolor[0], fogcolor[1], fogcolor[2], exp(fogdensity/DotProduct(diff,diff)));
963 if (gl_vertexarrays.value)
965 // LordHavoc: big mess...
966 // using arrays only slightly, although it is enough to prevent duplicates
967 // (saving half the transforms)
968 //glColor4f(shadecolor[0], shadecolor[1], shadecolor[2], modelalpha);
969 qglVertexPointer(3, GL_FLOAT, 0, aliasvert);
970 glEnableClientState(GL_VERTEX_ARRAY);
972 order = (int *)((int)pheader + pheader->ofs_glcmds);
975 if (!(count = *order++))
978 glBegin(GL_TRIANGLE_STRIP);
981 glBegin(GL_TRIANGLE_FAN);
986 qglArrayElement(order[2]);
992 glDisableClientState(GL_VERTEX_ARRAY);
996 order = (int *)((int)pheader + pheader->ofs_glcmds);
999 if (!(count = *order++))
1002 glBegin(GL_TRIANGLE_STRIP);
1005 glBegin(GL_TRIANGLE_FAN);
1010 glVertex3fv(&aliasvert[order[2] * 3]);
1017 glEnable (GL_TEXTURE_2D);
1021 if (!fogenabled && r_shadows.value && !(currententity->effects & EF_ADDITIVE) && currententity != &cl.viewent)
1024 float *av = aliasvert + 2, l = lightspot[2] + 0.125;
1026 for (i = 0;i < pheader->num_xyz;i++, av+=3)
1029 glDisable (GL_TEXTURE_2D);
1030 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1031 glEnable (GL_BLEND);
1032 glDepthMask(0); // disable zbuffer updates
1033 glColor4f (0,0,0,0.5 * modelalpha);
1035 if (gl_vertexarrays.value)
1037 qglVertexPointer(3, GL_FLOAT, 0, aliasvert);
1038 glEnableClientState(GL_VERTEX_ARRAY);
1042 if (!(count = *order++))
1045 glBegin(GL_TRIANGLE_STRIP);
1048 glBegin(GL_TRIANGLE_FAN);
1053 qglArrayElement(order[2]);
1059 glDisableClientState(GL_VERTEX_ARRAY);
1065 if (!(count = *order++))
1068 glBegin(GL_TRIANGLE_STRIP);
1071 glBegin(GL_TRIANGLE_FAN);
1076 glVertex3fv(&aliasvert[order[2] * 3]);
1083 glEnable (GL_TEXTURE_2D);
1087 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1088 glEnable (GL_BLEND);
1092 int modeldlightbits[8];
1093 extern int r_dlightframecount;
1101 void R_DrawAliasModel (entity_t *e, int cull)
1106 aliashdr_t *paliashdr = NULL;
1107 md2mem_t *pheader = NULL;
1110 if (modelalpha < (1.0 / 64.0))
1111 return; // basically completely transparent
1113 clmodel = currententity->model;
1115 VectorAdd (currententity->origin, clmodel->mins, mins);
1116 VectorAdd (currententity->origin, clmodel->maxs, maxs);
1118 if (cull && R_CullBox (mins, maxs))
1121 VectorCopy (currententity->origin, r_entorigin);
1122 VectorSubtract (r_origin, r_entorigin, modelorg);
1125 mleaf_t *leaf = Mod_PointInLeaf (currententity->origin, cl.worldmodel);
1126 if (leaf->dlightframe == r_dlightframecount)
1127 for (i = 0;i < 8;i++)
1128 modeldlightbits[i] = leaf->dlightbits[i];
1130 for (i = 0;i < 8;i++)
1131 modeldlightbits[i] = 0;
1134 // get lighting information
1136 if (currententity->model->flags & EF_FULLBRIGHT || currententity->effects & EF_FULLBRIGHT)
1138 shadecolor[0] = currententity->colormod[0] * 256;
1139 shadecolor[1] = currententity->colormod[1] * 256;
1140 shadecolor[2] = currententity->colormod[2] * 256;
1144 R_LightPoint (shadecolor, currententity->origin);
1146 // HACK HACK HACK -- no fullbright colors, so make torches full light
1147 if (!strcmp (currententity->model->name, "progs/flame2.mdl") || !strcmp (currententity->model->name, "progs/flame.mdl") )
1148 shadecolor[0] = shadecolor[1] = shadecolor[2] = 128;
1150 shadecolor[0] *= currententity->colormod[0];
1151 shadecolor[1] *= currententity->colormod[1];
1152 shadecolor[2] *= currententity->colormod[2];
1155 // locate the proper data
1156 if (clmodel->aliastype == ALIASTYPE_MD2)
1158 pheader = (void *)Mod_Extradata (currententity->model);
1159 c_alias_polys += pheader->num_tris;
1163 paliashdr = (void *)Mod_Extradata (currententity->model);
1164 c_alias_polys += paliashdr->numtris;
1167 // draw all the triangles
1169 if (clmodel->aliastype == ALIASTYPE_MD2)
1171 if (currententity->skinnum < 0 || currententity->skinnum >= pheader->num_skins)
1173 currententity->skinnum = 0;
1174 Con_DPrintf("invalid skin number %d for model %s\n", currententity->skinnum, clmodel->name);
1176 glBindTexture(GL_TEXTURE_2D, pheader->gl_texturenum[currententity->skinnum]);
1180 if (currententity->skinnum < 0 || currententity->skinnum >= paliashdr->numskins)
1182 currententity->skinnum = 0;
1183 Con_DPrintf("invalid skin number %d for model %s\n", currententity->skinnum, clmodel->name);
1185 anim = (int)(cl.time*10) & 3;
1186 glBindTexture(GL_TEXTURE_2D, paliashdr->gl_texturenum[currententity->skinnum][anim]);
1188 glDisable(GL_ALPHA_TEST);
1189 glEnable (GL_TEXTURE_2D);
1191 // we can't dynamically colormap textures, so they are cached
1192 // seperately for the players. Heads are just uncolored.
1193 if (currententity->colormap != 0 /*vid.colormap*/ /* && !gl_nocolors.value*/)
1195 i = currententity - cl_entities;
1196 if (i >= 1 && i<=cl.maxclients /* && !strcmp (currententity->model->name, "progs/player.mdl") */)
1197 glBindTexture(GL_TEXTURE_2D, playertextures - 1 + i);
1200 // if (gl_affinemodels.value)
1201 // glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
1202 if (clmodel->aliastype == ALIASTYPE_MD2)
1203 R_DrawQ2AliasFrame (pheader);
1205 R_DrawAliasFrame (paliashdr);
1207 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
1210 //==================================================================================
1212 void R_DrawBrushModel (entity_t *e);
1216 R_DrawEntitiesOnList
1219 // LordHavoc: split so bmodels are rendered before any other objects
1220 void R_DrawEntitiesOnList1 (void)
1224 if (!r_drawentities.value)
1227 for (i=0 ; i<cl_numvisedicts ; i++)
1229 if (cl_visedicts[i]->model->type != mod_brush)
1231 currententity = cl_visedicts[i];
1232 modelalpha = currententity->alpha;
1234 R_DrawBrushModel (currententity);
1238 void R_DrawEntitiesOnList2 (void)
1242 if (!r_drawentities.value)
1245 for (i=0 ; i<cl_numvisedicts ; i++)
1247 currententity = cl_visedicts[i];
1248 modelalpha = currententity->alpha;
1250 switch (currententity->model->type)
1253 R_DrawAliasModel (currententity, true);
1257 R_DrawSpriteModel (currententity);
1271 void R_DrawViewModel (void)
1273 if (!r_drawviewmodel.value || chase_active.value || envmap || !r_drawentities.value || cl.items & IT_INVISIBILITY || cl.stats[STAT_HEALTH] <= 0 || !cl.viewent.model)
1276 currententity = &cl.viewent;
1277 currententity->alpha = modelalpha = cl_entities[cl.viewentity].alpha; // LordHavoc: if the player is transparent, so is his gun
1278 currententity->effects = cl_entities[cl.viewentity].effects;
1279 currententity->scale = 1;
1280 VectorCopy(cl_entities[cl.viewentity].colormod, currententity->colormod);
1282 // hack the depth range to prevent view model from poking into walls
1283 glDepthRange (gldepthmin, gldepthmin + 0.3*(gldepthmax-gldepthmin));
1284 R_DrawAliasModel (currententity, FALSE);
1285 glDepthRange (gldepthmin, gldepthmax);
1288 void R_DrawBrushModel (entity_t *e);
1290 void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees );
1292 void R_SetFrustum (void)
1296 if (r_refdef.fov_x == 90)
1298 // front side is visible
1300 VectorAdd (vpn, vright, frustum[0].normal);
1301 VectorSubtract (vpn, vright, frustum[1].normal);
1303 VectorAdd (vpn, vup, frustum[2].normal);
1304 VectorSubtract (vpn, vup, frustum[3].normal);
1308 // rotate VPN right by FOV_X/2 degrees
1309 RotatePointAroundVector( frustum[0].normal, vup, vpn, -(90-r_refdef.fov_x / 2 ) );
1310 // rotate VPN left by FOV_X/2 degrees
1311 RotatePointAroundVector( frustum[1].normal, vup, vpn, 90-r_refdef.fov_x / 2 );
1312 // rotate VPN up by FOV_X/2 degrees
1313 RotatePointAroundVector( frustum[2].normal, vright, vpn, 90-r_refdef.fov_y / 2 );
1314 // rotate VPN down by FOV_X/2 degrees
1315 RotatePointAroundVector( frustum[3].normal, vright, vpn, -( 90 - r_refdef.fov_y / 2 ) );
1318 for (i=0 ; i<4 ; i++)
1320 frustum[i].type = PLANE_ANYZ;
1321 frustum[i].dist = DotProduct (r_origin, frustum[i].normal);
1322 // frustum[i].signbits = SignbitsForPlane (&frustum[i]);
1323 BoxOnPlaneSideClassify(&frustum[i]);
1327 void R_AnimateLight (void);
1328 void V_CalcBlend (void);
1335 void R_SetupFrame (void)
1337 // don't allow cheats in multiplayer
1338 if (cl.maxclients > 1)
1340 Cvar_Set ("r_fullbright", "0");
1341 Cvar_Set ("r_ambient", "0");
1348 // build the transformation matrix for the given view angles
1349 VectorCopy (r_refdef.vieworg, r_origin);
1351 AngleVectors (r_refdef.viewangles, vpn, vright, vup);
1354 r_oldviewleaf = r_viewleaf;
1355 r_viewleaf = Mod_PointInLeaf (r_origin, cl.worldmodel);
1357 V_SetContentsColor (r_viewleaf->contents);
1360 r_cache_thrash = false;
1371 void MYgluPerspective( GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar )
1373 GLdouble xmin, xmax, ymin, ymax;
1375 ymax = zNear * tan( fovy * M_PI / 360.0 );
1378 xmin = ymin * aspect;
1379 xmax = ymax * aspect;
1381 glFrustum( xmin, xmax, ymin, ymax, zNear, zFar );
1385 extern char skyname[];
1392 void R_SetupGL (void)
1395 extern int glwidth, glheight;
1396 int x, x2, y2, y, w, h;
1401 glMatrixMode(GL_PROJECTION);
1403 x = r_refdef.vrect.x * glwidth/vid.width;
1404 x2 = (r_refdef.vrect.x + r_refdef.vrect.width) * glwidth/vid.width;
1405 y = (vid.height-r_refdef.vrect.y) * glheight/vid.height;
1406 y2 = (vid.height - (r_refdef.vrect.y + r_refdef.vrect.height)) * glheight/vid.height;
1408 // fudge around because of frac screen scale
1427 glViewport (glx + x, gly + y2, w, h);
1428 screenaspect = (float)r_refdef.vrect.width/r_refdef.vrect.height;
1429 // yfov = 2*atan((float)r_refdef.vrect.height/r_refdef.vrect.width)*180/M_PI;
1430 // if (skyname[0]) // skybox enabled?
1431 // MYgluPerspective (r_refdef.fov_y, screenaspect, 4, r_skyboxsize.value*1.732050807569 + 256); // this is size*sqrt(3) + 256
1433 MYgluPerspective (r_refdef.fov_y, screenaspect, 4, r_farclip.value);
1435 glCullFace(GL_FRONT);
1437 glMatrixMode(GL_MODELVIEW);
1440 glRotatef (-90, 1, 0, 0); // put Z going up
1441 glRotatef (90, 0, 0, 1); // put Z going up
1442 glRotatef (-r_refdef.viewangles[2], 1, 0, 0);
1443 glRotatef (-r_refdef.viewangles[0], 0, 1, 0);
1444 glRotatef (-r_refdef.viewangles[1], 0, 0, 1);
1445 glTranslatef (-r_refdef.vieworg[0], -r_refdef.vieworg[1], -r_refdef.vieworg[2]);
1447 glGetFloatv (GL_MODELVIEW_MATRIX, r_world_matrix);
1450 // set drawing parms
1452 // if (gl_cull.value)
1453 glEnable(GL_CULL_FACE);
1455 // glDisable(GL_CULL_FACE);
1457 glEnable(GL_BLEND); // was Disable
1458 glDisable(GL_ALPHA_TEST);
1459 glAlphaFunc(GL_GREATER, 0.5);
1460 glEnable(GL_DEPTH_TEST);
1462 glShadeModel(GL_SMOOTH);
1465 void R_DrawWorld (void);
1466 //void R_RenderDlights (void);
1467 void R_DrawParticles (void);
1476 // glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // LordHavoc: moved to SCR_UpdateScreen
1479 glDepthFunc (GL_LEQUAL);
1481 glDepthRange (gldepthmin, gldepthmax);
1484 // LordHavoc: my trick to *FIX* GLQuake lighting once and for all :)
1487 glMatrixMode(GL_PROJECTION);
1489 glOrtho (0, vid.width, vid.height, 0, -99999, 99999);
1490 glMatrixMode(GL_MODELVIEW);
1492 glDisable (GL_DEPTH_TEST);
1493 glDisable (GL_CULL_FACE);
1494 glDisable(GL_TEXTURE_2D);
1496 glBlendFunc (GL_DST_COLOR, GL_ONE);
1497 glBegin (GL_TRIANGLES);
1498 glColor3f (1, 1, 1);
1499 glVertex2f (-5000, -5000);
1500 glVertex2f (10000, -5000);
1501 glVertex2f (-5000, 10000);
1503 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1504 glDisable(GL_BLEND);
1505 glEnable(GL_TEXTURE_2D);
1506 glEnable (GL_DEPTH_TEST);
1507 glEnable (GL_CULL_FACE);
1510 extern cvar_t contrast;
1511 extern cvar_t brightness;
1512 extern cvar_t gl_lightmode;
1516 glMatrixMode(GL_PROJECTION);
1518 glOrtho (0, vid.width, vid.height, 0, -99999, 99999);
1519 glMatrixMode(GL_MODELVIEW);
1521 glDisable (GL_DEPTH_TEST);
1522 glDisable (GL_CULL_FACE);
1523 glDisable(GL_TEXTURE_2D);
1527 glBlendFunc (GL_DST_COLOR, GL_ONE);
1528 glBegin (GL_TRIANGLES);
1529 glColor3f (1, 1, 1);
1530 glVertex2f (-5000, -5000);
1531 glVertex2f (10000, -5000);
1532 glVertex2f (-5000, 10000);
1535 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1536 contrast.value = bound(0.2, contrast.value, 1.0);
1537 if (/*gl_polyblend.value && */v_blend[3])
1539 glBegin (GL_TRIANGLES);
1540 glColor4fv (v_blend);
1541 glVertex2f (-5000, -5000);
1542 glVertex2f (10000, -5000);
1543 glVertex2f (-5000, 10000);
1547 glEnable (GL_CULL_FACE);
1548 glEnable (GL_DEPTH_TEST);
1549 glDisable(GL_BLEND);
1550 glEnable(GL_TEXTURE_2D);
1553 #define TIMEREPORT(DESC) \
1554 if (r_speeds2.value)\
1556 temptime = -currtime;\
1557 currtime = Sys_FloatTime();\
1558 temptime += currtime;\
1559 Con_Printf(DESC " %.4fms ", temptime * 1000.0);\
1566 r_refdef must be set before the first call
1569 extern qboolean intimerefresh;
1570 extern qboolean skyisvisible;
1571 extern void R_Sky();
1572 extern void UploadLightmaps();
1573 void R_RenderView (void)
1575 // double currtime, temptime;
1576 // if (r_norefresh.value)
1579 if (!r_worldentity.model || !cl.worldmodel)
1580 Sys_Error ("R_RenderView: NULL worldmodel");
1582 lighthalf = gl_lightmode.value;
1586 // if (r_speeds2.value)
1588 // currtime = Sys_FloatTime();
1589 // Con_Printf("render time: ");
1592 // TIMEREPORT("R_Clear")
1594 // render normal view
1603 skyisvisible = false;
1605 R_MarkLeaves (); // done here so we know if we're in water
1606 R_DrawWorld (); // adds static entities to the list
1608 S_ExtraUpdate (); // don't let sound get messed up if going slow
1609 R_DrawEntitiesOnList1 (); // BSP models
1611 skypolyrender(); // fogged sky polys, affects depth
1612 if (skyname[0] && skyisvisible && !fogenabled)
1613 R_Sky(); // does not affect depth, draws over the sky polys
1615 R_DrawEntitiesOnList2 (); // other models
1616 // R_RenderDlights ();
1626 // if (r_speeds2.value)
1627 // Con_Printf("\n");