Sign in to follow this  
flyslasher

Vertex Buffer Array...?

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this