Vertex Buffer help

Started by
4 comments, last by musikit 21 years, 11 months ago
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.nx = 0; plane.ny = 1; plane.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); </i>
Advertisement
First, your second triangle is flipped, or in other words, the vertices are ordered in a counter clockwise order.
Second, your vertex data contains a normal while the vertex shader doesn''t. change:
pDevice->SetVertexShader(D3DFVF_XYZ);
into:
pDevice->SetVertexShader(D3DFVF_XYZ | D3DFVF_NORMAL);
The screen is ''going nuts'' because Direct3D is trying to tell you you''re doing something wrong.

1)Install the Debug runtime if you haven''t already.
2)Go to the Control Panel and set the D3D debug level higher
3)Run your program in the debugger and it will tell you what''s wrong.

I think FantasyGuy nailed the problem, but do those 3 things anyway so you''ll know how to find this stuff on your own. The debug runtime can be your best friend when things are going wrong.


Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena
thxs.

ok. i switched the vertexes and did the SetVertexShader. however now it''s complaining with an error in the debug output

"Stream 0 stride should match the stride, implied by the current vertex shader"

i''ve been working strictly with meshes so far, so i''m not really sure what this error means.

Change;
pDevice->SetStreamSource(0,pVB,sizeof(NVertex)*6);

to
pDevice->SetStreamSource(0,pVB,sizeof(NVertex));

Cheers

Matt



Main site | Free source | Email
thxs. that did it.

i appreciate all the help.

This topic is closed to new replies.

Advertisement