# Method GL.glTexGen()

- Method
**glTexGen** `void`

**glTexGen(**`int`

`coord`

,`int`

`pname`

,`float`

|`int`

|`array`

(`float`

|`int`

)`param`

**)**- Description
glTexGen selects a texture-coordinate generation function or supplies coefficients for one of the functions.

*coord*names one of the (*s*,*t*,*r*,*q*) texture coordinates; it must be one of the symbols GL_S, GL_T, GL_R, or GL_Q.*pname*must be one of three symbolic constants: GL_TEXTURE_GEN_MODE, GL_OBJECT_PLANE, or GL_EYE_PLANE. If*pname*is GL_TEXTURE_GEN_MODE, then*params*chooses a mode, one of GL_OBJECT_LINEAR, GL_EYE_LINEAR, or GL_SPHERE_MAP. If*pname*is either GL_OBJECT_PLANE or GL_EYE_PLANE,*params*contains coefficients for the corresponding texture generation function. .P If the texture generation function is GL_OBJECT_LINEAR, the function.ce g = p sub 1 x sub o + p sub 2 y sub o + p sub 3 z sub o + p sub 4 w sub o

is used, where g is the value computed for the coordinate named in

*coord*, p sub 1, p sub 2, p sub 3, and p sub 4 are the four values supplied in*params*, and x sub o, y sub o, z sub o, and w sub o are the object coordinates of the vertex. This function can be used, for example, to texture-map terrain using sea level as a reference plane (defined by p sub 1, p sub 2, p sub 3, and p sub 4). The altitude of a terrain vertex is computed by the GL_OBJECT_LINEAR coordinate generation function as its distance from sea level; that altitude can then be used to index the texture image to map white snow onto peaks and green grass onto foothills.If the texture generation function is GL_EYE_LINEAR, the function

.ce g = {p sub 1} sup prime ~x sub e + {p sub 2} sup prime ~y sub e + {p sub 3} sup prime ~z sub e + {p sub 4} sup prime ~w sub e

is used, where

.ce $( {p sub 1} sup prime ~~{p sub 2} sup prime~~{p sub 3} sup prime~~ {{p sub 4}sup prime}) = ( p sub 1~~ p sub 2~~ p sub 3~~ p sub 4 ) ~M sup -1$

and x sub e, y sub e, z sub e, and w sub e are the eye coordinates of the vertex, p sub 1, p sub 2, p sub 3, and p sub 4 are the values supplied in

*params*, and M is the modelview matrix when glTexGen is invoked. If M is poorly conditioned or singular, texture coordinates generated by the resulting function may be inaccurate or undefined.Note that the values in

*params*define a reference plane in eye coordinates. The modelview matrix that is applied to them may not be the same one in effect when the polygon vertices are transformed. This function establishes a field of texture coordinates that can produce dynamic contour lines on moving objects.If

*pname*is GL_SPHERE_MAP and*coord*is either GL_S or GL_T, s and t texture coordinates are generated as follows. Let*u*be the unit vector pointing from the origin to the polygon vertex (in eye coordinates). Let*n*sup prime be the current normal, after transformation to eye coordinates. Let.ce f ~=~ ( f sub x~~f sub y~~f sub z ) sup T be the reflection vector such that

.ce f ~=~ u ~-~ 2 n sup prime n sup prime sup T u

Finally, let m ~=~ 2 sqrt { f sub x sup {~2} + f sub y sup {~2} + (f sub z + 1 ) sup 2}. Then the values assigned to the s and t texture coordinates are

.ce 1 s ~=~ f sub x over m ~+~ 1 over 2 .sp .ce 1 t ~=~ f sub y over m ~+~ 1 over 2

To enable or disable a texture-coordinate generation function, call glEnable or glDisable with one of the symbolic texture-coordinate names (GL_TEXTURE_GEN_S, GL_TEXTURE_GEN_T, GL_TEXTURE_GEN_R, or GL_TEXTURE_GEN_Q) as the argument. When enabled, the specified texture coordinate is computed according to the generating function associated with that coordinate. When disabled, subsequent vertices take the specified texture coordinate from the current set of texture coordinates. Initially, all texture generation functions are set to GL_EYE_LINEAR and are disabled. Both s plane equations are (1, 0, 0, 0), both t plane equations are (0, 1, 0, 0), and all r and q plane equations are (0, 0, 0, 0).

- Parameter
`coord`

Specifies a texture coordinate. Must be one of GL_S, GL_T, GL_R, or GL_Q.

- Parameter
`pname`

Specifies the symbolic name of the texture-coordinate generation function. Must be GL_TEXTURE_GEN_MODE.

- Parameter
`param`

Specifies a single-valued texture generation parameter, one of GL_OBJECT_LINEAR, GL_EYE_LINEAR, or GL_SPHERE_MAP.

- Parameter
`coord`

Specifies a texture coordinate. Must be one of GL_S, GL_T, GL_R, or GL_Q.

- Parameter
`pname`

Specifies the symbolic name of the texture-coordinate generation function or function parameters. Must be GL_TEXTURE_GEN_MODE, GL_OBJECT_PLANE, or GL_EYE_PLANE.

- Parameter
`params`

Specifies a pointer to an array of texture generation parameters. If

*pname*is GL_TEXTURE_GEN_MODE, then the array must contain a single symbolic constant, one of GL_OBJECT_LINEAR, GL_EYE_LINEAR, or GL_SPHERE_MAP. Otherwise,*params*holds the coefficients for the texture-coordinate generation function specified by*pname*.- Throws
GL_INVALID_ENUM is generated when

*coord*or*pname*is not an accepted defined value, or when*pname*is GL_TEXTURE_GEN_MODE and*params*is not an accepted defined value.GL_INVALID_ENUM is generated when

*pname*is GL_TEXTURE_GEN_MODE,*params*is GL_SPHERE_MAP, and*coord*is either GL_R or GL_Q.GL_INVALID_OPERATION is generated if glTexGen is executed between the execution of glBegin and the corresponding execution of glEnd.