Sampling
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:
Term | Meaning |
---|---|
GL_REPEAT (default) | Repeat the texture. |
GL_MIRRORED_REPEAT | Repeat, but flip the image on each repeat. |
GL_CLAMP_TO_EDGE | Clamp coordinates between 0 and 1. Causes stretching. |
GL_CLAMP_TO_BORDER | Clip 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.