difference of GL_CLAMP and GL_CLAMP_TO_EDGE

B91eae75cd6245bd8074bd0c3f1cc495
0
Nils_Pipenbrinck 101 Mar 20, 2006 at 21:26

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

6 Replies

Please log in or register to post a reply.

820ce9018b365a6aeba6e23847f17eda
0
geon 101 Mar 20, 2006 at 21:33

I believe you can specify wich color the “edge” should be treated as.

B91eae75cd6245bd8074bd0c3f1cc495
0
Nils_Pipenbrinck 101 Mar 20, 2006 at 21:49

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)?

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Mar 21, 2006 at 01:34

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.

B91eae75cd6245bd8074bd0c3f1cc495
0
Nils_Pipenbrinck 101 Mar 21, 2006 at 22:20

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).

105529c025b3f2095e00cdace8a48c58
0
hiji 101 Mar 17, 2010 at 11:19

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.
@Nils Pipenbrinck

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)?

C9dbfdecd7ffe7ec6809e039b4718866
0
Marinity 101 Sep 22, 2010 at 18:22

Thanks, isead about fixing GL_CLAMP to CLAMP_TO_EDGE htlped me