CMeshBuilder

From Valve Developer Community
Revision as of 21:57, 13 February 2013 by Gandalf458 (talk | contribs) (The code was in the wrong order. The material must be bound before the call to get the mesh)
Jump to navigation Jump to search

The CMeshBuilder can be used to draw primitives. In most cases it is required that you call CMeshBuilder inside of DrawModel. Also, DrawModel will only be called for your C_BaseEntity if you have the ShouldDraw function return true.

#ifdef CLIENT_DLL
	virtual bool	ShouldDraw() { return true; }
	virtual int	DrawModel( int flags );
#endif


#ifdef CLIENT_DLL
//-----------------------------------------------------------------------------
// Purpose: Override to allow us to draw motion blur quads
//-----------------------------------------------------------------------------
int YourClass::DrawModel( int flags )
{
// Do something here to get your vectors....

	CMatRenderContextPtr pRenderContext( materials );
	IMesh *pMesh;
//Must be bound before the call to get the mesh
	pRenderContext->Bind( pBlurMaterial );
	pMesh = pRenderContext->GetDynamicMesh();

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

	meshBuilder.Color3f( 1.0f, 1.0f, 1.0f );
	meshBuilder.TexCoord2f( 0,0,0 );
	meshBuilder.Position3f( posL.x,posL.y,posL.z );
	meshBuilder.AdvanceVertex();

	meshBuilder.Color3f( 1.0f, 1.0f, 1.0f );
	meshBuilder.TexCoord2f( 0,1,0 );
	meshBuilder.Position3f( posR.x,posR.y,posR.z );
	meshBuilder.AdvanceVertex();

	meshBuilder.Color3f( 1.0f, 1.0f, 1.0f );
	meshBuilder.TexCoord2f( 0,1,1 );
	meshBuilder.Position3f( oldPosL.x, oldPosL.y, oldPosL.z );
	meshBuilder.AdvanceVertex();

        meshBuilder.Color3f( 1.0f, 1.0f, 1.0f );
	meshBuilder.TexCoord2f( 0,0,1 );
        meshBuilder.Position3f( oldPosR.x, oldPosR.y, oldPosR.z );
	meshBuilder.AdvanceVertex();
	meshBuilder.End();
	pMesh->Draw();

	}
	return BaseClass::DrawModel( flags );
}
#endif