2
« on: August 19, 2024, 10:03:52 am »
I am trying to draw a 2D terrain. I have defined a heightmap, created a VertexArray of type Triangles, and populated it with the vertices of my heightmap. Specifying vertex colors works great, but I am now trying to use textures instead.
I have a texture atlas (e.g. see attached) that contains sub-textures for the different areas (e.g. grass, rock, etc.). I need to have those sub-textures tile across the triangles because some triangles are bigger than the sub-texture and most do not align with a texture boundary. Note that I am using an irregular grid (think something derived from a voronoi diagram) for the heightmap, so using grid-aligned quads is not possible.
When I set the texture to repeat, and specify texture coordinates, it tiles the whole texture atlas, not just a single texture. I can make this work (e.g. see attached) by breaking the atlas into individual textures, and creating one VertexArray per area (e.g. grass, rock, etc.). However, this means I must use a single texture across an area, with no ability to vary the texture, unless I create more individual textures and VertexArrays.
Is there another way to accomplish tiling of a sub-texture in an atlas? Does the question make sense?