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 5 of 5

Thread: How to render/switch between multiple VBOs?

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2013
    Posts
    12

    Question How to render/switch between multiple VBOs?

    Hi, i currently have a ship, and wish to shoot cannonballs from the ship. The problem is, i do not know how to switch from 1 VBO to another.
    I have tried glBindBuffer(GL_ARRAY_BUFFER, theCannonballBuffer); but that has not worked. I am using glDrawArrays(GL_TRIANGLES, 0, TerrainDemo.theCannonballBuffer.getFaces().size() * 3);

    I am actually using lwjgl instead of opengl, however the calls are the same and the opengl forum is far more helpful.

    Here is the entire relevant code (render method, loading method, etc):
    http://paste.ideaslabs.com/show/z4efZptZDJ

    Is anyone able to tell me what i am doing wrong?

    Here is a screenshot of the problem:
    http://gyazo.com/fe1cb62cd820f91719b4a00828fc2ac6

    Thanks.

  2. #2
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    455
    The buffer bound to GL_ARRAY_BUFFER is used by glVertexAttribPointer (+other gl***Pointer) functions, it isn't actually used by draw calls so has no effect. You need to make the gl***Pointer calls again, or if you use vertex array objects (VAOs) then you can switch VAO which stores all the relevant vertex attribute data.
    The buffer bound to GL_ELEMENT_ARRAY_BUFFER is used by draw call, so does have an effect when draw calls is made + is stored in VAOs.

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2013
    Posts
    12
    Sorry, could you please clarify? I do not know what a VAO is either. I am trying to use a CannonBall VBO, but instead the ship VBO is still being used, and i do not know how to switch to the CannonBall VBO.

    Thanks.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,200
    The way it works is like this.

    First you bind a buffer (using glBindBuffer). Then you make a bunch of glVertexAttribPointer calls. Those glVertexAttribPointer calls take the currently bound buffer and use it for setting up to draw.

    So you want to change your buffer. If you make another glBindBuffer call on it's own, that's not enough. Because the earlier glVertexAttribPointer calls are still using the original buffer. So you need to make your glVertexAttribPointer calls again in order to pick up the new buffer.

    In other words, glBindBuffer on it's own doesn't actually do much. All it does is says "any future GL calls which use a buffer will use this buffer". It also says "any previous GL calls which use a buffer will continue to use the old buffer which was bound at the time they were made". It's the calls you make after glBindBuffer that then pick up the currently bound buffer and do something meaningful with it; in this case changing the vertex attrib pointers.

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2013
    Posts
    12
    Quote Originally Posted by mhagain View Post
    The way it works is like this.

    First you bind a buffer (using glBindBuffer). Then you make a bunch of glVertexAttribPointer calls. Those glVertexAttribPointer calls take the currently bound buffer and use it for setting up to draw.

    So you want to change your buffer. If you make another glBindBuffer call on it's own, that's not enough. Because the earlier glVertexAttribPointer calls are still using the original buffer. So you need to make your glVertexAttribPointer calls again in order to pick up the new buffer.

    In other words, glBindBuffer on it's own doesn't actually do much. All it does is says "any future GL calls which use a buffer will use this buffer". It also says "any previous GL calls which use a buffer will continue to use the old buffer which was bound at the time they were made". It's the calls you make after glBindBuffer that then pick up the currently bound buffer and do something meaningful with it; in this case changing the vertex attrib pointers.
    Thank you very much ! I have now solved the problem.

    Many thanks!

Tags for this Thread

Posting Permissions

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