CMeshBuilder

From Valve Developer Community
Jump to navigation Jump to search
Wikipedia - Letter.png
This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages)
Dead End - Icon.png
This article has no links to other VDC articles. Please help improve this article by adding links that are relevant to the context within the existing text.
January 2024
Icon-callout-orphan.png
This article is an orphan, meaning that few or no articles link to it (since January 2024). You can help by adding links to this article from other relevant articles.

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