Jump to content
  • Advertisement
Sign in to follow this  
flyslasher

Vertex Buffer Array...?

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

Is this the correct way to 1. create and 2. draw a vertex buffer array?

1. Creating

    m_vObjectList.at( uiObjectID )->m_uiTexture = SOIL_load_OGL_texture( pchFile, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_COMPRESS_TO_DXT );
    m_vObjectList.at( uiObjectID )->m_iTextureWidth = iWidth;
    m_vObjectList.at( uiObjectID )->m_iTextureHeight = iHeight;

    GLfloat fVerticeData[12] = { 0, 0, 0, 0, (float)iHeight, 0, (float)iWidth, (float)iHeight, 0, (float)iWidth, 0, 0 };
    GLfloat fTexCoordData[8] = { 0, 0, 0, 1, 1, 1, 1, 0 };

    glGenBuffers( 2, m_vObjectList.at( uiObjectID )->m_uiTextureBuffer );

    glBindBuffer( GL_ARRAY_BUFFER, m_vObjectList.at( uiObjectID )->m_uiTextureBuffer[0] );
    glBufferData( GL_ARRAY_BUFFER, sizeof( fVerticeData ), fVerticeData, GL_STATIC_DRAW );

    glBindBuffer( GL_ARRAY_BUFFER, m_vObjectList.at( uiObjectID )->m_uiTextureBuffer[1] );
    glBufferData( GL_ARRAY_BUFFER, sizeof( fTexCoordData ), fTexCoordData, GL_STATIC_DRAW );

 

2. Drawing

for( size_t i = 0; i < m_vInstanceList.size(); ++i )
    {
        glPushMatrix();

        glBindBuffer( GL_ARRAY_BUFFER, m_vObjectList.at( m_vInstanceList.at( i )->m_uiObject )->m_uiTextureBuffer[0] );
        glEnableClientState( GL_VERTEX_ARRAY );
        glVertexPointer( 3, GL_FLOAT, 0, (void*)0 );

        glActiveTexture( m_vObjectList.at( m_vInstanceList.at( i )->m_uiObject )->m_uiTexture );
        glBindBuffer( GL_ARRAY_BUFFER, m_vObjectList.at( m_vInstanceList.at( i )->m_uiObject )->m_uiTextureBuffer[1] );
        glEnableClientState( GL_TEXTURE_COORD_ARRAY );
        glTexCoordPointer( 2, GL_FLOAT, 0, (void*)0 );

        glTranslated( m_vInstanceList.at( i )->m_iPosition[0], m_vInstanceList.at( i )->m_iPosition[1], 0 );

        glDrawArrays( GL_QUADS, 0, 4 );

        glDisableClientState( GL_VERTEX_ARRAY );
        glDisableClientState( GL_TEXTURE_COORD_ARRAY );

        glPopMatrix();
    }
Edited by PandaDragonThing

Share this post


Link to post
Share on other sites
Advertisement

Technically it is correct, yes. At initialization, I presume, you're creating the buffer object and filling it with data, and when drawing, you just bind the buffers and draw them

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!