Jump to content
  • Advertisement


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


vertex buffer updating

This topic is 5547 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''ve got quite a simple problem that i just can''t seem to find the right documentation to solve. I using DX 9.0a and I''ve created a vertex buffer using a function InitVB(): HRESULT InitVB() { // Initialize 2 sets of four vertices for rendering 2 trianglestrips CUSTOMVERTEX vertices[] = { { 100.0f+a.x, 250.0f-(a.y*140.0f), 0.5f, 1.0f, 0xffffffff, 0.0f, 1.0f}, // x, y, z, rhw, color { 100.0f+a.x, 200.0f-(a.y*140.0f), 0.5f, 1.0f, 0xffffffff, 0.0f, 0.0f}, { 150.0f+a.x, 250.0f-(a.y*140.0f), 0.5f, 1.0f, 0xffffffff, 1.0f, 1.0f}, { 150.0f+a.x, 200.0f-(a.y*140.0f), 0.5f, 1.0f, 0xffffffff, 1.0f, 0.0f}, }; CUSTOMVERTEX verticesb[] = { { 150.0f+b.x, 250.0f-(b.y*140.0f), 1.0f, 1.0f, 0xffffffff, 0.0f, 1.0f}, // x, y, z, rhw, color { 150.0f+b.x, 200.0f-(b.y*140.0f), 1.0f, 1.0f, 0xffffffff, 0.0f, 0.0f}, { 200.0f+b.x, 250.0f-(b.y*140.0f), 1.0f, 1.0f, 0xffffffff, 1.0f, 1.0f}, { 200.0f+b.x, 200.0f-(b.y*140.0f), 1.0f, 1.0f, 0xffffffff, 1.0f, 0.0f}, }; // Create the vertex buffer. Here we are allocating enough memory // (from the default pool) to hold all our 3 custom vertices. We also // specify the FVF, so the vertex buffer knows what data it contains. if( FAILED( g_pd3dDevice->CreateVertexBuffer( 4*sizeof(CUSTOMVERTEX), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL ) ) ) { return E_FAIL; } if( FAILED( g_pd3dDevice->CreateVertexBuffer( 4*sizeof(CUSTOMVERTEX), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVBb, NULL ) ) ) { return E_FAIL; } // Now we fill the vertex buffer. To do this, we need to Lock() the VB to // gain access to the vertices. This mechanism is required becuase vertex // buffers may be in device memory. VOID* pVertices; if( FAILED( g_pVB->Lock( 0, sizeof(vertices), (void**)&pVertices, 0 ) ) ) return E_FAIL; memcpy( pVertices, vertices, sizeof(vertices) ); g_pVB->Unlock(); VOID* pVerticesb; if( FAILED( g_pVBb->Lock( 0, sizeof(verticesb), (void**)&pVerticesb, 0 ) ) ) return E_FAIL; memcpy( pVerticesb, verticesb, sizeof(verticesb) ); g_pVBb->Unlock(); return S_OK; } However, I''m currently using this function in my main game loop to update teh information stored in these two vertex buffers, which is causing the program to crash by making the system fill the memory with updated versions of these buffers rather than updating just one copy of the buffers. I tried using g_pVB->Release to scrap the vertex buffer and start again each game loop, but of course this failed, what I need is a cut down copy of this function that updates the buffer rather than filling the memory, so I can use that function instead once within the game loop. I tried to implement a UpdateVB() function using just the last bit of the above code where it locks and updates the buffer, but of course it gave problems with vertices and verticesb being declared in InitVB(), leading me to maybe think I should create a ManipulateVB class which contains both the two functions and all the necessary declarations. What should I do? thanks very much for any replies

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!