# How do I structure code with multiple VBOs?

As per my previous question, it seems it would be desirable to use more than a single VBO in my OpenGL program. But I've hit a wall when trying to do this. Currently my main function looks something like this in pseudocode

setup "main" VBO and VAO

while true
update geometry into "main" VBO
glBufferData(... "main" VBO)
glClear(GL_COLOR_BUFFER_BIT)
glDrawArrays(...)


Now what I thought I could do is effectively move the setup "main" VBO inside the game loop itself

setup VAO

while true
setup "main" VBO
update geometry into "main" VBO
glBufferData(... "main" VBO)
glClear(GL_COLOR_BUFFER_BIT)
glDrawArrays(...)


which would then allow me to split the loop into multiple chunks, each creating its own VBO and drawing. But this doens't seem to work, and I get a blank white screen. I can only guess this is because the shaders are not only bound to the VAO, but also to the currently active VBO? I've tried glUseProgram() after the "main" VBO setup, but it doesn't seem to help.

I've found it quite difficult to find information regarding which phase exactly depends on which, and in what order things need to be executed.

• Shaders are not bound to the VBO. – immibis Mar 16 '16 at 8:54
• Are you making a new VBO on every step? Are you calling glBindBuffer on every step? Your pseudocode seems OK, so we'd have to see more realistic code to diagnose. I would recommend you check out the OpenGL Superbible ("blue book") – Nox Mar 16 '16 at 12:36

• A difference between BufferData and BufferSubData is that BufferData may reshape the buffer, while BufferSubData is stuck with the initial configuration. This matters even more if you use BufferStorage to make buffers of immutable shape, upon which it's an error to BufferData even if you specify identical sizes. – Lars Viklund Mar 22 '16 at 22:04