VAO Index Buffer + GL_TRIANGLES: Avoiding flipped textured? + Bleeding Textures?

Hey all, I’ve got a quick (possibly a not-so-quick-to-answer) question about coupling an Index Buffer with a VAO in concurrence with GL_TRIANGLE_STRIP for a heightmap and how I’d go about avoiding flipped textures. Here’s an example of how the Triangle Strip works, and what it’s doing right now as a result. The arrows show the order of which vertex is used and when if GL_TRIANGLE_STRIP is used, as does the Index Buffer.

I know the reason it is flipping the textures, I just don’t know how to efficiently fix it. The reason it’s flipping the textures in every other row is because each vertex, coupled with the Index Buffer, can only correspond to one texture coordinate. As a result when it comes time to render the second row of the heightmap, it renders the top of the square using the bottom right/left (BR and BL) coordinates of the texture, as the vertices making up the top of the square are also the vertices making up the bottom of the square above it. However, I have no clue how I’d go about fixing this without duplicating the vertex data so that each vertex can have two texture coords assigned to it (note this would mean a 128x128 heightmap would require data for 65,278 vertices as opposed to the 32639 vertices that would actually be rendered).

Another issue is that I only have 4 possible texture coordinates, yet I need to duplicate the same 4 texture coordinates multiple times so that the index buffer matches up to the correct texture coordinate for each vertex (ex. if the index is 20 then I need at least 20 texture coords loaded into an array for the index buffer to choose a texture coord for the vertex).

From what I can tell you can only use one Index Buffer with a VAO, whereas with a VBO you can have multiple Index Buffers, for example one Index Buffer for vertices, one for texture coordinates, one for normals, etc. Does anyone know of a way, or is anyone able to think of a way around this that doesn’t include creating tons of useless data that will never be used? I could use a shader to calculate the texture coordinates but I’m writing a game library, not a game, so I want it to be as easy to use as possible (so rather than requiring the use to write a shader specifically for heightmaps, I’d rather have it so the user can write a simple shader that’d be capable of rendering any VAO in the program).

Thanks for the help guys, I’m really stuck on this one. :wink: