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