1

I am developing a 2D Open GL game and i have to draw many squares on screen for a tilemap, with a diferent glTexCoordPointer from the texture.

Now, I don't know how to use Gldrawelements for draw many squares, which would be the structure of the indices if I want to draw many squares?

And, how can I put each array (vertices), which contains the coordinates of each square on the vertexbuffer?

Also, will it be possible to set different glTexCoordPointer for each square in just one call to the method or is necessary a loop like with GlDrawArrays? But, I want to use gldrawelements because i dont want to make a loop which execute many times gldrawarrays for each square, my fps drops notably.

Alex Hadley
  • 2,125
  • 2
  • 28
  • 50
Jose
  • 129
  • 1
  • 9

1 Answers1

2

If the squares are adjacent to each other, then use a quad-strip (or a equivalently a triangle-strip):

quad-strip of adjacent quads

If the squares are disjoint simply use quads

enter image description here

You can also use a quad-strip (equivalently a triangle-strip) in this case by adding degenerate quads (triangles):

GLushort indices[] = {A, B, C, D, D, E, E, F, G, H, H, I, I, J, K, L}

Two squares with the same vertex positions, but different texture coordinates must be represented with different quads.

wcochran
  • 10,089
  • 6
  • 61
  • 69