PDA

View Full Version : difference of GL_CLAMP and GL_CLAMP_TO_EDGE


Nils Pipenbrinck
03-20-2006, 01:26 PM
Does someone knows the exact difference between those two?

I had some problems using GL_CLAMP today. When I use it and the UV-coordinates go out of the 0..1 range something black gets blended into my texels (all my texels that are out of the 0.1 range are exactly halfed in value. on the extreme edges (where u and v are out of range) I have 1/4 of my color.

GL_CLAMP_TO_EDGE get's rid of that effect and clamps as I would expect it (or better said - as I know clamping from d3d)

I wonder: The spec sais: GL_CLAMP clamps the texture coordinates to 0 and 1. That would be perfectly fine for me, but somehow black blends into the pixels (even if my texture is entirely white).

Any idea?
Nils

geon
03-20-2006, 01:33 PM
I believe you can specify wich color the "edge" should be treated as.

Nils Pipenbrinck
03-20-2006, 01:49 PM
Ok, so I can somehow specify the "outside of the texture" color, and OpenGL blends towards that color up to 0.5f.

And CLAMP_TO_EDGE just clamps to the edge-texels and ignores the outside-color (as I would expect clamping to work in the first place)?

Reedbeta
03-20-2006, 05:34 PM
Correct. The border colors can be set when you specify the texture image with glTexImage2D, though I've never used this feature and can't think of a situation where it would be useful...GL_CLAMP_TO_EDGE clamps to [0 + 0.5*texel, 1 - 0.5*texel]. Since the texel centers are considered to be at 0.5's in OpenGL, clamping to [0, 1] causes bilinear filtering between the edge pixels and the border colors to kick in.

Nils Pipenbrinck
03-21-2006, 02:20 PM
Thanks a lot. that makes sense. I now changed all my references to GL_CLAMP to CLAMP_TO_EDGE. That's all I have on OpenGL/ES anyways (my target api).

hiji
03-17-2010, 04:19 AM
Thank you so much for clarifying this, GL_CLAMP to CLAMP_TO_EDGE also solved my issue. I was stuck on it from last couple of days but just got it and its working fine now.

Ok, so I can somehow specify the "outside of the texture" color, and OpenGL blends towards that color up to 0.5f.

And CLAMP_TO_EDGE just clamps to the edge-texels and ignores the outside-color (as I would expect clamping to work in the first place)?