Hey,
I'm trying to implement a real-time rendered scope for my mod. I've used
some modified code from Rear-view mirror tutorial from valve developer,
but I can't get it to work. The render texture is compiled well using
tutrorial from http://www.fpsbanana.com/tuts/208 and it shows as black
ingame, but no scope is rendered on it. The code I use:
rendertexture.cpp:
//=============================================================================
// Scope Texture
//=============================================================================
static CTextureReference s_pScopeTexture;
ITexture *GetScopeTexture( void )
{
if ( !s_pScopeTexture )
{
if( materials->FindTexture( "_rt_Scope",
TEXTURE_GROUP_RENDER_TARGET ) )
{
s_pScopeTexture.Init( materials->FindTexture(
"_rt_Scope",
TEXTURE_GROUP_RENDER_TARGET ) );
if( IsErrorTexture( s_pScopeTexture ) )
return NULL;
Assert( !IsErrorTexture( s_pScopeTexture ) );
AddReleaseFunc();
}
}
return s_pScopeTexture;
}
view.cpp:
void CViewRender::DrawScope( const CViewSetup &viewSet )
{
C_BasePlayer *localPlayer = C_BasePlayer::GetLocalPlayer();
if(!localPlayer)
return;
if( !localPlayer->GetActiveWeapon() )
return;
//Copy our current View.
CViewSetup mirrorView = viewSet;
//Get our camera render target.
ITexture *pRenderTarget = GetScopeTexture();
if( pRenderTarget == NULL )
return;
//Fog data, enables for this view, and reverts back to default.
fogparams_t oldFogParams;
float flOldZFar = 0.0f;
bool fogEnabled = true;
if ( fogEnabled )
{
oldFogParams = localPlayer->m_Local.m_fog;
flOldZFar = mirrorView.zFar;
localPlayer->m_Local.m_fog.enable = true;
localPlayer->m_Local.m_fog.start = 2048;
localPlayer->m_Local.m_fog.end = 4096;
localPlayer->m_Local.m_fog.farz = 4096;
localPlayer->m_Local.m_fog.colorPrimary.SetR( 0 );
localPlayer->m_Local.m_fog.colorPrimary.SetG( 0 );
localPlayer->m_Local.m_fog.colorPrimary.SetB( 0 );
mirrorView.zFar = 4096;
}
//Our view information, Origin, View Direction, window size
// location on material, and visual ratios.
mirrorView.width = 256;
mirrorView.height = 256;
mirrorView.x = 0;
mirrorView.y = 0;
mirrorView.origin = localPlayer->GetAbsOrigin() + Vector( 0, 0, 50);
mirrorView.angles = localPlayer->GetRenderAngles();
//mirrorView.angles.x += 30;
//mirrorView.angles.y = AngleNormalize( mirrorView.angles.y + 180 );
mirrorView.fov = 40/*localPlayer->GetActiveWeapon()->GetZoomFov()*/;
mirrorView.m_bOrtho = false;
mirrorView.m_flAspectRatio = 1.0f;
//Set the view up and output the scene to our RenderTarget (Scope
Material).
render->Push3DView( mirrorView, VIEW_CLEAR_DEPTH | VIEW_CLEAR_COLOR,
true, pRenderTarget, m_Frustum );
ViewDrawScene( true, true, mirrorView, 0, VIEW_MAIN );
render->PopView( m_Frustum );
// Reset the world fog parameters.
if ( fogEnabled )
{
localPlayer->m_Local.m_fog = oldFogParams;
mirrorView.zFar = flOldZFar;
}
}
And this in RenderViewEx:
if(g_pMaterialSystemHardwareConfig->GetDXSupportLevel() >= 70 )
{
DrawScope( view );
}
_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders