I’m using OpenGL to render a 2D tile map, and so far everything’s working quite well; Each tile is specified in vertices as a series of two triangles (6 points), which have been loaded into a buffer and drawn using glDrawArrays in mode GL_TRIANGLES. These vertices are specified in relation how far along the viewport they should be rendered (e.g. To render the sprite in the centre of the viewport, the x component of the vertex would be ‘0.5’).
Likewise I have an almost identical series of texture coordinates per sprite (two triangles) except the texture coordinates are specified in relation to how far along the texture they’re positioned. So far so good.
In the case of the vertices it’s fine that these coordinates never change, as I can just pass the camera scroll offsets into the vertex shader and move them along manually, but for the texture coordinates, these values can change entirely depending on what tiles are visible in the viewport.
How would you normally specify texture coordinates for scrolling tile maps? Is it common for the buffer to be re-initialised with the new texture coordinates as new tiles are revealed, or is there a cleaner way of achieving this?
This might be a vague question so I can clarify things if necessary. Any help appreciated.