View Full Version : Rendering multiple textures in one glDrawArrays call

03-25-2014, 01:59 PM
I have a number of quads being drawn on screen using VBO's with the
glDrawArrays call and I was wondering if it is possible to draw different textures onto each of these quads because they are in the same draw call and in the same vbo?

The problem is, if I were to bind a number of textures (like in the code below) then ALL the quads would have the last bound texture.

glBindTexture(GL_TEXTURE_2D, image.image);

glBindTexture(GL_TEXTURE_2D, image.image);

So can I use the two bound textures above on two different quads rendered in the same glDrawArrays call and if so how is this possible?


03-25-2014, 03:43 PM
A few different ways of doing this.

If your textures don't need mipmaps and don't repeat you could pack them all into a texture atlas and adjust your texcoords for sub-rectangles within that atlas.

If they're all square, all the same size, and you have no more than 6, you could put them on different faces of a cubemap.

The above two methods will work on really old hardware. A slightly more modern approach would be to use a texture array; this retains the restriction that all of your textures should be the same size, but otherwise you'd add an additional vertex attrib to your vertex layout specifying which array slice to use. That would be my own preferred approach.