Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: UV and position coords in the same VBO

  1. #1
    Intern Contributor
    Join Date
    Jun 2012

    UV and position coords in the same VBO

    Now that I've finally gotten a VBO and IBO to work, I'm trying to get a simple .bmp texture to display properly. I have my vertex data in a float array of the form
    Code :
    float[] vertices = { x1, y1, z1, u1, v1, x2, y2, z2, u2, v2, etc. }
    and I store that in a VBO in the init section, store indices in an IBO, then use glDrawElements() in the draw section to draw everything. Also, in the init section, I load a texture. I know I do that correctly, since when I use glBindTexture, draw a simple triangle using glBegin() and glEnd(), and use glTexCoord to assign uv coords to vertices, it comes out as it should.

    My problem is that I can't seem to move from that to using VBO uv data. I don't know how to get the code to recognize the u and v floats in the vertex array as uv coordinates, and I can't get it to apply the texture to the shape I draw using glDrawElements. When I just have glBindTexture followed by the glDrawElements bit to draw the square, I get the same untextured red square as when I don't have a texture at all, only it's somewhat darker.

    Kopelrativ's first post here leads me to suspect I need to do something with shaders, but I'm not sure what I need to do with them. What's the equivalent for glTexCoord when using VBOs and IBOs? How come glDrawElements drew an untextured object just fine without my having to write custom shaders? Can I still use glBindTexture, or do I have to use some kind of Texture Buffer Object?

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    I'm assuming that you're using old-style vertex array calls here (if you weren't you'd know it) so what you need to do is look at glTexCoordPointer and it's associated EnableClientState (GL_TEXTURE_COORD_ARRAY). Otherwise nothing changes.

  3. #3
    Intern Contributor
    Join Date
    Jun 2012
    I don't have any glEnableClientState for the glDrawElements, nor do I have a glVertexPointer, and yet the untextured triangles show up fine:
    Code :
                gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, vertexBufferObjectIds[0]);
                gl.VertexAttribPointer(0, 3, OpenGL.GL_FLOAT, false, (5 * sizeof(float)), new IntPtr(0));
                gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, indexBufferObjectIds[0]);
                gl.DrawElements(OpenGL.GL_TRIANGLES, 6, OpenGL.GL_UNSIGNED_INT, new IntPtr(0));
                gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, 0);
                gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, 0);
    Is that what you mean by old-style vertex array calls?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts