CMeshBuilder: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(A basic overview of how to use CMeshBuilder)
 
(The code was in the wrong order. The material must be bound before the call to get the mesh)
Line 18: Line 18:
CMatRenderContextPtr pRenderContext( materials );
CMatRenderContextPtr pRenderContext( materials );
IMesh *pMesh;
IMesh *pMesh;
//Must be bound before the call to get the mesh
pRenderContext->Bind( pBlurMaterial );
pMesh = pRenderContext->GetDynamicMesh();
pMesh = pRenderContext->GetDynamicMesh();
pRenderContext->Bind( pBlurMaterial );


CMeshBuilder meshBuilder;
CMeshBuilder meshBuilder;

Revision as of 21:57, 13 February 2013

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