The texture coordinates determine which texel in the texture map is assigned to that vertex. In exactly the same way that colors are interpolated between two vertices of shaded polygons and lines, texture coordinates are also interpolated between vertices.
Texture coordinates can comprise one, two, three, or four coordinates. They are
usually referred to as the s, t, r, and q coordinates to
distinguish them from object coordinates (x, y, z, and
w).
For one-dimensional textures, you use
the s coordinate; for two-dimensional textures, you use s
and t.
The command to specify texture coordinates, glTexCoord*():
void glTexCoord{1234}{sifd}(TYPEcoords);
void glTexCoord{1234}{sifd}v(TYPE *coords);
Subsequent calls to glVertex*() result in those vertices being assigned the current texture coordinates.
Usually, texture-coordinate values range from 0 to 1 for float as type; values can be assigned outside this range (see, Repeating and Clamping Textures):
| (1,0) | (1,1) | |
![]() |
||
| (0,0) | (0,1) |
gl.glBindTexture( GL.GL_TEXTURE_2D, textureId[4] );
gl.glBegin( GL.GL_QUADS ); {
gl.glTexCoord2f( 0f, 0f );
gl.glVertex2f( 0, 0 );
gl.glTexCoord2f( 0f, 1f );
gl.glVertex2f( 0, 1f );
gl.glTexCoord2f( 1f, 1f );
gl.glVertex2f( 1f, 1f );
gl.glTexCoord2f( 1f, 0f );
gl.glVertex2f( 1f, 0 );
} gl.glEnd();
Instead of explicitly assigning them yourself, you can choose to
have texture coordinates calculated automatically, (see, Automatic Texture-Coordinate
Generation).