So I am using a texture atlas with resolution 32x32. It is 23x21 tiles. I have generated a plane of 10x10 points for the model, and created indices and texture coordinates to match. The texture coordinates map the entire tilesheet to the plane created.
What I am doing now is taking sub images. I have done it before, but with a different, really complex and bad way (drawing a quad for each square using glDrawElements()).
So I took the map and I multiplied it by the amount of tiles. This gives me 10x10 tiles, each with a tileset texture. My problem here is I can’t manipulate these individual tiles further to isolate a specific tile from the tileset.
#version 120
in vec2 position;
in vec2 texcoord;
in float index;
out vec2 pass_texcoord;
uniform mat4 matrix_projection, matrix_transform, matrix_camera;
uniform sampler2D u_texture0;
uniform ivec2 texture_size;
uniform ivec2 stride;
uniform ivec2 map;
uniform ivec2 tiles;
void main(void) {
float xratio = float(stride.x)/float(texture_size.x);
float yratio = float(stride.y)/float(texture_size.y);
float yoffset = floor(index/float(tiles.x));
// pass_texcoord = vec2(texcoord.s*xratio + mod(index, tiles.x)*xratio, texcoord.t*yratio + yoffset*yratio);
pass_texcoord = vec2(texcoord.s * map.x, texcoord.t * map.y);
gl_Position = matrix_projection * matrix_transform * matrix_camera * vec4(position, 0, 1);
}
What am I missing?