Portable Half-Life SDK. GoldSource and Xash3D. Crossplatform.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

255 lines
6.5 KiB

//========= Copyright (c) 1996-2002, Valve LLC, All rights reserved. ============
7 years ago
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
// Triangle rendering, if any
#include "hud.h"
#include "cl_util.h"
// Triangle rendering apis are in gEngfuncs.pTriAPI
#include "const.h"
#include "entity_state.h"
#include "cl_entity.h"
#include "triangleapi.h"
#include "particlemgr.h"
extern "C"
{
void DLLEXPORT HUD_DrawNormalTriangles( void );
void DLLEXPORT HUD_DrawTransparentTriangles( void );
};
extern float g_fFogColor[3];
extern float g_fStartDist;
extern float g_fEndDist;
extern int g_iWaterLevel;
extern vec3_t v_origin;
int UseTexture(HSPRITE &hsprSpr, char * str)
{
if (hsprSpr == 0)
{
char sz[256];
sprintf( sz, "%s", str );
hsprSpr = SPR_Load( sz );
}
return gEngfuncs.pTriAPI->SpriteTexture( (struct model_s *)gEngfuncs.GetSpritePointer( hsprSpr ), 0 );
}
//
//-----------------------------------------------------
//
//LRC - code for CShinySurface, declared in hud.h
CShinySurface::CShinySurface( float fScale, float fAlpha, float fMinX, float fMaxX, float fMinY, float fMaxY, float fZ, char *szSprite)
{
m_fScale = fScale; m_fAlpha = fAlpha;
m_fMinX = fMinX; m_fMinY = fMinY;
m_fMaxX = fMaxX; m_fMaxY = fMaxY;
m_fZ = fZ;
m_hsprSprite = 0;
sprintf( m_szSprite, "%s", szSprite );
m_pNext = NULL;
}
CShinySurface::~CShinySurface()
{
if (m_pNext)
delete m_pNext;
}
void CShinySurface::DrawAll(const vec3_t &org)
{
gEngfuncs.pTriAPI->RenderMode( kRenderTransAdd ); //kRenderTransTexture );
gEngfuncs.pTriAPI->CullFace( TRI_NONE );
for(CShinySurface *pCurrent = this; pCurrent; pCurrent = pCurrent->m_pNext)
{
pCurrent->Draw(org);
}
gEngfuncs.pTriAPI->RenderMode( kRenderNormal );
}
void CShinySurface::Draw(const vec3_t &org)
{
// add 5 to the view height, so that we don't get an ugly repeating texture as it approaches 0.
float fHeight = org.z - m_fZ + 5;
// only visible from above
// if (fHeight < 0) return;
if (fHeight < 5) return;
// fade out if we're really close to the surface, so they don't see an ugly repeating texture
// if (fHeight < 15)
// gEngfuncs.pTriAPI->Color4f( 1.0, 1.0, 1.0, (fHeight - 5)*0.1*m_fAlpha );
// else
gEngfuncs.pTriAPI->Color4f( 1.0, 1.0, 1.0, m_fAlpha );
// check whether the texture is valid
if (!UseTexture(m_hsprSprite, m_szSprite)) return;
// gEngfuncs.Con_Printf("minx %f, maxx %f, miny %f, maxy %f\n", m_fMinX, m_fMaxX, m_fMinY, m_fMaxY);
float fFactor = 1/(m_fScale*fHeight);
float fMinTX = (org.x - m_fMinX)*fFactor;
float fMaxTX = (org.x - m_fMaxX)*fFactor;
float fMinTY = (org.y - m_fMinY)*fFactor;
float fMaxTY = (org.y - m_fMaxY)*fFactor;
// gEngfuncs.pTriAPI->Color4f( 1.0, 1.0, 1.0, m_fAlpha );
gEngfuncs.pTriAPI->Begin( TRI_QUADS );
gEngfuncs.pTriAPI->TexCoord2f( fMinTX, fMinTY );
gEngfuncs.pTriAPI->Vertex3f ( m_fMinX, m_fMinY, m_fZ+0.02f ); // add 0.02 to avoid z-buffer problems
7 years ago
gEngfuncs.pTriAPI->TexCoord2f( fMinTX, fMaxTY );
gEngfuncs.pTriAPI->Vertex3f ( m_fMinX, m_fMaxY, m_fZ+0.02f );
7 years ago
gEngfuncs.pTriAPI->TexCoord2f( fMaxTX, fMaxTY );
gEngfuncs.pTriAPI->Vertex3f ( m_fMaxX, m_fMaxY, m_fZ+0.02f );
7 years ago
gEngfuncs.pTriAPI->TexCoord2f( fMaxTX, fMinTY );
gEngfuncs.pTriAPI->Vertex3f ( m_fMaxX, m_fMinY, m_fZ+0.02f );
7 years ago
gEngfuncs.pTriAPI->End();
}
//
//-----------------------------------------------------
//
//LRCT
//#define TEST_IT
#if defined( TEST_IT )
/*
=================
Draw_Triangles
Example routine. Draws a sprite offset from the player origin.
=================
*/
void Draw_Triangles( void )
{
cl_entity_t *player;
vec3_t org;
// Load it up with some bogus data
player = gEngfuncs.GetLocalPlayer();
9 years ago
if( !player )
7 years ago
return;
org = player->origin;
org.x += 50;
org.y += 50;
9 years ago
if( gHUD.m_hsprCursor == 0 )
7 years ago
{
char sz[256];
//LRCT sprintf( sz, "sprites/cursor.spr" );
sprintf( sz, "sprites/bubble.spr" ); //LRCT
gHUD.m_hsprCursor = SPR_Load( sz );
}
9 years ago
if( !gEngfuncs.pTriAPI->SpriteTexture( (struct model_s *)gEngfuncs.GetSpritePointer( gHUD.m_hsprCursor ), 0 ) )
7 years ago
{
return;
}
9 years ago
7 years ago
// Create a triangle, sigh
gEngfuncs.pTriAPI->RenderMode( kRenderNormal );
gEngfuncs.pTriAPI->CullFace( TRI_NONE );
gEngfuncs.pTriAPI->Begin( TRI_QUADS );
// Overload p->color with index into tracer palette, p->packedColor with brightness
gEngfuncs.pTriAPI->Color4f( 1.0, 1.0, 1.0, 1.0 );
// UNDONE: This gouraud shading causes tracers to disappear on some cards (permedia2)
gEngfuncs.pTriAPI->Brightness( 1 );
gEngfuncs.pTriAPI->TexCoord2f( 0, 0 );
gEngfuncs.pTriAPI->Vertex3f( org.x, org.y, org.z );
gEngfuncs.pTriAPI->Brightness( 1 );
gEngfuncs.pTriAPI->TexCoord2f( 0, 1 );
gEngfuncs.pTriAPI->Vertex3f( org.x, org.y + 50, org.z );
gEngfuncs.pTriAPI->Brightness( 1 );
gEngfuncs.pTriAPI->TexCoord2f( 1, 1 );
gEngfuncs.pTriAPI->Vertex3f( org.x + 50, org.y + 50, org.z );
gEngfuncs.pTriAPI->Brightness( 1 );
gEngfuncs.pTriAPI->TexCoord2f( 1, 0 );
gEngfuncs.pTriAPI->Vertex3f( org.x + 50, org.y, org.z );
gEngfuncs.pTriAPI->End();
gEngfuncs.pTriAPI->RenderMode( kRenderNormal );
}
#endif
void BlackFog ( void )
{
//Not in water and we want fog.
static float fColorBlack[3] = {0,0,0};
bool bFog = g_iWaterLevel < 2 && g_fStartDist > 0 && g_fEndDist > 0;
if (bFog)
gEngfuncs.pTriAPI->Fog ( fColorBlack, g_fStartDist, g_fEndDist, bFog );
else
gEngfuncs.pTriAPI->Fog ( g_fFogColor, g_fStartDist, g_fEndDist, bFog );
}
void RenderFog ( void )
{
//Not in water and we want fog.
bool bFog = g_iWaterLevel < 2 && g_fStartDist > 0 && g_fEndDist > 0;
if (bFog)
gEngfuncs.pTriAPI->Fog ( g_fFogColor, g_fStartDist, g_fEndDist, bFog );
// else
// gEngfuncs.pTriAPI->Fog ( g_fFogColor, 10000, 10001, 0 );
}
/*
=================
HUD_DrawNormalTriangles
Non-transparent triangles-- add them here
=================
*/
void DLLEXPORT HUD_DrawNormalTriangles( void )
{
gHUD.m_Spectator.DrawOverview();
#if defined( TEST_IT )
// Draw_Triangles();
#endif
}
/*
=================
HUD_DrawTransparentTriangles
Render any triangles with transparent rendermode needs here
=================
*/
extern ParticleSystemManager* g_pParticleSystems; // LRC
void DLLEXPORT HUD_DrawTransparentTriangles( void )
{
BlackFog();
//22/03/03 LRC: shiny surfaces
if (gHUD.m_pShinySurface)
gHUD.m_pShinySurface->DrawAll(v_origin);
// LRC: find out the time elapsed since the last redraw
static float fOldTime, fTime;
fOldTime = fTime;
fTime = gEngfuncs.GetClientTime();
// LRC: draw and update particle systems
g_pParticleSystems->UpdateSystems(fTime - fOldTime);
#if defined( TEST_IT )
// Draw_Triangles();
#endif
}