Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: VBO not working

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2009
    Posts
    2

    VBO not working

    Hi everybody, let me get straight to the point. I've got some code from somewhere to build and use a VBO, but it's not working at all. I'm pretty sure a more experienced person would see whats wrong with this in an instance. It all compiles without errors or warnings. So let me show you my code:

    I'm loading in a heightmap and parse the vertex, uv and normal buffer I generate to this function. This is called once after I created the heightmap.
    Code :
    unsigned int GraphicsManager::createVBO(int size, Vector3* mVertexBuffer, Vector3* mNormalBuffer, Vector2* mUvBuffer)
    {
    	unsigned int id = mGraphicsManagerPimpl.mVboDictionary.size();
     
    	VboIdCollection* ids = new VboIdCollection();
    	ids->size = size;
     
    	glGenBuffersARB( 1, &ids->vId );
    	glBindBufferARB( GL_ARRAY_BUFFER_ARB, ids->vId );
    	glBufferDataARB( GL_ARRAY_BUFFER_ARB, size*3*sizeof(float), mVertexBuffer, GL_STATIC_DRAW_ARB );
     
    	glGenBuffersARB( 1, &ids->nId );
    	glBindBufferARB( GL_ARRAY_BUFFER_ARB, ids->nId );
    	glBufferDataARB( GL_ARRAY_BUFFER_ARB, size*3*sizeof(float), mNormalBuffer, GL_STATIC_DRAW_ARB );
     
    	glGenBuffersARB( 1, &ids->uvId );
    	glBindBufferARB( GL_ARRAY_BUFFER_ARB, ids->uvId );
    	glBufferDataARB( GL_ARRAY_BUFFER_ARB, size*2*sizeof(float), mUvBuffer, GL_STATIC_DRAW_ARB );
     
    	mGraphicsManagerPimpl.mVboDictionary.insert(std::make_pair(id, ids));
     
    	return id;
    }

    And here's the code I call every frame when I want to display the VBO.
    Code :
    void GraphicsManager::drawVBO(unsigned int id)
    {
    	vboIdcollection* ids = mGraphicsManagerPimpl.mVboDictionary.find(id)->second;
     
    	glBindBufferARB( GL_ARRAY_BUFFER_ARB, ids->vId );
    	glVertexPointer( 3, GL_FLOAT, 0, (char *) NULL );
     
    	glBindBufferARB( GL_ARRAY_BUFFER_ARB, ids->nId );
    	glNormalPointer( GL_FLOAT, 0, (char *) NULL );
     
    	glBindBufferARB( GL_ARRAY_BUFFER_ARB, ids->uvId );
    	glTexCoordPointer( 2, GL_FLOAT, 0, (char *) NULL );
     
    	glDrawArrays( GL_TRIANGLES, 0, ids->size );
     
    	glDisableClientState( GL_VERTEX_ARRAY );
    	glDisableClientState( GL_TEXTURE_COORD_ARRAY );
    	glDisableClientState( GL_NORMAL_ARRAY );
    }

    I would really appreciate the help.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Dec 2000
    Location
    Reutlingen, Germany
    Posts
    2,052

    Re: VBO not working

    You do not call

    glEnableClientState( GL_VERTEX_ARRAY );
    glEnableClientState( GL_TEXTURE_COORD_ARRAY );
    glEnableClientState( GL_NORMAL_ARRAY );

    at least not in the given code.

    Jan.
    GLIM - Immediate Mode Emulation for GL3

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2009
    Posts
    2

    Re: VBO not working

    Oh man I feel like a complete idiot right now :P. It works perfectly though . My FPS just quadrupled. succes \o/ Thanks alot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •