2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
gl_rmain.c
|
|
|
|
|
|
|
|
(description)
|
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
2001-09-28 06:26:31 +00:00
|
|
|
static const char rcsid[] =
|
|
|
|
"$Id$";
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2001-05-09 05:41:34 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/console.h"
|
2001-05-31 03:41:35 +00:00
|
|
|
#include "QF/cvar.h"
|
2001-05-14 06:47:38 +00:00
|
|
|
#include "QF/locs.h"
|
2001-05-14 20:35:32 +00:00
|
|
|
#include "QF/mathlib.h"
|
2001-05-09 05:41:34 +00:00
|
|
|
#include "QF/qargs.h"
|
2001-05-21 00:22:35 +00:00
|
|
|
#include "QF/render.h"
|
2001-05-14 20:35:32 +00:00
|
|
|
#include "QF/skin.h"
|
|
|
|
#include "QF/sound.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/sys.h"
|
2001-05-14 20:35:32 +00:00
|
|
|
#include "QF/vid.h"
|
2001-06-24 09:25:55 +00:00
|
|
|
#include "QF/GL/defines.h"
|
|
|
|
#include "QF/GL/funcs.h"
|
2001-08-26 17:13:33 +00:00
|
|
|
#include "QF/GL/qf_rlight.h"
|
|
|
|
#include "QF/GL/qf_rsurf.h"
|
2001-06-24 09:25:55 +00:00
|
|
|
#include "QF/GL/qf_screen.h"
|
|
|
|
#include "QF/GL/qf_vid.h"
|
|
|
|
|
2001-08-02 02:18:04 +00:00
|
|
|
#include "compat.h"
|
2001-05-13 00:28:50 +00:00
|
|
|
#include "r_cvar.h"
|
|
|
|
#include "r_dynamic.h"
|
2001-05-14 20:35:32 +00:00
|
|
|
#include "r_local.h"
|
2001-05-09 05:41:34 +00:00
|
|
|
#include "view.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
entity_t r_worldentity;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
qboolean r_cache_thrash; // compatability
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
vec3_t modelorg, r_entorigin;
|
|
|
|
entity_t *currententity;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int r_visframecount; // bumped when going to a new PVS
|
|
|
|
int r_framecount; // used for dlight push checking
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int c_brush_polys, c_alias_polys;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-09 05:41:34 +00:00
|
|
|
qboolean envmap; // true during envmap command capture
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
int mirrortexturenum; // quake texturenum, not gltexturenum
|
|
|
|
qboolean mirror;
|
|
|
|
mplane_t *mirror_plane;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// view origin
|
2001-02-26 06:48:02 +00:00
|
|
|
vec3_t vup;
|
|
|
|
vec3_t vpn;
|
|
|
|
vec3_t vright;
|
|
|
|
vec3_t r_origin;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
float r_world_matrix[16];
|
|
|
|
float r_base_world_matrix[16];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// screen size info
|
2001-02-26 06:48:02 +00:00
|
|
|
refdef_t r_refdef;
|
|
|
|
|
|
|
|
mleaf_t *r_viewleaf, *r_oldviewleaf;
|
|
|
|
|
|
|
|
int d_lightstylevalue[256]; // 8.8 fraction of base light value
|
|
|
|
|
2001-05-14 06:47:38 +00:00
|
|
|
vec3_t shadecolor; // Ender (Extend) Colormod
|
|
|
|
float modelalpha; // Ender (Extend) Alpha
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-09-09 19:37:07 +00:00
|
|
|
void R_MarkLeaves (void);
|
2001-05-13 00:28:50 +00:00
|
|
|
|
2001-10-23 17:20:56 +00:00
|
|
|
void R_DrawAliasModel (entity_t *e, qboolean cull);
|
|
|
|
void R_DrawSpriteModel (entity_t *e);
|
2001-08-22 11:00:25 +00:00
|
|
|
|
2001-10-30 19:58:01 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
2001-05-14 06:47:38 +00:00
|
|
|
glrmain_init (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-10-02 00:01:05 +00:00
|
|
|
gldepthmin = 0;
|
|
|
|
gldepthmax = 1;
|
|
|
|
qfglDepthFunc (GL_LEQUAL);
|
|
|
|
qfglDepthRange (gldepthmin, gldepthmax);
|
2001-05-14 06:47:38 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-09-04 10:32:51 +00:00
|
|
|
inline void
|
2001-02-26 06:48:02 +00:00
|
|
|
R_RotateForEntity (entity_t *e)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglTranslatef (e->origin[0], e->origin[1], e->origin[2]);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglRotatef (e->angles[1], 0, 0, 1);
|
|
|
|
qfglRotatef (-e->angles[0], 0, 1, 0);
|
2001-02-26 06:48:02 +00:00
|
|
|
// ZOID: fixed z angle
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglRotatef (e->angles[2], 1, 0, 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-05-14 06:47:38 +00:00
|
|
|
/*
|
|
|
|
R_ShowNearestLoc
|
|
|
|
|
|
|
|
Display the nearest symbolic location (.loc files)
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
R_ShowNearestLoc (void)
|
|
|
|
{
|
2001-09-09 19:37:07 +00:00
|
|
|
dlight_t *dl;
|
|
|
|
location_t *nearloc;
|
|
|
|
vec3_t trueloc;
|
2001-05-14 06:47:38 +00:00
|
|
|
|
|
|
|
if (r_drawentities->int_val)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nearloc = locs_find (r_origin);
|
|
|
|
|
|
|
|
if (nearloc) {
|
2001-05-20 05:42:52 +00:00
|
|
|
dl = R_AllocDlight (4096);
|
2001-05-14 06:47:38 +00:00
|
|
|
VectorCopy (nearloc->loc, dl->origin);
|
|
|
|
dl->radius = 200;
|
2001-05-20 03:54:55 +00:00
|
|
|
dl->die = r_realtime + 0.1;
|
2001-05-14 06:47:38 +00:00
|
|
|
dl->color[0] = 0;
|
|
|
|
dl->color[1] = 1;
|
|
|
|
dl->color[2] = 0;
|
|
|
|
|
|
|
|
VectorCopy (nearloc->loc, trueloc);
|
|
|
|
R_RunSpikeEffect (trueloc, 7);
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-05-14 06:47:38 +00:00
|
|
|
/*
|
|
|
|
R_DrawEntitiesOnList
|
|
|
|
|
|
|
|
Draw all the entities we have information on.
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
static void
|
|
|
|
R_DrawEntitiesOnList (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-09-09 19:37:07 +00:00
|
|
|
int i;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-14 06:47:38 +00:00
|
|
|
if (!r_drawentities->int_val) {
|
|
|
|
R_ShowNearestLoc();
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
2001-05-14 06:47:38 +00:00
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// LordHavoc: split into 3 loops to simplify state changes
|
2001-05-20 02:39:56 +00:00
|
|
|
for (i = 0; i < r_numvisedicts; i++) {
|
|
|
|
if (r_visedicts[i]->model->type != mod_brush)
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
2001-05-20 02:39:56 +00:00
|
|
|
currententity = r_visedicts[i];
|
2001-05-18 22:33:35 +00:00
|
|
|
modelalpha = currententity->alpha;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
R_DrawBrushModel (currententity);
|
|
|
|
}
|
|
|
|
|
2001-05-20 02:39:56 +00:00
|
|
|
for (i = 0; i < r_numvisedicts; i++) {
|
|
|
|
if (r_visedicts[i]->model->type != mod_alias)
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
2001-05-20 02:39:56 +00:00
|
|
|
currententity = r_visedicts[i];
|
2001-05-18 22:33:35 +00:00
|
|
|
modelalpha = currententity->alpha;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-21 00:22:35 +00:00
|
|
|
if (currententity == r_player_entity)
|
2001-02-19 21:15:25 +00:00
|
|
|
currententity->angles[PITCH] *= 0.3;
|
|
|
|
|
2001-06-24 09:25:55 +00:00
|
|
|
R_DrawAliasModel (currententity, true);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-10-30 19:58:01 +00:00
|
|
|
qfglColor3ubv (color_white);
|
2001-10-02 01:48:51 +00:00
|
|
|
qfglEnable (GL_ALPHA_TEST);
|
2001-05-20 02:39:56 +00:00
|
|
|
for (i = 0; i < r_numvisedicts; i++) {
|
|
|
|
if (r_visedicts[i]->model->type != mod_sprite)
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
2001-05-20 02:39:56 +00:00
|
|
|
currententity = r_visedicts[i];
|
2001-05-18 22:33:35 +00:00
|
|
|
modelalpha = currententity->alpha;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
R_DrawSpriteModel (currententity);
|
|
|
|
}
|
2001-10-02 01:48:51 +00:00
|
|
|
qfglDisable (GL_ALPHA_TEST);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static void
|
|
|
|
R_DrawViewModel (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-05-21 00:22:35 +00:00
|
|
|
currententity = r_view_model;
|
|
|
|
if (r_inhibit_viewmodel
|
|
|
|
|| !r_drawviewmodel->int_val
|
2001-05-15 03:27:55 +00:00
|
|
|
|| envmap
|
|
|
|
|| !r_drawentities->int_val
|
2001-05-21 00:22:35 +00:00
|
|
|
|| !currententity->model)
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
|
2001-05-18 22:33:35 +00:00
|
|
|
// this is a HACK! --KB
|
|
|
|
modelalpha = currententity->alpha;
|
2001-05-14 06:47:38 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// hack the depth range to prevent view model from poking into walls
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglDepthRange (gldepthmin, gldepthmin + 0.3 * (gldepthmax - gldepthmin));
|
2001-06-24 09:25:55 +00:00
|
|
|
R_DrawAliasModel (currententity, false);
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglDepthRange (gldepthmin, gldepthmax);
|
2001-08-30 18:24:19 +00:00
|
|
|
qfglColor3ubv (color_white);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-09-04 10:32:51 +00:00
|
|
|
inline static int
|
2001-02-26 06:48:02 +00:00
|
|
|
SignbitsForPlane (mplane_t *out)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-09-09 19:37:07 +00:00
|
|
|
int bits, j;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// for fast box on planeside test
|
|
|
|
|
|
|
|
bits = 0;
|
2001-02-26 06:48:02 +00:00
|
|
|
for (j = 0; j < 3; j++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (out->normal[j] < 0)
|
2001-02-26 06:48:02 +00:00
|
|
|
bits |= 1 << j;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
return bits;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static void
|
|
|
|
R_SetFrustum (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
if (r_refdef.fov_x == 90) {
|
2001-02-19 21:15:25 +00:00
|
|
|
// front side is visible
|
|
|
|
VectorAdd (vpn, vright, frustum[0].normal);
|
|
|
|
VectorSubtract (vpn, vright, frustum[1].normal);
|
|
|
|
|
|
|
|
VectorAdd (vpn, vup, frustum[2].normal);
|
|
|
|
VectorSubtract (vpn, vup, frustum[3].normal);
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
// rotate VPN right by FOV_X/2 degrees
|
2001-02-26 06:48:02 +00:00
|
|
|
RotatePointAroundVector (frustum[0].normal, vup, vpn,
|
|
|
|
-(90 - r_refdef.fov_x / 2));
|
2001-02-19 21:15:25 +00:00
|
|
|
// rotate VPN left by FOV_X/2 degrees
|
2001-02-26 06:48:02 +00:00
|
|
|
RotatePointAroundVector (frustum[1].normal, vup, vpn,
|
|
|
|
90 - r_refdef.fov_x / 2);
|
2001-02-19 21:15:25 +00:00
|
|
|
// rotate VPN up by FOV_X/2 degrees
|
2001-02-26 06:48:02 +00:00
|
|
|
RotatePointAroundVector (frustum[2].normal, vright, vpn,
|
|
|
|
90 - r_refdef.fov_y / 2);
|
2001-02-19 21:15:25 +00:00
|
|
|
// rotate VPN down by FOV_X/2 degrees
|
2001-02-26 06:48:02 +00:00
|
|
|
RotatePointAroundVector (frustum[3].normal, vright, vpn,
|
|
|
|
-(90 - r_refdef.fov_y / 2));
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (i = 0; i < 4; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
frustum[i].type = PLANE_ANYZ;
|
|
|
|
frustum[i].dist = DotProduct (r_origin, frustum[i].normal);
|
|
|
|
frustum[i].signbits = SignbitsForPlane (&frustum[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-10 06:01:11 +00:00
|
|
|
void
|
2001-02-26 06:48:02 +00:00
|
|
|
R_SetupFrame (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
R_AnimateLight ();
|
|
|
|
|
|
|
|
r_framecount++;
|
|
|
|
|
2001-05-14 06:47:38 +00:00
|
|
|
// build the transformation matrix for the given view angles
|
2001-02-19 21:15:25 +00:00
|
|
|
VectorCopy (r_refdef.vieworg, r_origin);
|
|
|
|
|
|
|
|
AngleVectors (r_refdef.viewangles, vpn, vright, vup);
|
|
|
|
|
2001-05-14 06:47:38 +00:00
|
|
|
// current viewleaf
|
2001-02-19 21:15:25 +00:00
|
|
|
r_oldviewleaf = r_viewleaf;
|
2001-05-20 04:25:36 +00:00
|
|
|
r_viewleaf = Mod_PointInLeaf (r_origin, r_worldentity.model);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
V_SetContentsColor (r_viewleaf->contents);
|
|
|
|
|
|
|
|
r_cache_thrash = false;
|
|
|
|
|
|
|
|
c_brush_polys = 0;
|
|
|
|
c_alias_polys = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static void
|
|
|
|
MYgluPerspective (GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-09-09 19:37:07 +00:00
|
|
|
GLdouble xmin, xmax, ymin, ymax;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
ymax = zNear * tan (fovy * M_PI / 360.0);
|
2001-02-19 21:15:25 +00:00
|
|
|
ymin = -ymax;
|
|
|
|
|
|
|
|
xmin = ymin * aspect;
|
|
|
|
xmax = ymax * aspect;
|
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglFrustum (xmin, xmax, ymin, ymax, zNear, zFar);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static void
|
|
|
|
R_SetupGL (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-05-20 22:02:44 +00:00
|
|
|
float screenaspect;
|
|
|
|
int x, x2, y2, y, w, h;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// set up viewpoint
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglMatrixMode (GL_PROJECTION);
|
|
|
|
qfglLoadIdentity ();
|
2001-02-26 06:48:02 +00:00
|
|
|
x = r_refdef.vrect.x * glwidth / vid.width;
|
|
|
|
x2 = (r_refdef.vrect.x + r_refdef.vrect.width) * glwidth / vid.width;
|
|
|
|
y = (vid.height - r_refdef.vrect.y) * glheight / vid.height;
|
2001-05-20 22:02:44 +00:00
|
|
|
y2 = (vid.height - (r_refdef.vrect.y + r_refdef.vrect.height)) * glheight
|
|
|
|
/ vid.height;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// fudge around because of frac screen scale
|
|
|
|
if (x > 0)
|
|
|
|
x--;
|
|
|
|
if (x2 < glwidth)
|
|
|
|
x2++;
|
|
|
|
if (y2 < 0)
|
|
|
|
y2--;
|
|
|
|
if (y < glheight)
|
|
|
|
y++;
|
|
|
|
|
|
|
|
w = x2 - x;
|
|
|
|
h = y - y2;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (envmap) {
|
2001-02-19 21:15:25 +00:00
|
|
|
x = y2 = 0;
|
|
|
|
w = h = 256;
|
|
|
|
}
|
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglViewport (glx + x, gly + y2, w, h);
|
2001-02-26 06:48:02 +00:00
|
|
|
screenaspect = (float) r_refdef.vrect.width / r_refdef.vrect.height;
|
|
|
|
MYgluPerspective (r_refdef.fov_y, screenaspect, 4, 4096);
|
|
|
|
|
|
|
|
if (mirror) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (mirror_plane->normal[2])
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglScalef (1, -1, 1);
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglScalef (-1, 1, 1);
|
|
|
|
qfglCullFace (GL_BACK);
|
2001-02-26 06:48:02 +00:00
|
|
|
} else
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglCullFace (GL_FRONT);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglMatrixMode (GL_MODELVIEW);
|
|
|
|
qfglLoadIdentity ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglRotatef (-90, 1, 0, 0); // put Z going up
|
|
|
|
qfglRotatef (90, 0, 0, 1); // put Z going up
|
|
|
|
qfglRotatef (-r_refdef.viewangles[2], 1, 0, 0);
|
|
|
|
qfglRotatef (-r_refdef.viewangles[0], 0, 1, 0);
|
|
|
|
qfglRotatef (-r_refdef.viewangles[1], 0, 0, 1);
|
|
|
|
qfglTranslatef (-r_refdef.vieworg[0], -r_refdef.vieworg[1],
|
2001-02-26 06:48:02 +00:00
|
|
|
-r_refdef.vieworg[2]);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglGetFloatv (GL_MODELVIEW_MATRIX, r_world_matrix);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// set drawing parms
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglEnable (GL_CULL_FACE);
|
|
|
|
qfglDisable (GL_ALPHA_TEST);
|
|
|
|
qfglAlphaFunc (GL_GREATER, 0.5);
|
|
|
|
qfglEnable (GL_DEPTH_TEST);
|
2001-05-14 06:47:38 +00:00
|
|
|
if (gl_dlight_smooth->int_val)
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglShadeModel (GL_SMOOTH);
|
2001-05-14 06:47:38 +00:00
|
|
|
else
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglShadeModel (GL_FLAT);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static void
|
|
|
|
R_Clear (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
if (gl_clear->int_val)
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglClear (GL_DEPTH_BUFFER_BIT);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-05-14 20:49:18 +00:00
|
|
|
void
|
|
|
|
R_RenderScene (void)
|
|
|
|
{
|
2001-05-22 06:00:38 +00:00
|
|
|
if (r_timegraph->int_val || r_speeds->int_val || r_dspeeds->int_val)
|
|
|
|
r_time1 = Sys_DoubleTime ();
|
|
|
|
|
2001-05-14 20:49:18 +00:00
|
|
|
R_SetupFrame ();
|
|
|
|
R_SetFrustum ();
|
|
|
|
R_SetupGL ();
|
|
|
|
R_MarkLeaves (); // done here so we know if we're in water
|
2001-08-05 04:01:45 +00:00
|
|
|
R_PushDlights (vec3_origin);
|
2001-05-14 20:49:18 +00:00
|
|
|
R_DrawWorld (); // adds static entities to the list
|
|
|
|
S_ExtraUpdate (); // don't let sound get messed up if going slow
|
|
|
|
R_DrawEntitiesOnList ();
|
|
|
|
R_RenderDlights ();
|
|
|
|
}
|
2001-05-13 00:28:50 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
R_Mirror (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-09-09 19:37:07 +00:00
|
|
|
float d;
|
|
|
|
entity_t **ent;
|
|
|
|
msurface_t *s;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!mirror)
|
|
|
|
return;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
memcpy (r_base_world_matrix, r_world_matrix, sizeof (r_base_world_matrix));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-19 20:57:29 +00:00
|
|
|
d = DotProduct (r_refdef.vieworg, mirror_plane->normal) -
|
|
|
|
mirror_plane->dist;
|
2001-08-22 11:00:25 +00:00
|
|
|
VectorMA (r_refdef.vieworg, -2 * d, mirror_plane->normal,
|
|
|
|
r_refdef.vieworg);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
d = DotProduct (vpn, mirror_plane->normal);
|
2001-02-26 06:48:02 +00:00
|
|
|
VectorMA (vpn, -2 * d, mirror_plane->normal, vpn);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
r_refdef.viewangles[0] = -asin (vpn[2]) / M_PI * 180;
|
|
|
|
r_refdef.viewangles[1] = atan2 (vpn[1], vpn[0]) / M_PI * 180;
|
2001-02-19 21:15:25 +00:00
|
|
|
r_refdef.viewangles[2] = -r_refdef.viewangles[2];
|
|
|
|
|
2001-05-20 02:39:56 +00:00
|
|
|
ent = R_NewEntity();
|
2001-05-15 21:34:54 +00:00
|
|
|
if (ent)
|
2001-05-21 00:22:35 +00:00
|
|
|
*ent = r_player_entity;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
gldepthmin = 0.5;
|
|
|
|
gldepthmax = 1;
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglDepthRange (gldepthmin, gldepthmax);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
R_RenderScene ();
|
|
|
|
R_DrawWaterSurfaces ();
|
|
|
|
|
|
|
|
gldepthmin = 0;
|
2001-10-02 00:01:05 +00:00
|
|
|
gldepthmax = 1;
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglDepthRange (gldepthmin, gldepthmax);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// blend on top
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglMatrixMode (GL_PROJECTION);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (mirror_plane->normal[2])
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglScalef (1, -1, 1);
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglScalef (-1, 1, 1);
|
|
|
|
qfglCullFace (GL_FRONT);
|
|
|
|
qfglMatrixMode (GL_MODELVIEW);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-06-26 02:26:46 +00:00
|
|
|
qfglLoadMatrixf (r_base_world_matrix);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-30 18:24:19 +00:00
|
|
|
color_white[2] = r_mirroralpha->value * 255;
|
|
|
|
qfglColor4ubv (color_white);
|
2001-05-20 04:25:36 +00:00
|
|
|
s = r_worldentity.model->textures[mirrortexturenum]->texturechain;
|
2001-02-26 06:48:02 +00:00
|
|
|
for (; s; s = s->texturechain)
|
2001-02-19 21:15:25 +00:00
|
|
|
R_RenderBrushPoly (s);
|
2001-05-20 04:25:36 +00:00
|
|
|
r_worldentity.model->textures[mirrortexturenum]->texturechain = NULL;
|
2001-08-30 18:24:19 +00:00
|
|
|
qfglColor3ubv (color_white);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-05-13 00:28:50 +00:00
|
|
|
R_RenderView
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-13 00:28:50 +00:00
|
|
|
r_refdef must be set before the first call
|
2001-02-19 21:15:25 +00:00
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
R_RenderView (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
if (r_norefresh->int_val)
|
|
|
|
return;
|
2001-05-20 04:25:36 +00:00
|
|
|
if (!r_worldentity.model)
|
2001-02-19 21:15:25 +00:00
|
|
|
Sys_Error ("R_RenderView: NULL worldmodel");
|
|
|
|
|
|
|
|
mirror = false;
|
|
|
|
|
|
|
|
R_Clear ();
|
|
|
|
|
|
|
|
// render normal view
|
2001-05-14 20:49:18 +00:00
|
|
|
R_RenderScene ();
|
2001-10-02 06:13:22 +00:00
|
|
|
R_DrawViewModel ();
|
2001-02-19 21:15:25 +00:00
|
|
|
R_DrawWaterSurfaces ();
|
2001-05-13 00:28:50 +00:00
|
|
|
R_UpdateFires ();
|
|
|
|
R_DrawParticles ();
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// render mirror view
|
2001-05-14 20:49:18 +00:00
|
|
|
R_Mirror ();
|
2001-08-30 18:24:19 +00:00
|
|
|
|
|
|
|
if (r_timegraph->int_val)
|
|
|
|
R_TimeGraph ();
|
|
|
|
if (r_zgraph->int_val)
|
|
|
|
R_ZGraph ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-06-24 09:25:55 +00:00
|
|
|
|
|
|
|
#if 0
|
2001-08-26 17:13:33 +00:00
|
|
|
qboolean
|
|
|
|
R_CullBlocked (vec3_t mins, vec3_t maxs, vec3_t org)
|
2001-06-24 09:25:55 +00:00
|
|
|
{
|
2001-09-09 19:37:07 +00:00
|
|
|
float rad;
|
|
|
|
static struct trace_t trace;
|
|
|
|
vec3_t point;
|
2001-06-24 09:25:55 +00:00
|
|
|
|
|
|
|
if (!gl_occlusion->int_val)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Check the origin first
|
|
|
|
if ( Mod_PointInLeaf(org, cl.worldmodel)->contents != CONTENTS_SOLID)
|
|
|
|
{
|
2001-08-22 11:00:25 +00:00
|
|
|
if (SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1,
|
|
|
|
r_refdef.vieworg, org, &trace))
|
2001-06-24 09:25:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2001-10-30 19:58:01 +00:00
|
|
|
rad = sqrt ((maxs[0] - org[0]) * (maxs[0] - org[0]) +
|
|
|
|
(maxs[1] - org[1]) * (maxs[1] - org[1]) +
|
|
|
|
(maxs[2] - org[2]) * (maxs[2] - org[2]));
|
2001-06-24 09:25:55 +00:00
|
|
|
|
|
|
|
// Check a few points on the bounding sphere to catch rotating objects
|
|
|
|
// Raise the origin a bit to catch droptofloor models
|
|
|
|
point[0] = org[0]; point[1] = org[1]+rad; point[2] = org[2]+4;
|
|
|
|
if ( Mod_PointInLeaf(point, cl.worldmodel)->contents != CONTENTS_SOLID)
|
|
|
|
{
|
2001-08-22 11:00:25 +00:00
|
|
|
if (SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1,
|
|
|
|
r_refdef.vieworg, point, &trace))
|
2001-06-24 09:25:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
point[0] = org[0]+rad; point[1] = org[1]; point[2] = org[2]+4;
|
|
|
|
if ( Mod_PointInLeaf(point, cl.worldmodel)->contents != CONTENTS_SOLID)
|
|
|
|
{
|
2001-08-22 11:00:25 +00:00
|
|
|
if (SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1,
|
|
|
|
r_refdef.vieworg, point, &trace))
|
2001-06-24 09:25:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
point[0] = org[0]; point[1] = org[1]-rad; point[2] = org[2]+4;
|
|
|
|
if ( Mod_PointInLeaf(point, cl.worldmodel)->contents != CONTENTS_SOLID)
|
|
|
|
{
|
2001-08-22 11:00:25 +00:00
|
|
|
if (SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1,
|
|
|
|
r_refdef.vieworg, point, &trace))
|
2001-06-24 09:25:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
point[0] = org[0]-rad; point[1] = org[1]; point[2] = org[2]+4;
|
|
|
|
if ( Mod_PointInLeaf(point, cl.worldmodel)->contents != CONTENTS_SOLID)
|
|
|
|
{
|
2001-08-22 11:00:25 +00:00
|
|
|
if (SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1,
|
|
|
|
r_refdef.vieworg, point, &trace))
|
2001-06-24 09:25:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2001-08-22 11:00:25 +00:00
|
|
|
// Check the poles of the sphere (can catch ents on ledges that would
|
|
|
|
// otherwise be missed)
|
2001-06-24 09:25:55 +00:00
|
|
|
point[0] = org[0]; point[1] = org[1]; point[2] = org[2]+rad;
|
|
|
|
if ( Mod_PointInLeaf(point, cl.worldmodel)->contents != CONTENTS_SOLID)
|
|
|
|
{
|
2001-08-22 11:00:25 +00:00
|
|
|
if (SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1,
|
|
|
|
r_refdef.vieworg, point, &trace))
|
2001-06-24 09:25:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
point[0] = org[0]; point[1] = org[1]; point[2] = org[2]-rad;
|
|
|
|
if ( Mod_PointInLeaf(point, cl.worldmodel)->contents != CONTENTS_SOLID)
|
|
|
|
{
|
2001-08-22 11:00:25 +00:00
|
|
|
if (SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1,
|
|
|
|
r_refdef.vieworg, point, &trace))
|
2001-06-24 09:25:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the corners...
|
|
|
|
if ( Mod_PointInLeaf(maxs, cl.worldmodel)->contents != CONTENTS_SOLID)
|
|
|
|
{
|
2001-08-22 11:00:25 +00:00
|
|
|
if (SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1,
|
|
|
|
r_refdef.vieworg, maxs, &trace))
|
2001-06-24 09:25:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
point[0] = mins[0]; point[1] = maxs[1]; point[2] = maxs[2];
|
|
|
|
if ( Mod_PointInLeaf(point, cl.worldmodel)->contents != CONTENTS_SOLID)
|
|
|
|
{
|
2001-08-22 11:00:25 +00:00
|
|
|
if (SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1,
|
|
|
|
r_refdef.vieworg, point, &trace))
|
2001-06-24 09:25:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
point[0] = mins[0]; point[1] = mins[1]; point[2] = maxs[2];
|
|
|
|
if ( Mod_PointInLeaf(point, cl.worldmodel)->contents != CONTENTS_SOLID)
|
|
|
|
{
|
2001-08-22 11:00:25 +00:00
|
|
|
if (SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1,
|
|
|
|
r_refdef.vieworg, point, &trace))
|
2001-06-24 09:25:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
point[0] = maxs[0]; point[1] = mins[1]; point[2] = maxs[2];
|
|
|
|
if ( Mod_PointInLeaf(point, cl.worldmodel)->contents != CONTENTS_SOLID)
|
|
|
|
{
|
2001-08-22 11:00:25 +00:00
|
|
|
if (SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1,
|
|
|
|
r_refdef.vieworg, point, &trace))
|
2001-06-24 09:25:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ( Mod_PointInLeaf(mins, cl.worldmodel)->contents != CONTENTS_SOLID)
|
|
|
|
{
|
2001-08-22 11:00:25 +00:00
|
|
|
if (SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1,
|
|
|
|
r_refdef.vieworg, mins, &trace))
|
2001-06-24 09:25:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
point[0] = mins[0]; point[1] = maxs[1]; point[2] = mins[2]+4;
|
|
|
|
if ( Mod_PointInLeaf(point, cl.worldmodel)->contents != CONTENTS_SOLID)
|
|
|
|
{
|
2001-08-22 11:00:25 +00:00
|
|
|
if (SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1,
|
|
|
|
r_refdef.vieworg, point, &trace))
|
2001-06-24 09:25:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
point[0] = maxs[0]; point[1] = mins[1]; point[2] = mins[2]+4;
|
|
|
|
if ( Mod_PointInLeaf(point, cl.worldmodel)->contents != CONTENTS_SOLID)
|
|
|
|
{
|
2001-08-22 11:00:25 +00:00
|
|
|
if (SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1,
|
|
|
|
r_refdef.vieworg, point, &trace))
|
2001-06-24 09:25:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
point[0] = maxs[0]; point[1] = maxs[1]; point[2] = mins[2]+4;
|
|
|
|
if ( Mod_PointInLeaf(point, cl.worldmodel)->contents != CONTENTS_SOLID)
|
|
|
|
{
|
2001-08-22 11:00:25 +00:00
|
|
|
if (SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1,
|
|
|
|
r_refdef.vieworg, point, &trace))
|
2001-06-24 09:25:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Model is blocked (probably)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|