DrawIndexedPrimitive DX9 and VC++ 2005

B24044bda718c3a3fc73ea9b2ead04a4
0
kurlyak 101 Feb 27, 2012 at 18:14

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!

0 Replies

Please log in or register to post a reply.

No replies have been made yet.