First, read this: http://ahlukalt.blogspot.com/ (The latest post, "Vertex Buffers").
They're out to get me.
Here's my vertex struct along with the array of them I'm using:
Code:
struct CUSTOMVERTEX
{
float x, y, z;
DWORD color;;
};
CUSTOMVERTEX g_4Verts[] =
{
{-1.0f, -1.0f, 5.0f, D3DCOLOR_XRGB(255, 0, 0)},
{-1.0f, 1.0f, 5.0f, D3DCOLOR_XRGB(255, 255, 0)},
{ 1.0f, -1.0f, 5.0f, D3DCOLOR_XRGB(0, 255, 0)},
{ 1.0f, 1.0f, 5.0f, D3DCOLOR_XRGB(0, 0, 255)}
};
USHORT g_Indices[] = { 0, 1, 2, 1, 3, 2 };
So first I was locking the vertex buffer with D3DLOCK_DISCARD only to find out "Direct3D9: (ERROR) :Can specify D3DLOCK_DISCARD or D3DLOCK_NOOVERWRITE for only Vertex Buffers created with D3DUSAGE_DYNAMIC".
So I set the lock flag to 0 (since I don't know what else to set it to) and now the Lock() calls succeed but still nothing is drawn.
Here's where I create the vertex / index buffers and fill 'em up. I think it's pretty self explanatory; If you want me to post up the vertex / index buffer classes, tell me:
Code:
// The 0 (3rd arg) to SetData() is setting the Lock() flags to 0
void Game::OnCreateDevice(LPDIRECT3DDEVICE9 pDevice)
{
m_VB4.CreateBuffer(pDevice, 4, D3DFVF_XYZ | D3DFVF_DIFFUSE, sizeof(CUSTOMVERTEX));
m_VB4.SetData(4, g_4Verts, 0);
m_IB.CreateBuffer(pDevice, 6, D3DFMT_INDEX16);
m_IB.SetData(6, g_Indices, 0);
m_VB4.SetIndexBuffer(&m_IB);
}
The rendering:
Code:
void Game::OnRenderFrame(LPDIRECT3DDEVICE9 pDevice)
{
pDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 200),
1.0f, 0);
pDevice->BeginScene();
m_VB4.Render(pDevice, 2, D3DPT_TRIANGLELIST);
pDevice->EndScene();
pDevice->Present(0, 0, 0, 0);
}
Here's the Render() method itself:
Code:
void bgVertexBuffer::Render(LPDIRECT3DDEVICE9 pDevice, UINT uNumPrimitives,
D3DPRIMITIVETYPE primitiveType)
{
if (!pDevice)
return;
pDevice->SetStreamSource(0, m_pVB, 0, m_uVertexSize);
pDevice->SetFVF(m_dwFVF);
// Got milk? Oops, I mean, Got an index buffer?
if (m_pIB)
{
pDevice->SetIndices(m_pIB->GetBuffer());
pDevice->DrawIndexedPrimitive(primitiveType, 0, 0, m_uNumVertices, 0, uNumPrimitives);
}
else
pDevice->DrawPrimitive(primitiveType, 0, uNumPrimitives);
}
While debugging I don't get any DirectX error messages in the output window so I'm fairly stumped. It's nothing to do with setting the Lock() flags to 0 is it?