I have a game where each "tile" of the terrain is a triangle (Settlers 2). Those are placed next to each other and in way creating an infinite world (right/bottom jumps back to left/top). There is a 3D component (each triangle point has a height) but that gets translated into an Y-position offset, so everything can be considered 2D.
Everything (texture coords, screen coords, color (white<->black, FoW)) is put into VBOs already and usually does not change (FoW may disappear which updates the color VBO, but rarely)
When drawing I iterate over the visible tiles (currently in view) and collect "runs" of tiles with the same texture. After that I do:
- Bind current texture
- Draw current run (offset into VBOs + num of same textured tiles)
- Repeat until all runs are drawn
To reduce the number of texture switches I wanted to create a texture atlas. But the problem: Some textures are animated (texture animation so all tiles use the same frame of the animation at any given time) and those animations may be different.
To give some numbers:
- ~30 textures, pretty small (~30-60px each)
- 8 are animated, rest static
- animation length is 4-8 frames
- animation frame time is constant
How would I best go with those animations?
- Put all static textures into 1 texture, animated ones into separate ones?
- Unroll animations so I have ~8 textures (possibly 24 if I have 8 frame and 6 frame animations) where each texture is 1 frame (so static textures are copied into those unmodified)
- Repeat all textures into 1 texture and do some U-coordinate shifting in a shader (not used ATM, but will add soon) -> again possible waste
- Some shader magic?
Using OpenGL 2.1, C++.
Visualization of 3 textures: Triangles cut out from squares in any position (in fact only 6 are possible: Top to bottom, top to middle, top to middle rotated by 135° and their mirrored counterparts). Shown is 1 of 2 triangles per square, the other one is mirrored horizontally. All tiles may have different sizes