Original Post
Hi,
i just started to look into vertex buffers and i thought that i good way of understanding them would to put a floor under a mesh i''m displaying. However i''m having problems. whenever i run my program the screen goes nuts and keeps switching coloring every frame. i figure it''s something stupid but i can''t see what. any help anyone can give is appreciated.
this is the code that i use to initialize the VB.
NVertex plane[6]; //normaled vertex x,y,z nx,ny,nz
ZeroMemory(plane,sizeof(NVertex)*6);
plane[0].x = 100;
plane[0].z = 100;
plane[1].x = 100;
plane[1].z = -100;
plane[2].x = -100;
plane[2].z = -100;
plane[3].x = -100;
plane[3].z = -100;
plane[4].x = 100;
plane[4].z = 100;
plane[5].x = -100;
plane[5].z = 100;
for(int i = 0; i <6; i++)
{
plane.y = 0;
plane[i].nx = 0;
plane[i].ny = 1;
plane[i].nz = 0;
}
hr = pDevice->CreateVertexBuffer(6*sizeof(NVertex),0,NVertexFormat,D3DPOOL_DEFAULT,&pVB); //succeeds
if(FAILED(hr))
{
DEBUG_MSG("CreateVertexBuffer",hr);
}
LPBYTE pData = NULL;
hr = pVB->Lock(0,0,&pData,0 ); //succeeds
if(FAILED(hr))
{
DEBUG_MSG("Lock",hr);
}
memcpy(pData,plane,sizeof(NVertex)*6);
hr = pVB->Unlock(); //succeeds
--------------------------------
and this is the code i use to display it
--------------------------------
D3DXMATRIX matWorld;
D3DXMatrixIdentity(&matWorld);
pDevice->SetTransform(D3DTS_WORLD,&matWorld);
pDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_WIREFRAME );
EnableLighting(FALSE);
pDevice->SetVertexShader(D3DFVF_XYZ);
pDevice->SetStreamSource(0,pVB,sizeof(NVertex)*6);
pDevice->DrawPrimitive(D3DPT_TRIANGLELIST,0,2);