Texture Address Mode Clamping, how does it work?
I'm trying to understand how texture clamping works in OpenGL or any other API f开发者_如何学Pythonor that matter. I am aware of the fact that you define the operation as extending the range from [0,1] to anything, but clamping it to the edge.
So, if I have a pseudocode function:
unsigned int clampedTexel(float u, float v)
{
if(u < 0) u = 0;
if(u >= width) u = width-1;
if(v < 0) v = 0;
if(v >= height) v = height-1;
return image[u][v];
}
Right? So, If I run out of range, like 1.1 in the u direction, why doesn't it get clamped to the black color which is at the end? Rather than black, it goes to white in this example. Have I misunderstood something? Why is the value next to black getting clamped to white?
Or any other extension which is alternating from the edge color. Help me see where I am failing, please.
I think I see the problem. You're overlooking the fact that the top row of the texture is really the "white/black" alternating line, not the "black/white" line it appears to be. So the top row repeating white/black is correct. A similar situation occurs on the right edge where the last column is repeating white/black down rather than black/white.
Here is your texture with its outline:
精彩评论