VBOs and multiple textures

Started by
1 comment, last by zalzane 12 years, 3 months ago
First some background, I have terrain information that is loaded and unloaded in chunks depending on a player's position in the world.

Each chunk is loaded into one large VBO. (empty space in the VBO is all zeros)

According to my understanding of textures and VBOs, multiple textures have to be rendered as such:


glBindTexture(GL_TEXTURE_2D,texture1);
glDrawArrays(GL_TRIANGLES, offset1,size1);

glBindTexture(GL_TEXTURE_2D,texture2);

glDrawArrays(GL_TRIANGLES, offset2,size2);

SDL_GL_SwapBuffers();



This is an issue for me because the information has to be loaded into the VBO with its chunk group, and in order to fit the scheme above I would need to break apart each chunk and keep track of where all the individual triangles are for when the chunk needs to be unloaded.

To me that is extremely messy and I would probably kill myself if i actually had to code it.

Is there any other way to do VBOs with multiple textures? Or do all the triangles have to be ordered in the VBO by which texture they use like in the code snip?

Also if you have an answer please expand more than just saying "use texture arrays" or something like that. OpenGL has far too poor of documentation to just google that sort of thing.

Thanks.
Advertisement
You can use index buffers to reference vertices inside a VBO in any order you like.

e.g. given two quads made out of 6 vertices, maybe you want all those triangles to be textured with Tex#1, except for the bottom left triangle, which should use Tex#2
[font=courier new,courier,monospace]1-2-5[/font]
[font=courier new,courier,monospace]|\|\|[/font]
[font=courier new,courier,monospace]4-3-6[/font]

You could create an IBO with a segment for each texture, where,
the indices for texture 1 are: 123,256,632
and the indices for texture 2 are: 341
that makes sense and I got the code working, thank you!

This topic is closed to new replies.

Advertisement