Question Regarding VBO/VAO and Attributes

Hi,

I am starting to learn GLSL, and have been working on a simple tutorial that involves drawing a triangle with different colored vertices. So far however, I have only been able to change the vertex color attribute with a VBO. Is there an alternative method of linking attributes (not just color) to vertices?

Additionally I have run into a strange problem with the VAO/VBO setup. If I place all of the calls in the draw function, the triangle draws. If I place all of the calls except for the glBindVertexArray and glDrawArrays in the init function, and then place those two commands in the draw function, the screen becomes blank… Also, the vaoHandle which is being called is “Global”. Does anyone have any ideas what might cause this problem?

Thanks.

A vertex array object is a mechanism to aggregate state, i.e. pointers and buffer bindings. At init time you need to generate AND bind the VAO, then generate, bind and setup your VBO and (optionally) your IBO and your attribute pointers.

At render time, you just need to bind the VAO and issue the corresponding draw call.

Referring to your VBO trouble, you can change the data of the buffer object as much as you want. You only need to be consistent with your buffer layout and the attribute pointers. For instance, your VBO could comprise only vertices - or it could use vertices and vertex normals, or addtionally colors.

There are also several memory layout schemes. Packing the data means to tightly concatenate attributes, i.e. vertices first, then normals, then tex coords and so on. Another common case is interleaved data, i.e. vertex0,normal0, texcoord0, vertex1,normal1,texcoord1, …

If you want to change the data of your VBO, you need to be aware of the layout of the buffer. If you know what to change, bind the buffer, use glBufferData to change the whole buffer or use glBufferSubdata/glMapBuffer(don’t forget to unmap afterwards) to change portions of the buffer indicated by the memory layout.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.