CMeshBuilder: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(The code was in the wrong order. The material must be bound before the call to get the mesh)
No edit summary
Line 53: Line 53:


</syntaxhighlight>
</syntaxhighlight>
[[Category:Programming]]

Revision as of 08:35, 14 April 2021

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