I am using the scanline algorithm to draw the triangle and interpolate texture coordinates.
after interpolating the (u,v) at a pixel I get the corresponding textel position like this:
1 2 3
int textureX = u * (texture.width - 1) + 0.5f;
int textureY = v * (texture.height - 1) + 0.5f;
// plot the pixel with color texture[textureX][textureY];
what could the problem be.
I was interpolating U and V but that was a mistake because they are not linear functions,
I had to interpolate U/Z and V/Z instead and then multiply both of them by Z to get the correct result.