Beispiel #1
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : frame - 
//			x - 
//			y - 
//			*prcSubRect - 
//-----------------------------------------------------------------------------
void CEngineSprite::DrawFrameOfSize( int frame, int x, int y, int iWidth, int iHeight, const wrect_t *prcSubRect )
{
	// FIXME: If we ever call this with AVIs, need to have it call GetTexCoordRange and make that work
	Assert( !IsAVI() && !IsBIK() );

	float fLeft = 0;
	float fRight = 1;
	float fTop = 0;
	float fBottom = 1;

	if ( prcSubRect )
	{
		AdjustSubRect( this, frame, &fLeft, &fRight, &fTop, &fBottom, &iWidth, &iHeight, prcSubRect );
	}

	if ( giScissorTest && !Scissor( x, y, iWidth, iHeight, fLeft, fTop, fRight, fBottom ) )
		return;

	SetFrame( frame );

	CMatRenderContextPtr pRenderContext( materials );
	IMesh* pMesh = pRenderContext->GetDynamicMesh( true, NULL, NULL, GetMaterial() );

	CMeshBuilder meshBuilder;
	meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );

	float color[3];
	GetHUDSpriteColor( color );
	
	meshBuilder.Color3fv( color );
	meshBuilder.TexCoord2f( 0, fLeft, fTop );
	meshBuilder.Position3f( x, y, 0.0f );
	meshBuilder.AdvanceVertex();

	meshBuilder.Color3fv( color );
	meshBuilder.TexCoord2f( 0, fRight, fTop );
	meshBuilder.Position3f( x + iWidth, y, 0.0f );
	meshBuilder.AdvanceVertex();

	meshBuilder.Color3fv( color );
	meshBuilder.TexCoord2f( 0, fRight, fBottom );
	meshBuilder.Position3f( x + iWidth, y + iHeight, 0.0f );
	meshBuilder.AdvanceVertex();

	meshBuilder.Color3fv( color );
	meshBuilder.TexCoord2f( 0, fLeft, fBottom );
	meshBuilder.Position3f( x, y + iHeight, 0.0f );
	meshBuilder.AdvanceVertex();

	meshBuilder.End();
	pMesh->Draw();
}
void Tri_DrawScaledSprite( HSPRITE hSprite, int frame, int r, int g, int b, int a, const RenderMode renderMode, const float flScale, ITriCoordFallback& callback, const wrect_t* pSpriteRect )
{
	if( hSprite == INVALID_HSPRITE )
	{
		gEngfuncs.Con_DPrintf( "Tri_DrawScaledSprite: hSprite is invalid!\n" );
		return;
	}

	const int iOrigWidth = gEngfuncs.pfnSPR_Width( hSprite, frame );
	const int iOrigHeight = gEngfuncs.pfnSPR_Height( hSprite, frame );

	wrect_t subRect;

	if( pSpriteRect )
	{
		subRect = *pSpriteRect;
	}
	else
	{
		subRect.left = subRect.top = 0;
		subRect.right = iOrigWidth;
		subRect.bottom = iOrigHeight;
	}

	int x, y;

	//Fallback on Software; no scaling or render mode support. - Solokiller
	if( !IEngineStudio.IsHardware() )
	{
		//Always scale 1. - Solokiller
		callback.Calculate( hSprite, frame, subRect, 1.0f, x, y );

		gEngfuncs.pfnSPR_Set( hSprite, r, g, b );

		gEngfuncs.pfnSPR_DrawHoles( frame, x, y, pSpriteRect );

		return;
	}

	wrect_t rect;

	//Trim a pixel border around it, since it blends. - Solokiller
	rect.left = subRect.left * flScale + ( flScale - 1 );
	rect.top = subRect.top * flScale + ( flScale - 1 );
	rect.right = subRect.right * flScale - ( flScale - 1 );
	rect.bottom = subRect.bottom * flScale - ( flScale - 1 );

	const int iWidth = iOrigWidth * flScale;
	const int iHeight = iOrigHeight * flScale;

	callback.Calculate( hSprite, frame, rect, flScale, x, y );

	model_t* pCrosshair = const_cast<model_t*>( gEngfuncs.GetSpritePointer( hSprite ) );

	auto TriAPI = gEngfuncs.pTriAPI;

	TriAPI->SpriteTexture( pCrosshair, frame );

	TriAPI->Color4fRendermode( r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f, renderMode );
	TriAPI->RenderMode( renderMode );

	float flLeft = 0;
	float flTop = 0;
	float flRight = 1.0;
	float flBottom = 1.0f;

	int iImgWidth = iWidth;
	int iImgHeight = iHeight;

	AdjustSubRect( iWidth, iHeight, &flLeft, &flRight, &flTop, &flBottom, &iImgWidth, &iImgHeight, &rect );

	TriAPI->Begin( TriangleMode::TRI_QUADS );

	TriAPI->TexCoord2f( flLeft, flTop );
	TriAPI->Vertex3f( x, y, 0 );

	TriAPI->TexCoord2f( flRight, flTop );
	TriAPI->Vertex3f( x + iImgWidth, y, 0 );

	TriAPI->TexCoord2f( flRight, flBottom );
	TriAPI->Vertex3f( x + iImgWidth, y + iImgHeight, 0 );

	TriAPI->TexCoord2f( flLeft, flBottom );
	TriAPI->Vertex3f( x, y + iImgHeight, 0 );

	TriAPI->End();
}