Jump to content
  • Advertisement

Archived

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

MatthewB

The Vertex Buffer & Multiple Models

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

Ok, here's the problem. The most detailed example I have of filling a vertex buffer is from the very good book: "Special Effects Game Programming with DirectX." However, the example source code only loads a single object, one triangle.
    
HRESULT InitGeometry()
{
    // Initialize three vertices for rendering a triangle

    CUSTOMVERTEX g_Vertices[] =
    {
        { -1.0f,-1.0f, 0.0f, 0xffff0000, },
        {  1.0f,-1.0f, 0.0f, 0xff0000ff, },
        {  0.0f, 1.0f, 0.0f, 0xffffffff, },
    };

    // Create the vertex buffer.

    if( FAILED( g_pd3dDevice->CreateVertexBuffer( 3*sizeof(CUSTOMVERTEX),
                                                  0, D3DFVF_CUSTOMVERTEX,
                                                  D3DPOOL_DEFAULT, &g_pVB ) ) )
    {
        return E_FAIL;
    }

    // Fill the vertex buffer.

    VOID* pVertices;
    if( FAILED( g_pVB->Lock( 0, sizeof(g_Vertices), (BYTE**)&pVertices, 0 ) ) )
        return E_FAIL;
    memcpy( pVertices, g_Vertices, sizeof(g_Vertices) );
    g_pVB->Unlock();

    return S_OK;
}
    
Since I do not know the exact number of models whose vertices I will be loading I need to be able to dynamically allocate the individual vertex buffers. I assume that you normally only have one buffer per model, maybe I'm wrong. Which of the following variables actually is the buffer: g_pVB OR g_Vertices? At first I thought that the g_pVB was, but then it gets copied into p_Vertices. So is g_pVB now free for me to use for the next model. BTW, I am loading my models in a loop, so using my counter as an index in an array had occurred to me, but when I declared g_pVB as a *g_pVB and then used it in the CreateVertexBuffer function as &g_pVB[count], I am unable to use the Release() member function with it later. If anyone has some simple (haha) source code that shows how to load multiple models into the vertex buffer, I would much appreciate it. Thanks. [edited by - MatthewB on December 27, 2002 8:03:06 AM]

Share this post


Link to post
Share on other sites
Advertisement
Does anyone have any more insight into vertex buffers than me? I have seen lots of "beginner" examples, but they all load vertices for ONE triangle or else load ONE mesh from an .x file. I am stuck until I can figure this out. Any help will be appreciated.
.... Getting desperate

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!