Replace glColor4f (1,1,1,1) with glColor4ubv (white), and similar for glColor3 and black. Cleanup and very minor speedup.

Also, use quads instead of tris for particles, and a far nicer dot texture.
This commit is contained in:
Ragnvald Maartmann-Moe IV 2002-01-06 22:46:23 +00:00
parent 345e6a9e15
commit 3f062fddcb
8 changed files with 93 additions and 71 deletions

View file

@ -263,9 +263,7 @@ void Draw_Fill (int x, int y, int w, int h, int c)
qglDisable (GL_TEXTURE_2D);
color.c = d_8to24table[c];
qglColor3f (color.v[0]/255.0,
color.v[1]/255.0,
color.v[2]/255.0);
qglColor3ubv (color.v);
qglBegin (GL_QUADS);
@ -275,7 +273,7 @@ void Draw_Fill (int x, int y, int w, int h, int c)
qglVertex2f (x, y+h);
qglEnd ();
qglColor3f (1,1,1);
qglColor3ubv (color_white);
qglEnable (GL_TEXTURE_2D);
}
@ -300,7 +298,7 @@ void Draw_FadeScreen (void)
qglVertex2f (0, vid.height);
qglEnd ();
qglColor4f (1,1,1,1);
qglColor4ubv (color_white);
qglEnable (GL_TEXTURE_2D);
qglDisable (GL_BLEND);
}

View file

@ -57,7 +57,7 @@ void R_RenderDlight (dlight_t *light)
for (i=0 ; i<3 ; i++)
v[i] = light->origin[i] - vpn[i]*rad;
qglVertex3fv (v);
qglColor3f (0,0,0);
qglColor3ubv (color_black);
for (i=16 ; i>=0 ; i--)
{
a = i/16.0 * M_PI*2;
@ -94,7 +94,7 @@ void R_RenderDlights (void)
for (i=0 ; i<r_newrefdef.num_dlights ; i++, l++)
R_RenderDlight (l);
qglColor3f (1,1,1);
qglColor3ubv (color_white);
qglDisable (GL_BLEND);
qglEnable (GL_TEXTURE_2D);
qglBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

View file

@ -51,6 +51,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// fall over
#define ROLL 2
extern byte color_white[4];
extern byte color_black[4];
#ifndef __VIDDEF_T
#define __VIDDEF_T

View file

@ -848,14 +848,12 @@ void R_DrawAliasModel (entity_t *e)
R_RotateForEntity (e);
qglDisable (GL_TEXTURE_2D);
qglEnable (GL_BLEND);
qglColor4f (0,0,0,0.5);
qglColor4ubv (color_black);
GL_DrawAliasShadow (paliashdr, currententity->frame );
qglEnable (GL_TEXTURE_2D);
qglDisable (GL_BLEND);
qglPopMatrix ();
}
#endif
qglColor4f (1,1,1,1);
qglColor4ubv (color_white);
}

View file

