Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am working through some beginner OpenGL tutorials, and the current one teaches how to apply a texture to a simple rectangle. The tutorial states tells me to set the texture parameters GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T to GL_CLAMP_TO_EDGE, however I am uncertain as to what this actually does. I am aware it is something to do with how textures larger/smaller than the space they are being mapped onto are handled, but I'm not sure what behavior this actually causes. What does GL_CLAMP_TO_EDGE do, and how is this different from GL_CLAMP, GL_CLAMP_TO_BORDER, GL_REPEAT? Thanks very much in advance, and bonus helpfulness if you can provide images for an idiot like me.

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

Well S and T just mean U and V (or X and Y if you prefer), or in GLSL:

vec4.xyzw == vec4.rgba == vec4.strq

The GL_REPEAT mode has textures repeat when you go past (0,0) to (1,1) range

The GL_CLAMP_TO_EDGE mode has textures stop at the last pixel when you fall off the edge.

The GL_CLAMP and GL_CLAMP_TO_BORDER are depreciated because all texture borders must be 0 pixels, so the modes don't make sense anymore. (somewhere around GL3 I believe)


There are some good examples on http://www.flipcode.com/archives/Advanced_OpenGL_Texture_Mapping.shtml, here is a preview:

Wrap S : GL_CLAMP / Wrap T : GL_CLAMP

clamp clamp

Wrap S : GL_CLAMP / Wrap T : GL_REPEAT

clamp repeat

Wrap S : GL_REPEAT / Wrap T : GL_CLAMP

repeat clamp

Wrap S : GL_REPEAT / Wrap T : GL_REPEAT

repeat repeat

share|improve this answer
    
Thanks. Great answer. Do you know if there is any difference between GL_CLAMP_TO_EDGE and GL_CLAMP, and if there is anyway of just getting the texture to expand to fill the available space? –  handuel Sep 22 '13 at 15:00
    
Sorry for not clarifying, where I say CLAMP I mean GL_CLAMP_TO_EDGE, GL_CLAMP is gone in modern OpenGL. I'll edit the answer to emphasize that. –  MickLH Sep 22 '13 at 15:16
    
As for "expanding" if you simply mean stretching the texture into a different range, that should be handled during mesh parameterization. (UV mapping, artists job).. If you really must do it pragmatically then you will have to write your own formula to use in a shader. (Or I guess GL_TEXTURE matrix if your app is severely outdated already :P) –  MickLH Sep 22 '13 at 15:29
add comment

Here is an extract of the OpenGL Reference page on glTexParameter as of 2014/02/07, formatted a bit for easier reading:

GL_TEXTURE_WRAP_S

Sets the wrap parameter for texture coordinate s to either GL_CLAMP_TO_EDGE, GL_CLAMP_TO_BORDER, GL_MIRRORED_REPEAT, GL_REPEAT, or GL_MIRROR_CLAMP_TO_EDGE.

  • GL_CLAMP_TO_EDGE causes s coordinates to be clamped to the range range, where N is the size of the texture in the direction of clamping.

  • GL_CLAMP_TO_BORDER evaluates s coordinates in a similar manner to GL_CLAMP_TO_EDGE.
    However, in cases where clamping would have occurred in GL_CLAMP_TO_EDGE mode, the fetched texel data is substituted with the values specified by GL_TEXTURE_BORDER_COLOR.

  • GL_REPEAT causes the integer part of the s coordinate to be ignored;
    the GL uses only the fractional part, thereby creating a repeating pattern.

  • GL_MIRRORED_REPEAT causes the s coordinate to be set to the fractional part of the texture coordinate if the integer part of s is even; if the integer part of s is odd, then the s texture coordinate is set to 1-frac, where frac represents the fractional part of s.

  • GL_MIRROR_CLAMP_TO_EDGE causes the the s coordinate to be repeated as for GL_MIRRORED_REPEAT for one reptition of the texture, at which point the coordinate to be clamped as in GL_CLAMP_TO_EDGE.

Initially, GL_TEXTURE_WRAP_S is set to GL_REPEAT.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.