Original Post
Hello again, sorry for all the newb questions. I'm trying to draw 3 lines (red green and blue) at the origin so I can visualize the x y and z axis. The lines are rendered correctly but they are black. Am I doing something wrong? Is there a better way to draw colored lines?
#define D3DFVF_LINEVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE)
struct LINEVERTEX
{
FLOAT px, py, pz;
D3DCOLOR diffuse;
};
LPDIRECT3DVERTEXBUFFER9 LineVB = NULL;
vector<LINEVERTEX> Lines;
HRESULT InitAxis()
{
LINEVERTEX lv;
// Red line
lv.px = 0.0f;
lv.py = 0.0f;
lv.pz = 0.0f;
lv.diffuse = D3DCOLOR_XRGB(255, 0, 0);
Lines.push_back(lv);
lv.px = 10.0f;
lv.py = 0.0f;
lv.pz = 0.0f;
lv.diffuse = D3DCOLOR_XRGB(255, 0, 0);
Lines.push_back(lv);
// Green line
lv.px = 0.0f;
lv.py = 0.0f;
lv.pz = 0.0f;
lv.diffuse = D3DCOLOR_XRGB(0, 255, 0);
Lines.push_back(lv);
lv.px = 0.0f;
lv.py = 10.0f;
lv.pz = 0.0f;
lv.diffuse = D3DCOLOR_XRGB(0, 255, 0);
Lines.push_back(lv);
// Blue line
lv.px = 0.0f;
lv.py = 0.0f;
lv.pz = 0.0f;
lv.diffuse = D3DCOLOR_XRGB(0, 0, 255);
Lines.push_back(lv);
lv.px = 0.0f;
lv.py = 0.0f;
lv.pz = 10.0f;
lv.diffuse = D3DCOLOR_XRGB(0, 0, 255);
Lines.push_back(lv);
// Create the vertex buffer
if (FAILED(D3DDevice->CreateVertexBuffer((UINT)Lines.size() * sizeof(LINEVERTEX), 0, D3DFVF_LINEVERTEX, D3DPOOL_DEFAULT, &LineVB, NULL)))
{
MessageBox(NULL, "Error creating vertex buffer", "Error", MB_OK);
return E_FAIL;
}
// Fill the vertex buffer
VOID* pVertices;
if (FAILED(LineVB->Lock(0, 0, (void**)&pVertices, 0)))
{
MessageBox(NULL, "Error filling vertex buffer", "Error", MB_OK);
return E_FAIL;
}
memcpy(pVertices, &(Lines[0]), Lines.size() * sizeof(LINEVERTEX));
LineVB->Unlock();
return S_OK;
}
VOID Render()
{
// ...
D3DDevice->SetStreamSource(0, LineVB, 0, sizeof(LINEVERTEX));
D3DDevice->SetFVF(D3DFVF_LINEVERTEX);
D3DDevice->DrawPrimitive(D3DPT_LINELIST, 0, (UINT)Lines.size() / 2);
// ...
}