VBO texture coords
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?
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.
You mean there is no way to put them in separate buffers? That would be best for me since my vertex data is dynamic but my texture coordinates are going to be static.
I didn''t say you can''t use separate buffers. Take a look at the last example in the spec.
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?
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);
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);
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);
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);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement