VBO texture coords

Started by
6 comments, last by Raloth 20 years, 7 months ago
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?
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
Advertisement
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.

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

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.
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
I didn''t say you can''t use separate buffers. Take a look at the last example in the spec.

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

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?
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
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);
---I write code.DelphiGL (http://delphigl.cfxweb.net)
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);
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...
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...

This topic is closed to new replies.

Advertisement