Archived

This topic is now archived and is closed to further replies.

Raloth

VBO texture coords

Recommended Posts

Is there anyway I can store texture coordinates in a VBO? I can''t get them to work just using a vertex array with my other VBOs. There is no token ''GL_TEXTURE_COORD_ARRAY_BUFFER_ARB'' so how am I supposed to do it?

Share this post


Link to post
Share on other sites
Texture coords are part of the vertex data, same as normals, colours and position. If you know how to use vertex arrays, VBO is not much different. Just make sure you allocate enough video memory to store all the vertex data, and then get buffer offsets within that memory block and use them in place of texcoord, normal, colour and position pointers.

Share this post


Link to post
Share on other sites
I''m afraid I don''t understand . I know you can have two buffers mapped at once but I don''t know how to point the texture coordinates to it. Do I just set the texture unit, bind the buffer that has my coordinates, and then call glTexCoordPointer?

Share this post


Link to post
Share on other sites
Just do this to create the buffers:

glGenBuffersARB(1, &vertex_buffer);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertex_buffer);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, size, vertices, GL_STATIC_DRAW_ARB);

glGenBuffersARB(1, &texcoord_buffer);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, texcoord_buffer);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, size, texcoords, GL_STATIC_DRAW_ARB);

then this when you want to use the buffers:

glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertex_buffer);
glVertexPointer(3, GL_FLOAT, 0, 0);
glEnableClientState(GL_VERTEX_ARRAY);

glBindBufferARB(GL_ARRAY_BUFFER_ARB, texcoord_buffer);
glTexCoordPointer(3, GL_FLOAT, 0, 0);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It is not necessary to create that many VBOs. Remember that there is overhead associated with each VBO. Just bind the buffer and call BufferData on the vertex data then just call it again with the texcoord data:

glGenBuffersARB(1, &only_need_one_buffer);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, only_need_one_buffer);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, size, vertices, GL_STATIC_DRAW_ARB);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, size, texcoords, GL_STATIC_DRAW_ARB);

then this when you want to use the buffers:

glBindBufferARB(GL_ARRAY_BUFFER_ARB, only_need_one_buffer);
glVertexPointer(3, GL_FLOAT, 0, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glTexCoordPointer(3, GL_FLOAT, 0, 0);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

Share this post


Link to post
Share on other sites
Thanks, it works now . I noticed that the performance is actually less though than when I was just using a normal vertex array for the texture coordinates. I guess maybe I should stick them in with the vertex data after all...

Share this post


Link to post
Share on other sites