Jump to content
  • Advertisement
Sign in to follow this  
Vanderry

[DX9] Render mesh one polygon at a time

This topic is 3084 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys !

I have these meshes loaded from .x-files that I want to render one polygon at a time, or rather I would like to render certain selected polygons differently. So the way I figured this should be done is something like this:

LPDIRECT3DVERTEXBUFFER9 pVB = NULL;
LPDIRECT3DINDEXBUFFER9 pIB = NULL;
m_pMesh->GetVertexBuffer( &pVB );
m_pMesh->GetIndexBuffer( &pIB );
pDevice->SetFVF( m_pMesh->GetFVF() );
pDevice->SetStreamSource( 0, pVB, 0, m_pMesh->GetNumBytesPerVertex() );
pDevice->SetIndices( pIB );

for( UINT i = 0; i < m_pMesh->GetNumFaces(); i++ )
{
pDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, 3, i, 1 );
}


However this doesn't seem to work so I thought I'd ask what I'm doing wrong, is this the right way to render a mesh one polygon at a time or is there a better way?

- Dave

Share this post


Link to post
Share on other sites
Advertisement
Try this:

pDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, 3, i * 3, 1 );

since in that code, i is the index for the face, not the vertex index. That is, you want to render faces 0, 1, 2, etc., and the vertex indices for those are 0, 3, 6, etc.

Share this post


Link to post
Share on other sites
Quote:
Original post by Gage64
Try this:

pDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, 3, i * 3, 1 );

since in that code, i is the index for the face, not the vertex index. That is, you want to render faces 0, 1, 2, etc., and the vertex indices for those are 0, 3, 6, etc.


Thanks man, that solved the problem nicely :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!