Exemplo n.º 1
0
void R_DrawAliasShadows (entity_t **ents, int numents, void *meshbuffer)
{
    if (r_shadows.value > 0.01f)
    {
        int i;
        qbool stateset = false;
        byte shadecolor[4] = {0, 0, 0, 128};
//		extern int gl_stencilbits;

        for (i = 0; i < numents; i++)
        {
            entity_t *ent = ents[i];
            glmatrix eshadow;

            if (!(ent->model->flags & MOD_NOSHADOW))
            {
                aliasstate_t *state = &ent->aliasstate;
                aliashdr_t *hdr = Mod_Extradata (ent->model);
                float lheight = state->origin[2] - state->lightspot[2];

                if (!stateset)
                {
                    float *mesh = (float *) meshbuffer;

                    qglDepthMask (GL_FALSE);
                    qglEnable (GL_BLEND);
                    GL_TexEnv (GL_TEXTURE1_ARB, GL_TEXTURE_2D, GL_NONE);
                    GL_TexEnv (GL_TEXTURE0_ARB, GL_TEXTURE_2D, GL_NONE);
                    qglColor4f (0, 0, 0, r_shadows.value);
                    shadecolor[3] = BYTE_CLAMPF (r_shadows.value);

                    /*
                    if (gl_stencilbits)
                    {
                    	qglEnable (GL_STENCIL_TEST);
                    	qglStencilFunc (GL_EQUAL, 1, 2);
                    	qglStencilOp (GL_KEEP, GL_KEEP, GL_INCR);
                    }
                    */

                    GL_SetStreamSource (GLSTREAM_POSITION, 3, GL_FLOAT, sizeof (float) * 4, mesh);
                    GL_SetStreamSource (GLSTREAM_COLOR, 4, GL_UNSIGNED_BYTE, sizeof (float) * 4, &mesh[3]);
                    GL_SetStreamSource (GLSTREAM_TEXCOORD0, 0, GL_NONE, 0, NULL);
                    GL_SetStreamSource (GLSTREAM_TEXCOORD1, 0, GL_NONE, 0, NULL);
                    GL_SetStreamSource (GLSTREAM_TEXCOORD2, 0, GL_NONE, 0, NULL);

                    stateset = true;
                }

                GL_LoadMatrix (&eshadow, &r_world_matrix);

                if (state->origin[0] || state->origin[1] || state->origin[2])
                    GL_TranslateMatrix (&eshadow, state->origin[0], state->origin[1], state->origin[2]);

                GL_TranslateMatrix (&eshadow, 0, 0, -lheight);
                GL_MultiplyMatrix (&eshadow, &shadowmatrix, &eshadow);
                GL_TranslateMatrix (&eshadow, 0, 0, lheight);

                if (state->angles[1]) GL_RotateMatrix (&eshadow, state->angles[1], 0, 0, 1);

                GL_TranslateMatrix (&eshadow, hdr->scale_origin[0], hdr->scale_origin[1], hdr->scale_origin[2]);
                GL_ScaleMatrix (&eshadow, hdr->scale[0], hdr->scale[1], hdr->scale[2]);

                qglLoadMatrixf (eshadow.m16);

                R_DrawAliasShadow (ent, hdr, state, (float *) meshbuffer, (float *) shadecolor);
            }
        }

        if (stateset)
        {
            /*
            if (gl_stencilbits)
            	qglDisable (GL_STENCIL_TEST);
            */

            GL_TexEnv (GL_TEXTURE0_ARB, GL_TEXTURE_2D, GL_REPLACE);
            qglDisable (GL_BLEND);
            qglDepthMask (GL_TRUE);
            qglColor4f (1, 1, 1, 1);

            qglLoadMatrixf (r_world_matrix.m16);
        }
    }
}
Exemplo n.º 2
0
void
R_DrawAliasModel ( entity_t *e )
{
	int i;
	dmdl_t      *paliashdr;
	float an;
	vec3_t bbox [ 8 ];
	image_t     *skin;

	if ( !( e->flags & RF_WEAPONMODEL ) )
	{
		if ( R_CullAliasModel( bbox, e ) )
		{
			return;
		}
	}

	if ( e->flags & RF_WEAPONMODEL )
	{
		if ( gl_lefthand->value == 2 )
		{
			return;
		}
	}

	paliashdr = (dmdl_t *) currentmodel->extradata;

	/* get lighting information */
	if ( currententity->flags & ( RF_SHELL_HALF_DAM | RF_SHELL_GREEN | RF_SHELL_RED | RF_SHELL_BLUE | RF_SHELL_DOUBLE ) )
	{
		VectorClear( shadelight );

		if ( currententity->flags & RF_SHELL_HALF_DAM )
		{
			shadelight [ 0 ] = 0.56;
			shadelight [ 1 ] = 0.59;
			shadelight [ 2 ] = 0.45;
		}

		if ( currententity->flags & RF_SHELL_DOUBLE )
		{
			shadelight [ 0 ] = 0.9;
			shadelight [ 1 ] = 0.7;
		}

		if ( currententity->flags & RF_SHELL_RED )
		{
			shadelight [ 0 ] = 1.0;
		}

		if ( currententity->flags & RF_SHELL_GREEN )
		{
			shadelight [ 1 ] = 1.0;
		}

		if ( currententity->flags & RF_SHELL_BLUE )
		{
			shadelight [ 2 ] = 1.0;
		}
	}
	else if ( currententity->flags & RF_FULLBRIGHT )
	{
		for ( i = 0; i < 3; i++ )
		{
			shadelight [ i ] = 1.0;
		}
	}
	else
	{
		R_LightPoint( currententity->origin, shadelight );

		/* player lighting hack for communication back to server */
		if ( currententity->flags & RF_WEAPONMODEL )
		{
			/* pick the greatest component, which should be the same
			   as the mono value returned by software */
			if ( shadelight [ 0 ] > shadelight [ 1 ] )
			{
				if ( shadelight [ 0 ] > shadelight [ 2 ] )
				{
					gl_lightlevel->value = 150 * shadelight [ 0 ];
				}
				else
				{
					gl_lightlevel->value = 150 * shadelight [ 2 ];
				}
			}
			else
			{
				if ( shadelight [ 1 ] > shadelight [ 2 ] )
				{
					gl_lightlevel->value = 150 * shadelight [ 1 ];
				}
				else
				{
					gl_lightlevel->value = 150 * shadelight [ 2 ];
				}
			}
		}
	}

	if ( currententity->flags & RF_MINLIGHT )
	{
		for ( i = 0; i < 3; i++ )
		{
			if ( shadelight [ i ] > 0.1 )
			{
				break;
			}
		}

		if ( i == 3 )
		{
			shadelight [ 0 ] = 0.1;
			shadelight [ 1 ] = 0.1;
			shadelight [ 2 ] = 0.1;
		}
	}

	if ( currententity->flags & RF_GLOW )
	{
		/* bonus items will pulse with time */
		float scale;
		float min;

		scale = 0.1 * sin( r_newrefdef.time * 7 );

		for ( i = 0; i < 3; i++ )
		{
			min = shadelight [ i ] * 0.8;
			shadelight [ i ] += scale;

			if ( shadelight [ i ] < min )
			{
				shadelight [ i ] = min;
			}
		}
	}

	/* ir goggles color override */
	if ( r_newrefdef.rdflags & RDF_IRGOGGLES && currententity->flags & RF_IR_VISIBLE )
	{
		shadelight [ 0 ] = 1.0;
		shadelight [ 1 ] = 0.0;
		shadelight [ 2 ] = 0.0;
	}

	shadedots =
		r_avertexnormal_dots [ ( (int) ( currententity->angles [ 1 ] * ( SHADEDOT_QUANT / 360.0 ) ) ) & ( SHADEDOT_QUANT - 1 ) ];

	an = currententity->angles [ 1 ] / 180 * M_PI;
	shadevector [ 0 ] = cos( -an );
	shadevector [ 1 ] = sin( -an );
	shadevector [ 2 ] = 1;
	VectorNormalize( shadevector );

	/* locate the proper data */
	c_alias_polys += paliashdr->num_tris;

	/* draw all the triangles */
	if ( currententity->flags & RF_DEPTHHACK ) /* hack the depth range to prevent view model from poking into walls */
	{
		qglDepthRange( gldepthmin, gldepthmin + 0.3 * ( gldepthmax - gldepthmin ) );
	}

	if ( ( currententity->flags & RF_WEAPONMODEL ) && ( gl_lefthand->value == 1.0F ) )
	{
		extern void R_MYgluPerspective ( GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar );

		qglMatrixMode( GL_PROJECTION );
		qglPushMatrix();
		qglLoadIdentity();
		qglScalef( -1, 1, 1 );
		R_MYgluPerspective( r_newrefdef.fov_y, (float) r_newrefdef.width / r_newrefdef.height,  4,  4096 );
		qglMatrixMode( GL_MODELVIEW );

		qglCullFace( GL_BACK );
	}

	qglPushMatrix();
	e->angles [ PITCH ] = -e->angles [ PITCH ];
	R_RotateForEntity( e );
	e->angles [ PITCH ] = -e->angles [ PITCH ];

	/* select skin */
	if ( currententity->skin )
	{
		skin = currententity->skin; /* custom player skin */
	}
	else
	{
		if ( currententity->skinnum >= MAX_MD2SKINS )
		{
			skin = currentmodel->skins [ 0 ];
		}
		else
		{
			skin = currentmodel->skins [ currententity->skinnum ];

			if ( !skin )
			{
				skin = currentmodel->skins [ 0 ];
			}
		}
	}

	if ( !skin )
	{
		skin = r_notexture; /* fallback... */
	}

	R_Bind( skin->texnum );

	/* draw it */
	qglShadeModel( GL_SMOOTH );

	R_TexEnv( GL_MODULATE );

	if ( currententity->flags & RF_TRANSLUCENT )
	{
		qglEnable( GL_BLEND );
	}

	if ( ( currententity->frame >= paliashdr->num_frames ) ||
		 ( currententity->frame < 0 ) )
	{
		ri.Con_Printf( PRINT_ALL, "R_DrawAliasModel %s: no such frame %d\n",
				currentmodel->name, currententity->frame );
		currententity->frame = 0;
		currententity->oldframe = 0;
	}

	if ( ( currententity->oldframe >= paliashdr->num_frames ) ||
		 ( currententity->oldframe < 0 ) )
	{
		ri.Con_Printf( PRINT_ALL, "R_DrawAliasModel %s: no such oldframe %d\n",
				currentmodel->name, currententity->oldframe );
		currententity->frame = 0;
		currententity->oldframe = 0;
	}

	if ( !gl_lerpmodels->value )
	{
		currententity->backlerp = 0;
	}

	R_DrawAliasFrameLerp( paliashdr, currententity->backlerp );

	R_TexEnv( GL_REPLACE );
	qglShadeModel( GL_FLAT );

	qglPopMatrix();

	if ( ( currententity->flags & RF_WEAPONMODEL ) && ( gl_lefthand->value == 1.0F ) )
	{
		qglMatrixMode( GL_PROJECTION );
		qglPopMatrix();
		qglMatrixMode( GL_MODELVIEW );
		qglCullFace( GL_FRONT );
	}

	if ( currententity->flags & RF_TRANSLUCENT )
	{
		qglDisable( GL_BLEND );
	}

	if ( currententity->flags & RF_DEPTHHACK )
	{
		qglDepthRange( gldepthmin, gldepthmax );
	}

	if ( gl_shadows->value &&
		 !( currententity->flags & ( RF_TRANSLUCENT | RF_WEAPONMODEL | RF_NOSHADOW ) ) )
	{
		qglPushMatrix();

		/* don't rotate shadows on ungodly axes */
		qglTranslatef( e->origin [ 0 ], e->origin [ 1 ], e->origin [ 2 ] );
		qglRotatef( e->angles [ 1 ], 0, 0, 1 );

		qglDisable( GL_TEXTURE_2D );
		qglEnable( GL_BLEND );
		qglColor4f( 0, 0, 0, 0.5f );
		R_DrawAliasShadow( paliashdr, currententity->frame );
		qglEnable( GL_TEXTURE_2D );
		qglDisable( GL_BLEND );
		qglPopMatrix();
	}

	qglColor4f( 1, 1, 1, 1 );
}