Jump to content
  • Advertisement


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


Vertex Buffers (D3D 9 Novice Please Help)

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

I''m trying to create a dynamic way of creating and rendering Vertex Buffers, but it just doesn''t work. I don''t get any errors, just nothing shows up. Also this is for use in a Direct 3D 9 wrapper for a Visual Basic project. int renderprimitiveex(egGeometry primitive, int p_start, int p_count, void *p_array) { //Create Vertex Buffer LPDIRECT3DVERTEXBUFFER9 t_VB = NULL; if(SUCCEEDED(g_pd3dDevice->CreateVertexBuffer(3*sizeof(egVertex), 0, D3DFVF_EGVERTEX, D3DPOOL_DEFAULT, &t_VB, NULL))) { //Fill Vertex Buffer VOID* pVertices; if(FAILED(t_VB->Lock(0, sizeof(p_array), (void**)&pVertices, 0))) { return 0; } memcpy(pVertices, p_array, sizeof(p_array)); t_VB->Unlock(); } else { return -1; } //Set Render State g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE); //Render if (SUCCEEDED(g_pd3dDevice->SetStreamSource(0, t_VB, 0, sizeof(egVertex)))) { g_pd3dDevice->SetFVF(D3DFVF_EGVERTEX); g_pd3dDevice->DrawPrimitive(primitive, p_start, p_count); return 1; } else { return 0; } //Else Return -1 return 0; }

Share this post

Link to post
Share on other sites
First, you should never create and delete vertex buffers in your render loop. A better way to do this would be to create your vertex buffer during initialization with the DYNAMIC flag, and then fill it during runtime.

I''m not sure if it''s intentional, but your vertex buffer is only set to hold 3 vertices. Pointing it out just in case

Your variable "VOID* pVertices;" should be of type "egVertex*" instead of "VOID*".

Since your vertex buffer only holds 3 vertices, I hope that "p_start" is 0 and "p_count" is 1.

Also, you never actually destroy your vertex buffer. This creates a memory leak that could cause unexpected results in the rest of your app. If you''re going to create a vertex buffer in your render loop (bad idea to begin with, but oh well), then make sure you delete it when you''re done.


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!