Brain Dump

Sampling

Tags
computer-graphics opengl

The [see page 6, process] of picking a color for a pixel on an objects surface from a texture map.

Textures are mapped into a coordinate-space with \((0,0)\) in the bottom left and \((1,1)\) in the top right. If we specify a texture coordinate outside of this range, OpenGl supports a few options for what to do:

TermMeaning
GL_REPEAT (default)Repeat the texture.
GL_MIRRORED_REPEATRepeat, but flip the image on each repeat.
GL_CLAMP_TO_EDGEClamp coordinates between 0 and 1. Causes stretching.
GL_CLAMP_TO_BORDERClip off the parts outside of the coordinate-space.

Each of these options can be configured per texture axis \((s,r,t)\) like so:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);

Note: GL_CLAMP_TO_BORDER only stretches the texture across the borders. For a square image this produces a + shaped pattern. You can specify a border color with the glTexParameterfv method.