Texture coordinates associated with a vertex may either be taken from the current texture coordinates or generated according to a function dependent on vertex coordinates. The command
void TexGen[ifd] ( enum coord, enum pname, T param ) ;
void TexGen[ifd]v ( enum coord, enum pname, T params ) ;
controls texture coordinate generation. coord must be one of the constants S, T, R, or Q, indicating that the pertinent coordinate is the s, t, r, or q coordinate, respectively. In the first form of the command, param is a symbolic constant specifying a single-valued texture generation parameter; in the second form, params is a pointer to an array of values that specify texture generation parameters. pname must be one of the three symbolic constants TEXTURE_GEN_MODE, OBJECT_PLANE, or EYE_PLANE. If pname is TEXTURE_GEN_MODE, then either params points to or param is an integer that is one of the symbolic constants OBJECT_LINEAR, EYE_LINEAR, or SPHERE_MAP.
If TEXTURE_GEN_MODE indicates OBJECT_LINEAR, then the generation function for the coordinate indicated by coord is
, , , and are the object coordinates of the vertex. are specified by calling TexGen with pname set to OBJECT_PLANE in which case params points to an array containing . There is a distinct group of plane equation coefficients for each texture coordinate; coord indicates the coordinate to which the specified coefficients pertain.
If TEXTURE_GEN_MODE indicates EYE_LINEAR, then the function is
, , , and are the eye coordinates of the vertex. are set by calling TexGen with pname set to EYE_PLANE in correspondence with setting the coefficients in the OBJECT_PLANE case. M is the model-view matrix in effect when are specified. Computed texture coordinates may be inaccurate or undefined if M is poorly conditioned or singular.
When used with a suitably constructed texture image, calling TexGen with TEXTURE_GEN_MODE indicating SPHERE_MAP can simulate the reflected image of a spherical environment on a polygon. SPHERE_MAP texture coordinates are generated as follows. Denote the unit vector pointing from the origin to the vertex (in eye coordinates) by . Denote the current normal, after transformation to eye coordinates, by . Let , the reflection vector, be given by
and let . Then the value assigned to an s coordinate (the first TexGen argument value is S) is ; the value assigned to a t coordinate is . Calling TexGen with a coord of either R or Q when pname indicates SPHERE_MAP generates the error INVALID_ENUM.
A texture coordinate generation function is enabled or disabled using Enable and Disable with an argument of TEXTURE_GEN_S, TEXTURE_GEN_T, TEXTURE_GEN_R, or TEXTURE_GEN_Q (each indicates the corresponding texture coordinate). When enabled, the specified texture coordinate is computed according to the current EYE_LINEAR, OBJECT_LINEAR or SPHERE_MAP specification, depending on the current setting of TEXTURE_GEN_MODE for that coordinate. When disabled, subsequent vertices will take the indicated texture coordinate from the current texture coordinates.
The state required for texture coordinate generation comprises a three-valued integer for each coordinate indicating coordinate generation mode, and a bit for each coordinate to indicate whether texture coordinate generation is enabled or disabled. In addition, four coefficients are required for the four coordinates for each of EYE_LINEAR and OBJECT_LINEAR. The initial state has the texture generation function disabled for all texture coordinates. The initial values of for s are all 0 except which is one; for t all the are zero except , which is 1. The values of for r and q are all 0. These values of apply for both the EYE_LINEAR and OBJECT_LINEAR versions. Initially all texture generation modes are EYE_LINEAR.