- April 12, 2012 at 9:43 pm #30830
I’m working my way through your texturing example in your training course. One thing that isn’t clear to me is why you bind the buffer twice. First in your init function. This makes sense to me, it’s also here where you pass the array containing all the vertex data.
But then in your RenderScene function you rebind the VBO and make two calls to glEnableVertexAttribArray and glVertexAttribPointer. Once for the vertex data and once for the textures. The comments say you’re passing the vertex and texture data, but it doesn’t look like you are, because you just pass a 0 or a void pointer. Not to mention the vertex data has already been passed in the init and I thought the whole point of VBOs was that it caches the data on the GPU so you don’t have to keep sending the information over.
So, can you explain why you make those calls again in the RenderScene function but with a 0 value or void pointer?
Legion 2012-04-12 22:54:00April 12, 2012 at 10:55 pm #35737
OK, I think I figured it out. Instead of passing in an array of data, because you’re using a VBO, you’re passing an offset into the vertex structure. I guess that’s how OpenGL is able to distinguish position data from texture data when it’s interleaved.April 13, 2012 at 9:21 am #35738
the first call in InitView() binds the buffer and uploads the data (vertices and texture coordinates).
The second call in RenderScene() binds the buffer and tells GL the offsets of the vertices and texture coordinates relative to the buffer start.
Yes, you’re right, that is how OpenGL distinguishes the individual elements.