@ -52,6 +52,8 @@ int r_framecount; // used for dlight push checking
int c_brush_polys, c_alias_polys;
float v_blend[4]; // final blending color
byte color_white[4] = {255, 255, 255, 255};
byte color_black[4] = {0, 0, 0, 128};
void GL_Strings_f( void );
@ -226,10 +228,11 @@ void R_DrawSpriteModel (entity_t *e)
if ( e->flags & RF_TRANSLUCENT )
alpha = e->alpha;
if ( alpha != 1.0F )
qglEnable( GL_BLEND );
qglColor4f( 1, 1, 1, alpha );
if (alpha != 1.0F) {
qglEnable (GL_BLEND);
color_white[3] = alpha * 255;
}
qglColor4ubv (color_white);
GL_Bind(currentmodel->skins[e->frame]->texnum);
@ -267,10 +270,11 @@ void R_DrawSpriteModel (entity_t *e)
qglDisable (GL_ALPHA_TEST);
GL_TexEnv( GL_REPLACE );
if ( alpha != 1.0F )
qglDisable( GL_BLEND );
qglColor4f( 1, 1, 1, 1 );
if (alpha != 1.0F) {
qglDisable (GL_BLEND);
color_white[3] = 255;
}
qglColor4ubv (color_white);
}
//==================================================================================
@ -308,7 +312,7 @@ void R_DrawNullModel (void)
qglVertex3f (16*cos(i*M_PI/2), 16*sin(i*M_PI/2), 0);
qglEnd ();
qglColor3f (1,1,1);
qglColor3ubv (color_white);
qglPopMatrix ();
qglEnable (GL_TEXTURE_2D);
}
@ -413,7 +417,7 @@ void GL_DrawParticles (void)
{
const particle_t *p;
int i;
vec3_t up, right;
vec3_t up, right, up_right_scale, down_right_scale, VA[4];
float scale;
byte color[4];
@ -421,10 +425,7 @@ void GL_DrawParticles (void)
qglDepthMask( GL_FALSE ); // no z buffering
qglEnable( GL_BLEND );
GL_TexEnv( GL_MODULATE );
qglBegin( GL_TRIANGLES );
VectorScale (vup, 1.5, up);
VectorScale (vright, 1.5, right);
qglBegin( GL_QUADS );
for (p = r_newrefdef.particles, i = 0; i < r_newrefdef.num_particles;
i++, p++)
@ -435,32 +436,38 @@ void GL_DrawParticles (void)
( p->origin[2] - r_origin[2] ) * vpn[2];
if (scale < 20)
scale = 1;
scale = 0.75;
else
scale = 1 + scale * 0.004;
scale = 0.75 + scale * 0.003;
VectorScale (vup, scale, up);
VectorScale (vright, scale, right);
VectorAdd (up, right, up_right_scale);
VectorSubtract (right, up, down_right_scale);
VectorSubtract (p->origin, down_right_scale, VA[0]);
VectorAdd (p->origin, up_right_scale, VA[1]);
VectorAdd (p->origin, down_right_scale, VA[2]);
VectorSubtract (p->origin, up_right_scale, VA[3]);
*(int *)color = d_8to24table[p->color];
color[3] = p->alpha*255;
qglColor4ubv( color );
qglTexCoord2f( 0.0625, 0.0625 );
qglVertex3fv( p->origin );
qglTexCoord2f( 0.0, 0.0 );
qglVertex3fv( VA[0] );
qglTexCoord2f( 1.0625, 0.0625 );
qglVertex3f( p->origin[0] + up[0]*scale,
p->origin[1] + up[1]*scale,
p->origin[2] + up[2]*scale);
qglTexCoord2f( 1.0, 0.0 );
qglVertex3fv( VA[1] );
qglTexCoord2f( 0.0625, 1.0625 );
qglVertex3f( p->origin[0] + right[0]*scale,
p->origin[1] + right[1]*scale,
p->origin[2] + right[2]*scale);
qglTexCoord2f( 1.0, 1.0);
qglVertex3fv( VA[2] );
qglTexCoord2f( 0.0, 1.0 );
qglVertex3fv( VA[3] );
}
qglEnd ();
qglDisable( GL_BLEND );
qglColor4f( 1,1,1,1 );
qglColor4ubv (color_white);
qglDepthMask( 1 ); // back to normal Z buffering
GL_TexEnv( GL_REPLACE );
}
@ -497,7 +504,7 @@ void R_DrawParticles (void)
qglEnd();
qglDisable( GL_BLEND );
qglColor4f( 1.0F, 1.0F, 1.0F, 1.0F );
qglColor4ubv (color_white);
qglDepthMask( GL_TRUE );
qglEnable( GL_TEXTURE_2D );
@ -545,7 +552,7 @@ void R_PolyBlend (void)
qglEnable (GL_TEXTURE_2D);
qglEnable (GL_ALPHA_TEST);
qglColor4f(1,1,1,1);
qglColor4ubv (color_white);
}
//=======================================================================
@ -878,7 +885,7 @@ void R_SetGL2D (void)
qglDisable (GL_CULL_FACE);
qglDisable (GL_BLEND);
qglEnable (GL_ALPHA_TEST);
qglColor4f (1,1,1,1);
qglColor4ubv (color_white);
}
/*
static void GL_DrawColoredStereoLinePair( float r, float g, float b, float y )
@ -886,7 +893,7 @@ static void GL_DrawColoredStereoLinePair( float r, float g, float b, float y )
qglColor3f( r, g, b );
qglVertex2f( 0, y );
qglVertex2f( vid.width, y );
qglColor3f( 0, 0, 0 );
qglColor3ubv (color_black);
qglVertex2f( 0, y + 1 );
qglVertex2f( vid.width, y + 1 );
}
@ -1502,10 +1509,9 @@ void R_BeginFrame( float camera_separation )
qglDisable (GL_CULL_FACE);
qglDisable (GL_BLEND);
qglEnable (GL_ALPHA_TEST);
qglDisable (GL_TEXTURE_2D); //FIXME WTF? why do I need to toggle this?
qglDisable (GL_TEXTURE_2D); // FIXME: WTF? Why do I need to toggle this?
qglEnable (GL_TEXTURE_2D);
qglColor4f (1,1,1,1);
qglColor4ubv (color_white);
/*
** draw buffer stuff

View file

@ -38,6 +38,32 @@ byte dottexture[8][8] =
{0,0,0,0,0,0,0,0},
};
void InitDotParticleTexture (void)
{
byte data[32][32][4];
int x, y, dx2, dy, d, i;
for (x = 0; x < 32; x++) {
dx2 = x - 16;
dx2 *= dx2;
for (y = 0; y < 32; y++) {
dy = y - 16;
d = 255 - (dx2 + (dy * dy));
if (d <= 0) {
d = 0;
for (i = 0; i < 3; i++)
data[y][x][i] = 0;
} else
for (i = 0; i < 3; i++)
data[y][x][i] = 255;
data[y][x][3] = (byte) d;
}
}
r_particletexture = GL_LoadPic ("***particle***", (byte *)data, 32, 32,
it_sprite, 32);
}
void R_InitParticleTexture (void)
{
int x,y;
@ -46,20 +72,10 @@ void R_InitParticleTexture (void)
//
// particle texture
//
for (x=0 ; x<8 ; x++)
{
for (y=0 ; y<8 ; y++)
{
data[y][x][0] = 255;
data[y][x][1] = 255;
data[y][x][2] = 255;
data[y][x][3] = dottexture[x][y]*255;
}
}
r_particletexture = GL_LoadPic ("***particle***", (byte *)data, 8, 8, it_sprite, 32);
InitDotParticleTexture ();
//
// also use this for bad textures, but without alpha
// dot texture
//
for (x=0 ; x<8 ; x++)
{
@ -186,7 +202,7 @@ void GL_SetDefaultState( void )
qglDisable (GL_CULL_FACE);
qglDisable (GL_BLEND);
qglColor4f (1,1,1,1);
qglColor4ubv (color_white);
qglPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
qglShadeModel (GL_FLAT);

View file

@ -240,7 +240,7 @@ void R_DrawTriangleOutlines (void)
qglDisable (GL_TEXTURE_2D);
qglDisable (GL_DEPTH_TEST);
qglColor4f (1,1,1,1);
qglColor4ubv (color_white);
for (i=0 ; i<MAX_LIGHTMAPS ; i++)
{
@ -623,7 +623,7 @@ void R_DrawAlphaSurfaces (void)
}
GL_TexEnv( GL_REPLACE );
qglColor4f (1,1,1,1);
qglColor4ubv (color_white);
qglDisable (GL_BLEND);
r_alpha_surfaces = NULL;
@ -902,7 +902,9 @@ void R_DrawInlineBModel (void)
if ( currententity->flags & RF_TRANSLUCENT )
{
qglEnable (GL_BLEND);
qglColor4f (1,1,1,0.25);
color_white[3] = 64;
qglColor4ubv (color_white);
color_white[3] = 255;
GL_TexEnv( GL_MODULATE );
}
@ -946,7 +948,7 @@ void R_DrawInlineBModel (void)
else
{
qglDisable (GL_BLEND);
qglColor4f (1,1,1,1);
qglColor4ubv (color_white);
GL_TexEnv( GL_REPLACE );
}
}
@ -987,7 +989,7 @@ void R_DrawBrushModel (entity_t *e)
if (R_CullBox (mins, maxs))
return;
qglColor3f (1,1,1);
qglColor3ubv (color_white);
memset (gl_lms.lightmap_surfaces, 0, sizeof(gl_lms.lightmap_surfaces));
VectorSubtract (r_newrefdef.vieworg, e->origin, modelorg);
@ -1217,7 +1219,7 @@ void R_DrawWorld (void)
gl_state.currenttextures[0] = gl_state.currenttextures[1] = -1;
qglColor3f (1,1,1);
qglColor3ubv (color_white);
memset (gl_lms.lightmap_surfaces, 0, sizeof(gl_lms.lightmap_surfaces));
R_ClearSkyBox ();

View file

@ -566,7 +566,7 @@ void R_DrawSkyBox (void)
#if 0
qglEnable (GL_BLEND);
GL_TexEnv( GL_MODULATE );
qglColor4f (1,1,1,0.5);
qglColor4f (1.0, 1.0, 1.0, 0.5);
qglDisable (GL_DEPTH_TEST);
#endif
if (skyrotate)
@ -608,10 +608,10 @@ qglRotatef (r_newrefdef.time * skyrotate, skyaxis[0], skyaxis[1], skyaxis[2]);
}
qglPopMatrix ();
#if 0
glDisable (GL_BLEND);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glColor4f (1,1,1,0.5);
glEnable (GL_DEPTH_TEST);
qglDisable (GL_BLEND);
qglTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
qglColor4f (1.0, 1.0, 1.0, 0.5);
qglEnable (GL_DEPTH_TEST);
#endif
}