Jump to content


DrawIndexedPrimitive DX9 and VC++ 2005


  • You cannot reply to this topic
No replies to this topic

#1 kurlyak

    Member

  • Members
  • PipPip
  • 93 posts

Posted 27 February 2012 - 06:14 PM

I am confused with DrawIndexedPrimitive() DX9. I am myself create Attribute Buffer, create Vert Buffer and Index Buffer. But 3D model don`t render properly. What is the matter?

Indices Array arranged by material. That is for example:
Mat #1 - > face 1, face 2, face 3
Mat #2 -> face 4, face 5, face 6 etc.
And indices array contain:
1, 2, 3, 4, 5, 6 etc.


My code:
pTR2RoomMesh[i].pAttr = new D3DXATTRIBUTERANGE[pTR2RoomMesh[i].nNumMat];
for(UINT k=0; k<pTR2RoomMesh[i].nNumMat; k++)
{
set <int> myset;
for(UINT j=0; j< v[k].size(); j++)
{
UINT v1, v2, v3;
UINT face = v[k][j].face;
v1 = pTR2RoomMesh[i].pIndicesArrayNew[face*3];
v2 = pTR2RoomMesh[i].pIndicesArrayNew[face*3 + 1];
v3 = pTR2RoomMesh[i].pIndicesArrayNew[face*3 + 2];
myset.insert(v1);
myset.insert(v2);
myset.insert(v3);
}
UINT nFaceStart = vn[k][0].face;
UINT nFaceCount = (UINT) vn[k].size();
UINT nVertStart = pTR2RoomMesh[i].pIndicesArrayNew[nFaceStart*3];

pTR2RoomMesh[i].pAttr[k].AttribId = k;
pTR2RoomMesh[i].pAttr[k].VertexStart = nVertStart;
pTR2RoomMesh[i].pAttr[k].VertexCount = (UINT) myset.size();
pTR2RoomMesh[i].pAttr[k].FaceStart = nFaceStart;
pTR2RoomMesh[i].pAttr[k].FaceCount = nFaceCount;
}
for (int i = 0; i < Level->NumRooms; i++)
{
for(int k = 0; k < pTR2RoomMesh[i].nNumMat; k++)
{
..........................
m_pD3DDevice->SetFVF(D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1);
m_pD3DDevice->SetStreamSource( 0, pTR2RoomMesh[i].pVB, 0, sizeof(LEVEL_VERTEX) );
m_pD3DDevice->SetIndices( pTR2RoomMesh[i].pIB );
m_pD3DDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST,
0,
pTR2RoomMesh[i].pAttr[k].VertexStart,   //MinIndex
pTR2RoomMesh[i].pAttr[k].VertexCount,   //NumVertices
pTR2RoomMesh[i].pAttr[k].FaceStart*3,   //StartIndex
pTR2RoomMesh[i].pAttr[k].FaceCount );   //NumPrimitives
...................

Thanks in advance!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users