# glBindBuffer in Texturing example

**URL:** <https://forums.imgtec.com/t/glbindbuffer-in-texturing-example/1383>\
**Category:** PowerVR Insider\
**Created:** [April 12, 2012, 7:43pm UTC](https://forums.imgtec.com/t/glbindbuffer-in-texturing-example/1383 "2012-04-12T19:43:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![legion](https://avatars.discourse-cdn.com/v4/letter/l/838e76/32.png) [@legion](https://forums.imgtec.com/u/legion)\
**Post date:** [April 12, 2012, 7:43pm UTC](https://forums.imgtec.com/t/glbindbuffer-in-texturing-example/1383/1 "2012-04-12T19:43:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![legion](https://avatars.discourse-cdn.com/v4/letter/l/838e76/32.png) [@legion](https://forums.imgtec.com/u/legion)\
**Post date:** [April 12, 2012, 8:55pm UTC](https://forums.imgtec.com/t/glbindbuffer-in-texturing-example/1383/2 "2012-04-12T20:55:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![marco](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.imgtec.com/marco/32/96_2.png) [@marco](https://forums.imgtec.com/u/marco)\
**Post date:** [April 13, 2012, 7:21am UTC](https://forums.imgtec.com/t/glbindbuffer-in-texturing-example/1383/3 "2012-04-13T07:21:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![legion](https://avatars.discourse-cdn.com/v4/letter/l/838e76/32.png) [@legion](https://forums.imgtec.com/u/legion)\
**Post date:** [April 13, 2012, 12:37pm UTC](https://forums.imgtec.com/t/glbindbuffer-in-texturing-example/1383/4 "2012-04-13T12:37:45Z")

</div>

Thanks Marco!
