Jump to content
  • Advertisement
Sign in to follow this  

Vertex Buffer directx

This topic is 3790 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 folks, i have the problem that this code is part of my very basic application. I dont want to create a new vertexbuffer each frame... i would more likly to change the current vertex buffer. i have the reference t_buffer but that does not help me right now. how can i update my vertexbuffer without creating a new one. or if that fails how can i destroy the old one before creating a new one. thanks for your time Ben
// this is the function that puts the 3D models into video RAM
void init_graphics(void)

	std::vector<float> spec;
	spec.resize(256,0.0f); //fill vector with infos ...

    CUSTOMVERTEX t_vert[512];
	int o = 0;
	for(int i = 0;i<512;i+=2)
		t_vert.X = 10+1*i;
		t_vert.Y = 400.0f-1-400*spec[o++];
		t_vert.Z = 0.5f;
		t_vert.RHW = 1.0f;
		t_vert.COLOR = D3DCOLOR_XRGB(255, 0, 0);

		t_vert[i+1].X = 10+1*i;
		t_vert[i+1].Y = 400.0f;
		t_vert[i+1].Z = 0.5f;
		t_vert[i+1].RHW = 1.0f;
		t_vert[i+1].COLOR = D3DCOLOR_XRGB(255, 255, 0);
    // create a vertex buffer interface called t_buffer
    //how can i change the current one than rather then creating a new one??
    VOID* pVoid;    // a void pointer

    // lock t_buffer and load the vertices into it
    t_buffer->Lock(0, 0, (void**)&pVoid, 0);
    memcpy(pVoid, t_vert, sizeof(t_vert));

Share this post

Link to post
Share on other sites
So, the answer is that you don't need to create vertex buffer every frame, it will degrade your performance. Instead of that make vertex buffer global, and fill it with vertices when you init your application.
If you need to change vertex buffer dynamically (every frame) then create vertex buffer with D3DUSAGE_WRITEONLY |D3DUSAGE_DYNAMIC flags and then with lock and unlock you can access your vertex buffer.

And with DirectX questions, please post in DirectX forum, you can get more accurate answers there.

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!