env_projectedtexture fixes

I’m trying to do this:

https://developer.valvesoftware.com/wiki/Env_projectedtexture/fixes

I’ve put in the code, following the directions to the best of my knowledge. But I’m getting some rather entertaining errors:

[code]1>c:\program files (x86)\steam\steamapps\sourcemods\five codebase\src\game\client\c_env_projectedtexture.cpp(170) : error C2181: illegal else without matching if

1>c:\program files (x86)\steam\steamapps\sourcemods\five codebase\src\game\client\c_env_projectedtexture.cpp(228) : error C2601: ‘C_EnvProjectedTexture::Simulate’ : local function definitions are illegal

1> c:\program files (x86)\steam\steamapps\sourcemods\five codebase\src\game\client\c_env_projectedtexture.cpp(126): this line contains a ‘{’ which has not yet been matched

1>c:\program files (x86)\steam\steamapps\sourcemods\five codebase\src\game\client\c_env_projectedtexture.cpp(234) : fatal error C1075: end of file found before the left brace ‘{’ at ‘c:\program files (x86)\steam\steamapps\sourcemods\five codebase\src\game\client\c_env_projectedtexture.cpp(126)’ was matched

1>c:\program files (x86)\steam\steamapps\sourcemods\five codebase\src\game\client\spritemodel.cpp(442) : error C3861: ‘IsBIK’: identifier not found[/code]

Most of these seem to be in the env_projectedtexture.cpp, since I was modifying it to run the tutorial’s code.

I’m a bit of a novice at this coding thing -_-;;
Anyone want to give this a punt, or see what I’m doing wrong?

Seems like you’re missing some closing brackets. Try this and report back:

[code]void C_EnvProjectedTexture::OnDataChanged( DataUpdateType_t updateType )
{
UpdateLight( true );
BaseClass::OnDataChanged( updateType );
}

void C_EnvProjectedTexture::UpdateLight( bool bForceUpdate )
{
if ( m_bState == false )
{
if ( m_LightHandle != CLIENTSHADOW_INVALID_HANDLE )
{
ShutDownLightHandle();
}

	return;
}
Vector vForward, vRight, vUp, vPos = GetAbsOrigin();
FlashlightState_t state;

if ( m_hTargetEntity != NULL )
{
	if ( m_bCameraSpace )
	{
		const QAngle &angles = GetLocalAngles();

		C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
		if( pPlayer )
		{
			const QAngle playerAngles = pPlayer->GetAbsAngles();
			
			Vector vPlayerForward, vPlayerRight, vPlayerUp;
			AngleVectors( playerAngles, &vPlayerForward, &vPlayerRight, &vPlayerUp );

        	matrix3x4_t	mRotMatrix;
			AngleMatrix( angles, mRotMatrix );

			VectorITransform( vPlayerForward, mRotMatrix, vForward );
			VectorITransform( vPlayerRight, mRotMatrix, vRight );
			VectorITransform( vPlayerUp, mRotMatrix, vUp );

			float dist = (m_hTargetEntity->GetAbsOrigin() - GetAbsOrigin()).Length();
			vPos = m_hTargetEntity->GetAbsOrigin() - vForward*dist;

			VectorNormalize( vForward );
			VectorNormalize( vRight );
			VectorNormalize( vUp );
		}
	}
	else
	{
		// VXP: Fixing targeting
		Vector vecToTarget;
		QAngle vecAngles;
		if ( m_hTargetEntity == NULL )
		{
			vecAngles = GetAbsAngles();
		}
		else
		{
			vecToTarget = m_hTargetEntity->GetAbsOrigin() - GetAbsOrigin();
			VectorAngles( vecToTarget, vecAngles );
		}
		AngleVectors( vecAngles, &vForward, &vRight, &vUp );
	}
}
else
{
	AngleVectors( GetAbsAngles(), &vForward, &vRight, &vUp );
}

state.m_fHorizontalFOVDegrees = m_flLightFOV;
state.m_fVerticalFOVDegrees = m_flLightFOV;

state.m_vecLightOrigin = vPos;
BasisToQuaternion( vForward, vRight, vUp, state.m_quatOrientation );

state.m_fQuadraticAtten = 0.0;
state.m_fLinearAtten = 100;
state.m_fConstantAtten = 0.0f;
state.m_Color[0] = m_LinearFloatLightColor.x;
state.m_Color[1] = m_LinearFloatLightColor.y;
state.m_Color[2] = m_LinearFloatLightColor.z;
state.m_Color[3] = 0.0f; // fixme: need to make ambient work m_flAmbient;
state.m_NearZ = m_flNearZ;
state.m_FarZ = m_flFarZ;
state.m_flShadowSlopeScaleDepthBias = mat_slopescaledepthbias_shadowmap.GetFloat();
state.m_flShadowDepthBias = mat_depthbias_shadowmap.GetFloat();
state.m_bEnableShadows = m_bEnableShadows;
state.m_pSpotlightTexture = materials->FindTexture( m_SpotlightTextureName, TEXTURE_GROUP_OTHER, false );
state.m_nSpotlightTextureFrame = m_nSpotlightTextureFrame;

state.m_nShadowQuality = m_nShadowQuality; // Allow entity to affect shadow quality

if( m_LightHandle == CLIENTSHADOW_INVALID_HANDLE )
{
	m_LightHandle = g_pClientShadowMgr->CreateFlashlight( state );
}
else
{
	if ( m_hTargetEntity != NULL || bForceUpdate == true )
	{
		g_pClientShadowMgr->UpdateFlashlightState( m_LightHandle, state );
	}
}

if( m_bLightOnlyTarget )
{
	g_pClientShadowMgr->SetFlashlightTarget( m_LightHandle, m_hTargetEntity );
}
else
{
	g_pClientShadowMgr->SetFlashlightTarget( m_LightHandle, NULL );
}

g_pClientShadowMgr->SetFlashlightLightWorld( m_LightHandle, m_bLightWorld );

//if ( bForceUpdate == false )
//{
	g_pClientShadowMgr->UpdateProjectedTexture( m_LightHandle, true );
//}

}

void C_EnvProjectedTexture::Simulate( void )
{
UpdateLight( GetMoveParent() != NULL );

BaseClass::Simulate();

}[/code]

YOU ARE THE MAN, K-MAN.

That’s fixed everything in the projected texture project. However, the project failed because of something in a part of the project I don’t remember touching at all.

1>c:\program files (x86)\steam\steamapps\sourcemods\five codebase\src\game\client\spritemodel.cpp(442) : error C3861: 'IsBIK': identifier not found

The lines referenced in spritemodel:

[code]void CEngineSprite: :smiley: rawFrameOfSize( 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();

}[/code]

What’s weird is that I never touched this part of the code. Is this error in the vanilla 2007 source code? Should I just comment it out?

Try commenting out Assert( !IsAVI() && !IsBIK() );

Yay, the build was successful! Thanks, Keresh! I’ll have to make a test map with some projected textures and see if it works. I will report back with my findings.

Founded in 2004, Leakfree.org became one of the first online communities dedicated to Valve’s Source engine development. It is more famously known for the formation of Black Mesa: Source under the 'Leakfree Modification Team' handle in September 2004.