问题
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.
回答1:
If the squares are adjacent to each other, then use a quad-strip (or a equivalently a triangle-strip):
If the squares are disjoint simply use quads
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.
来源:https://stackoverflow.com/questions/10592974/how-i-can-use-gldrawelements-for-many-squares