gl_fires/r_firecolor patch. Software client still builds and runs correctly,

but as I don't have GL at work, I have no idea if gl client still works, or if
rocket trails work (default to off). This is mostly a blind patch taking the
code from oldtree to newtree.
This commit is contained in:
Bill Currie 2000-06-19 22:15:18 +00:00
parent 6024c0ce7f
commit 1246b26046
6 changed files with 231 additions and 3 deletions

View file

@ -148,7 +148,8 @@ typedef struct
float die; // stop lighting after this time
float decay; // drop this each second
float minlight; // don't add when contributing less
float color[3]; // Don't use alpha --KB
float _color[3]; // Don't use alpha --KB
float *color;
} dlight_t;
typedef struct

View file

@ -250,6 +250,24 @@ void GL_DisableMultitexture (void);
void GL_EnableMultitexture (void);
void GL_SelectTexture (GLenum target);
//
// gl_rpart.c
//
typedef struct {
int key; // allows reusability
vec3_t origin, owner;
float size;
float die, decay; // duration settings
float minlight; // lighting threshold
float _color[4]; // RGBA
float *color;
} fire_t;
void R_AddFire (vec3_t, vec3_t, entity_t *ent);
fire_t *R_AllocFire (int);
void R_DrawFire (fire_t *);
void R_UpdateFires (void);
//
// gl_warp.c
//

View file

@ -79,6 +79,7 @@ dlight_t *CL_AllocDlight (int key)
{
memset (dl, 0, sizeof(*dl));
dl->key = key;
dl->color = dl->_color;
return dl;
}
}
@ -92,6 +93,7 @@ dlight_t *CL_AllocDlight (int key)
{
memset (dl, 0, sizeof(*dl));
dl->key = key;
dl->color = dl->_color;
return dl;
}
}
@ -99,6 +101,7 @@ dlight_t *CL_AllocDlight (int key)
dl = &cl_dlights[0];
memset (dl, 0, sizeof(*dl));
dl->key = key;
dl->color = dl->_color;
return dl;
}

View file

