I am developing an application which integrates Cg vertex and fragment programs with OpenGL API.
I am required to query texels from textures. I know the coordinates of the texel, which I have normalised. Do I pass this as it is after normalisation to my fragment program, so that appropriate texel is queried?
I am confused as for certain cases I got negative x and y coordinates to query; and do not know what this mean. I think -ve x-value means the projected point is not in texture and can be ignored or left as it is. And -ve y-value is because textures are stored from bottom left corner (inverted).
For vertex and fragment programs having “strange” texcoords will simply work. The result is however, dependant from texture object state (mainly wrap mode).
If you want to do it on the CPU, I suggest to just multiply the coord by the texture pixel size and then use the result to look up a 2x2 box of texels in the texcoord array. Lerping this correctly is fairly easy then but there will be some differences (always the same floating point error stuff).