Search code examples
opengltexturesmode

Texture Address Mode Clamping, how does it work?


I'm trying to understand how texture clamping works in OpenGL or any other API for 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];

}


(source: sud at wwwx.cs.unc.edu)

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.


Solution

  • 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:

    enter image description here