@ -58,6 +58,7 @@
#define MAX_PARTICLES 2048 // default max # of particles at one
// time
#define MAX_FIRES 128 // rocket flames
#define ABSOLUTE_MIN_PARTICLES 512 // no fewer than this no matter what's
// on the command line
@ -72,6 +73,7 @@ int r_numparticles;
vec3_t r_pright, r_pup, r_ppn;
fire_t r_firs[MAX_FIRES];
/*
===============
@ -435,6 +437,7 @@ void R_RocketTrail (vec3_t start, vec3_t end, int type)
}
else if (type == 0)
{ // rocket trail
R_AddFire (start, end, ent);
p->ramp = (rand()&3);
p->color = ramp3[(int)p->ramp];
p->type = pt_fire;
@ -627,3 +630,199 @@ void R_DrawParticles (void)
glEnable(GL_ALPHA_TEST);
}
/*
R_AddFire
Nifty ball of fire GL effect. Kinda a meshing of the dlight and
particle engine code.
*/
float r_firecolor_flame[4]={0.9,0.7,0.3,1.0};
float r_firecolor_light[4]={0.9,0.7,0.3,0}; // alpha not used
void
R_AddFire (vec3_t start, vec3_t end, entity_t *ent)
{
float len;
fire_t *f;
dlight_t *dl;
vec3_t vec;
int key;
if (!gl_fires->value)
return;
VectorSubtract (end, start, vec);
len = VectorNormalize (vec);
key = ent-cl_entities+1;
if (len)
{
f = R_AllocFire (key);
VectorCopy (end, f->origin);
VectorCopy (start, f->owner);
f->size = 20;
f->die = cl.time + 0.5;
f->decay = -1;
f->color=r_firecolor_flame;
dl = CL_AllocDlight (key);
VectorCopy (end, dl->origin);
dl->radius = 200;
dl->die = cl.time + 0.5;
dl->color=r_firecolor_light;
}
}
/*
R_AllocFire
Clears out and returns a new fireball
*/
fire_t *
R_AllocFire (int key)
{
int i;
fire_t *f;
if (key) // first try to find/reuse a keyed spot
{
f = r_fires;
for (i = 0; i < MAX_FIRES; i++, f++)
if (f->key == key)
{
memset (f, 0, sizeof(*f));
f->key = key;
f->color = f->_color;
return f;
}
}
f = r_fires; // no match, look for a free spot
for (i = 0; i < MAX_FIRES; i++, f++)
{
if (f->die < cl.time)
{
memset (f, 0, sizeof(*f));
f->key = key;
f->color = f->_color;
return f;
}
}
f = &r_fires[0];
memset (f, 0, sizeof(*f));
f->key = key;
f->color = f->_color;
return f;
}
/*
R_DrawFire
draws one fireball - probably never need to call this directly
*/
void
R_DrawFire (fire_t *f)
{
int i, j;
vec3_t vec,vec2;
float radius;
float *b_sin, *b_cos;
b_sin = bubble_sintable;
b_cos = bubble_costable;
radius = f->size + 0.35;
// figure out if we're inside the area of effect
VectorSubtract (f->origin, r_origin, vec);
if (Length (vec) < radius)
{
AddLightBlend (1, 0.5, 0, f->size * 0.0003); // we are
return;
}
// we're not - draw it
glBegin (GL_TRIANGLE_FAN);
glColor4fv (f->color);
for (i=0 ; i<3 ; i++)
vec[i] = f->origin[i] - vpn[i] * radius;
glVertex3fv (vec);
glColor3f (0.0, 0.0, 0.0);
// don't panic, this just draws a bubble...
for (i=16 ; i>=0 ; i--)
{
for (j=0 ; j<3 ; j++) {
vec[j] = f->origin[j] + (*b_cos * vright[j]
+ vup[j]*(*b_sin)) * radius;
vec2[j] = f->owner[j] + (*b_cos * vright[j]
+ vup[j]*(*b_sin)) * radius;
}
glVertex3fv (vec);
glVertex3fv (vec2);
b_sin++;
b_cos++;
}
glEnd ();
}
/*
R_UpdateFires
Draws each fireball in sequence
*/
void
R_UpdateFires (void)
{
int i;
fire_t *f;
if (!gl_fires->value)
return;
glDepthMask (0);
glDisable (GL_TEXTURE_2D);
glShadeModel (GL_SMOOTH);
glEnable (GL_BLEND);
glBlendFunc (GL_ONE, GL_ONE);
f = r_fires;
for (i = 0; i < MAX_FIRES; i++, f++)
{
if (f->die < cl.time || !f->size)
continue;
f->size += f->decay;
f->color[3] /= 2.0;
R_DrawFire (f);
}
glColor3f (1.0, 1.0, 1.0);
glDisable (GL_BLEND);
glEnable (GL_TEXTURE_2D);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDepthMask (1);
}
void
R_FireColor_f(void)
{
int i;
if (Cmd_Argc() == 1) {
Con_Printf ("r_firecolor %f %f %f %f\n",
r_firecolor_flame[0],
r_firecolor_flame[1],
r_firecolor_flame[2],
r_firecolor_flame[3]);
return;
}
if (Cmd_Argc() !=6) {
Con_Printf ("Usage r_firecolor R G B A\n");
return;
}
for (i=0; i<4; i++) {
r_firecolor_flame[i]=atof(Cmd_Argv(i+1));
r_firecolor_light[i]=r_firecolor_flame[i];
}
}

View file

@ -1023,7 +1023,7 @@ void R_RenderScene (void)
GL_DisableMultitexture();
R_RenderDlights ();
R_UpdateFires ();
R_DrawParticles ();
#ifdef GLTEST

View file

@ -57,8 +57,10 @@
#include "glquake.h"
qboolean VID_Is8bit(void);
extern void R_InitBubble();
void R_InitBubble();
void R_FireColor_f(void);
cvar_t *gl_fires;
qboolean allowskybox; // allow skyboxes? --KB
/*
@ -230,6 +232,8 @@ void R_Init (void)
Cmd_AddCommand ("pointfile", R_ReadPointFile_f);
Cmd_AddCommand ("loadsky", R_LoadSky_f);
Cmd_AddCommand ("r_firecolor", R_FireColor_f);
r_norefresh = Cvar_Get("r_norefresh", "0", CVAR_NONE, "None");
r_lightmap = Cvar_Get("r_lightmap", "0", CVAR_NONE, "None");
r_fullbright = Cvar_Get("r_fullbright", "0", CVAR_NONE, "None");
@ -258,6 +262,9 @@ void R_Init (void)
gl_playermip = Cvar_Get("gl_playermip", "0", CVAR_NONE, "None");
gl_nocolors = Cvar_Get("gl_nocolors", "0", CVAR_NONE, "None");
gl_fires = Cvar_Get ("gl_fires", "0", CVAR_ARCHIVE,
"Toggles lavaball and rocket fireballs");
gl_keeptjunctions = Cvar_Get("gl_keeptjunctions", "1", CVAR_NONE, "None");
gl_reporttjunctions = Cvar_Get("gl_reporttjunctions", "0", CVAR_NONE, "None");