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):
Is anyone able to tell me what i am doing wrong?
Here is a screenshot of the problem:
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.
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.
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.
Originally Posted by mhagain
Tags for this Thread