Thursday, April 2, 2015

opengl - What does changing GL_TEXTURE_WRAP)_(S/T) do?


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.



Answer




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 more modes so make sure to read the docs. (Examples: GL_MIRRORED_REPEAT, GL_MIRROR_CLAMP_TO_EDGE)




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



No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...