Hey guys, I've encountered the exact same as issue as the OP but the solution hasn't worked for me. Its probably because my setup is slightly different and I haven't understood the way the texture_coords work. The result i'm getting is what looks like slices of several sprites grouped together, the result is very weird.
Some background:
I have a 832x64 spritesheet, with 13 sprites in total. Each sprite is 64x64. Therefore my quads are like
0,0 64,0 128,0 192,0 and so on.
I am a bit confused how things are actually working in the code snippet provided by pgimeno.
My question:
If my understanding is correct the following line is executed for every pixel in the Texture, which is going to be the entire sprite sheet in this case because as pgimeno explained love2d sends the entire sprite sheet to the shader not just the quad.
Code: Select all
vec2 quad_coords = vec2((texture_coords.x * iw - qx) / qw, (texture_coords.y * ih - qy) / qh);
Assuming the love.draw function has been called with the first quad, we will have the following values for the extern variables:
qx = 0, qy = 0, qw = 64, qh = 64, iw = 832, ih = 64;
So now for the first iteration of the above line of code, i'm assuming the shader will start in the top left corner of the texture, so texture_coords.x will be 0.
Code: Select all
x is = (0 * 832 - 0) / 64 = 0
y is = (0 * 64 -0) / 64 = 0
that looks fine, but say next pixel being operated on is x = 0.1,y=0 (to be honest I'm not sure if this will infact be the 2nd pixel), so now
Code: Select all
x is = (0.1 * 832 - 0) / 64 = 1.3
y is = (0 * 64 - 0) / 64 = 0
So now looks like x has exceeded 1? And in a lot of threads what I've read is that texture_coords are between 0 and 1. Not sure whats going on. And I'm sure pgimeno's solution worked for the OP, which means I'm doing something silly.
Any help would be appreciated. Very confused.
Thanks