Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

musikit

Vertex Buffer help

This topic is 5917 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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);

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!