Jump to content
  • Advertisement
Sign in to follow this  
Denzin

Modifying VertexBuffer Data

This topic is 2954 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

Greetings! I've happen to run into a wall when working on a current project that requires me to manipulate a mesh's vertex data per frame.

The code


sCOLORVERTEX* pVertices;

terrainMesh->VertexBuffer()->Lock(0,sizeof(sCOLORVERTEX),(void**)&pVertices,0);

for(unsigned i=0; i < terrainMesh->Verts(); ++i)
{
pVertices.color = D3DCOLOR_XRGB(rand()%255,rand()%255,rand()%255);
pVertices.pos.y =rand() % 200 - 100;
}

terrainMesh->VertexBuffer()->Unlock();



(modifications are a trivial test)
For the first time this is called, all verts are assigned a random height and color (easily determined visually). Every frame there after, this function is called yet only one vert changes color and height, everything else stays exactly the same!

Share this post


Link to post
Share on other sites
Advertisement
the second parameter to Lock() is
The amount of data (in bytes) that you wish to lock. Setting this to 0 will lock the entire buffer.

What does sizeof(sCOLORVERTEX) evaluate to?

Share this post


Link to post
Share on other sites

const DWORD FVF_COLORVERTEX = D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_DIFFUSE;

struct sCOLORVERTEX
{
D3DXVECTOR3 pos;
D3DXVECTOR3 normal;
D3DCOLOR color;
};



I want to lock the entire buffer to modify every vert in it, only one is taking the change however.

Share this post


Link to post
Share on other sites
oh oops! i didn't notice that sizeof() was in there. Thank you for making me look like a doof :P
Silly mistakes on tired eyes.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!