Jump to content


difference of GL_CLAMP and GL_CLAMP_TO_EDGE


6 replies to this topic

#1 Nils Pipenbrinck

    Senior Member

  • Members
  • PipPipPipPip
  • 597 posts

Posted 20 March 2006 - 09: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

#2 geon

    Senior Member

  • Members
  • PipPipPipPip
  • 939 posts

Posted 20 March 2006 - 09:33 PM

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

#3 Nils Pipenbrinck

    Senior Member

  • Members
  • PipPipPipPip
  • 597 posts

Posted 20 March 2006 - 09: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)?

#4 Reedbeta

    DevMaster Staff

  • Administrators
  • 5311 posts
  • LocationSanta Clara, CA

Posted 21 March 2006 - 01:34 AM

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.
reedbeta.com - developer blog, OpenGL demos, and other projects

#5 Nils Pipenbrinck

    Senior Member

  • Members
  • PipPipPipPip
  • 597 posts

Posted 21 March 2006 - 10: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).

#6 hiji

    New Member

  • Members
  • Pip
  • 1 posts

Posted 17 March 2010 - 11: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.

Nils Pipenbrinck said:

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

hiji :)

#7 Marinity

    New Member

  • Members
  • Pip
  • 1 posts

Posted 22 September 2010 - 06:22 PM

Thanks, isead about fixing GL_CLAMP to CLAMP_TO_EDGE htlped me





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users