It seems that you are overwriting your index buffer in between your draw calls, you might want to have a careful look at how you fill these. Also in the SetStreamSource call for the second draw is using an offset of 36 instead of 24 like the first one, why is this as that might be why you are skipping 2 verts at a time. Have a look at your vertex declarations in PIX as they will tell you what your stride size should be
My index buffer is only filled once, (During initialization)
Here is how I fill it
//Creation
if(FAILED( g_pd3dDevice->CreateIndexBuffer(s_nBatchSize * 6, 0,
D3DFMT_INDEX32, D3DPOOL_DEFAULT ,&m_pIB, NULL)))
//Filling only done once
// Lock the index buffer
VOID* pIndices;
m_pIB->Lock(0, s_nBatchSize * 6, (void**)&pIndices, 0);
uINT indices[s_nBatchSize * 6];//Because for a quad you need 4 verts and 6 indicies
uINT indexCounter = 0;//used to store a value that helps set the correct indicie value
for(uINT i = 0; i < s_nBatchSize * 6; i += 6)
{
//Set 6 values that use 4 verticies
//0, 1, 2 Triangle 1
indices[i + 0] = (indexCounter * 4 + 0);
indices[i + 1] = (indexCounter * 4 + 1);
indices[i + 2] = (indexCounter * 4 + 2);
//2, 1, 3 Triangle 2
indices[i + 3] = (indexCounter * 4 + 2);
indices[i + 4] = (indexCounter * 4 + 1);
indices[i + 5] = (indexCounter * 4 + 3);
//Increase the index counter to get the right values
++indexCounter;
}
memcpy(pIndices, indices, sizeof(indices) / sizeof(indices[0]));//sizeof(indices) / sizeof(indices[0]) = number of elements in the array
// Unlock it
m_pIB->Unlock();
Does that look right?
"second draw is using an offset of 36 instead of 24"
I can't figure this out, I don't know where the first one is coming from, it only gets called once per frame atm, so I have no idea what is calling it
g_pd3dDevice->SetStreamSource(0, m_pVB, nRenderOffset, sizeof( SpriteVertex ));
Interestingly though, sizeof (SpriteVetex) = 36 but when I put 24 in there instead I ACTUALLY SEE A SPRITE RENDERED I'm not sure what this means though.
One thing I just want check though as I am unfimiliar with them is my Vertex Declaration.
Do these two add up?:
//VERTEX
struct SpriteVertex
{
D3DXVECTOR3 vPos;
D3DXCOLOR Colour;
uINT u1, v1;
};
//VERTEX DECLARATION
D3DVERTEXELEMENT9 Sprite_Decl[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0},
{0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
D3DDECL_END() // this macro is needed as the last item!
};
Thanks