glBindBuffer in Texturing example

This topic contains 3 replies, has 2 voices, and was last updated by  Legion 5 years, 8 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #30830

    Legion
    Member

    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?Legion2012-04-12 22:54:00

    #35737

    Legion
    Member

    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.

    #35738

    marco
    Member

    Hi Legion,

    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.

    Regards,
    Marco

    #35739

    Legion
    Member

    Thanks Marco!

Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.