DrawPrimitive() works, but not DrawIndexedPrimitive()

Started by
3 comments, last by __Daedalus__ 19 years, 9 months ago
Hey all, I'm writing a set of wrapper classes for D3D and i've run into a little problem. I can draw a triangle fine if i use DrawPrimitive(). but using DrawIndexedPrimitive() doesn't display anything. Heres how i use my classes at the moment:

CStaticVB theVB;
CDynamicIB theIB;
Vertex* pVert;
WORD* pIndices;
DWORD dwOffset;

   theVB.Create(3);
   theIB.Create(3);

   pVert = (Vertex*)theVB.Lock(0,3);
   pVert->vPos = D3DXVECTOR3(0,1,0);
   pVert->vNormal = D3DXVECTOR3(0,0,-1);
   pVert->u1 = 0.0f;
   pVert->v1 = 0.0f;
   pVert++;
   pVert->vPos = D3DXVECTOR3(1,0,0);
   pVert->vNormal = D3DXVECTOR3(0,0,-1);
   pVert->u1 = 0.0f;
   pVert->v1 = 0.0f;
   pVert++;
   pVert->vPos = D3DXVECTOR3(-1,0,0);
   pVert->vNormal = D3DXVECTOR3(0,0,-1);
   pVert->u1 = 0.0f;
   pVert->v1 = 0.0f;
   pVert++;
   theVB.Unlock();
   pIndices = theIB.Lock(3,dwOffset);  // dwOffset passed by reference and filled in
   *pIndices++ = 0;
   *pIndices++ = 1;
   *pIndices++ = 2;
   theIB.Unlock();

   theIB.DrawIndexedPrimitive(theVB,D3DPT_TRIANGLELIST,dwOffset,0,3,1); 
   theVB.DrawPrimitive(D3DPT_TRIANGLELIST,0,1);

   theIB.Release();
   theVB.Release();
If i comment out the line calling DrawIndexedPrimitive(), i get a triangle, but if i comment out the line calling DrawPrimitive(), i get nothing. The reason for the dwOffset parameter is that when i call CIB::Create() (or CVB::Create()), it creates a region inside a IDirect3DIndexBuffer9. This way, i can put several models inside one IB (or VB) easily. For testing purposes, i've forced it to create a new IDirect3DIndexBuffer9 each time, containing only 3 indices, so dwOffset is always 0. Calling CVB::DrawPrimitive() internally calls CRender::SetVB() - which calls SetFVF() and SetStreamSource() if needed, and then calls IDirect3DDevice9::DrawPrimitive(). Calling CIB::DrawIndexedPrimitive() internally calls CRender::SetVB(), CRender::SetIB() - which calls SetIndices() - and then calls IDirect3DDevice9::DrawIndexedPrimitive(). Heres what CIB::DrawIndexedPrimitive() looks like:

void CIB::DrawIndexedPrimitive(const CVB& rVB, D3DPRIMITIVETYPE eType,
                               DWORD dwStartIndex, DWORD dwMinIndex,
                               DWORD dwNumVerts, DWORD dwPrimCount)
{
   GetRender()->SetIB(m_pIB);
   GetRender()->SetVB(rVB.m_pVB);
   GetRender()->GetDevice()->DrawIndexedPrimitive(eType,m_dwStartIndex,
      dwMinIndex,dwNumVerts,m_dwStartIndex,dwPrimCount);
}
And that translates to the following: IDirect3DDevice9::DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,3,0,1); I've got macros around all of my D3D calls to check the return values - Every call succeeds. I've also got the debug runtimes installed, and the debug output set to maximum. I've also disabled culling, and i'm not using textures or anything. So, does anyone have any ideas about why this might not be working? I know its not exactly easy to see, since everythings wrapped up, but perhaps someone has had a similar problem? Cheers, Steve
Advertisement
What size format are you using to create your index buffer? For example, if you are creating your index buffer with the D3DFMT_INDEX16 flag then you must use the WORD* (16 bit) variable to manipulate your indices. If, on the other hand, you are using D3DFMT_INDEX32 to create you index buffer then you must manipulate your indices with DWORD* (32 bit) variable (e.g. DWORD* pIndices; in your code).

Hope that helps
My indices are D3DFMT_INDEX16.

Heres the output of one frames worth of D3DSpy calls if it helps. I can't see anything wrong with them though :(
D3DSpy Output

EDIT:
Just for giggles, heres the output using DrawPrimitive() (but leaving all the other calls in except for DrawIndexedPrimitive())
D3DSpy Output 2
Ooookkkeeeey.... I don't know what i did, but its apparently working now.

I'll let you know if i ever find out what it was...

Cheers,
Steve
Quote:Original post by Evil Steve
Ooookkkeeeey.... I don't know what i did, but its apparently working now.

I'll let you know if i ever find out what it was...

Cheers,
Steve

I hope you find out what it was - there is nothing more irritating than when that happens [smile] The few times that has happened to me is when I have cleaned and done a full recompilation of my project or rebooted my machine.

This topic is closed to new replies.

Advertisement