Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Rendering multiple textures in one glDrawArrays call

  1. #1
    Newbie Newbie
    Join Date
    Mar 2014
    Posts
    2

    Question Rendering multiple textures in one glDrawArrays call

    I have a number of quads being drawn on screen using VBO's with the
    Code :
    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.
    Code :
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, image.image);
     
    glActiveTexture(GL_TEXTURE1);
    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?

    Thanks,
    GGL

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,183
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •