Jump to content


initialize index buffer of mesh


3 replies to this topic

#1 f1engineer

    New Member

  • Members
  • PipPip
  • 18 posts

Posted 21 August 2007 - 10:40 AM

Hello all
I try to create a simple square using mesh. The square has 2 triangles and 4 vertex points. Bellow is my function that must create this mesh. However after executing it I don't receive what I expected. Can someone tell where is my mistake:

[source]
void CD3DSimulationView::CreateMeshes()
{
unsigned short nNumFaces = 2;
unsigned short nNumVertices = 4;

//setup mesh
if(SUCCESS(D3DXCreateMeshFVF(nNumFaces, nNumVertices, D3DXMESH_VB_MANAGED, D3DFVF_XYZ,
m_pd3dDevice, &m_pMesh))
{

//allocate vertex buffer
CUSTOMVERTEX* pVertices;
m_pMesh->LockVertexBuffer(D3DLOCK_DISCARD, (void**)&pVertices);

//initialize vertex buffer // X Y Z
pVertices[0].m_pVertices = D3DXVECTOR3( 2, -2, 0);
pVertices[1].m_pVertices = D3DXVECTOR3(-2, -2, 0);
pVertices[2].m_pVertices = D3DXVECTOR3(-2, 2, 0);
pVertices[3].m_pVertices = D3DXVECTOR3( 2, 2, 0);

m_pMesh->UnlockVertexBuffer();

//allocate and initialize index buffer
UINT16 *pIB = NULL;
m_pMesh->LockIndexBuffer(0, (void**)&pIB);

pIB[0] = 0;
pIB[1] = 1;
pIB[2] = 2;

pIB[3] = 0;
pIB[4] = 3;
pIB[5] = 2;

m_pMesh->UnlockIndexBuffer();
}
}
[source]
best regards
Kamen

#2 f1engineer

    New Member

  • Members
  • PipPip
  • 18 posts

Posted 21 August 2007 - 12:55 PM

Concreteness my question is:

Do I initialize index buffer correctly? I think my mistake is of initializing the index buffer.

regards
Kamen

#3 J22

    Member

  • Members
  • PipPip
  • 92 posts

Posted 21 August 2007 - 04:22 PM

f1engineer said:

Do I initialize index buffer correctly?
I don't think you do. Instead of setting pIB[3] = 0; pIB[4] = 3; pIB[5] = 2; I believe you should have it like this: pIB[3] = 0; pIB[4] = 2; pIB[5] = 3; to have the same winding order for both triangles.

#4 f1engineer

    New Member

  • Members
  • PipPip
  • 18 posts

Posted 22 August 2007 - 06:30 AM

Thank You
I shall try immediately.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users