Specifies a pointer to a parameter array that contains either an RGBA color,
a single symbolic constant, one of GL_ADD, GL_ADD_SIGNED,
GL_DOT3_RGB, GL_DOT3_RGBA, GL_INTERPOLATE, GL_MODULATE, GL_DECAL,
GL_BLEND, GL_REPLACE, GL_SUBTRACT, GL_COMBINE,
GL_TEXTURE, GL_CONSTANT, GL_PRIMARY_COLOR, GL_PREVIOUS,
GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, GL_SRC_ALPHA,
GL_ONE_MINUS_SRC_ALPHA,
a single boolean value for the point sprite texture coordinate replacement,
or 1.0, 2.0, or 4.0 when specifying the GL_RGB_SCALE or GL_ALPHA_SCALE.

Description

A texture environment specifies how texture values are interpreted when a
fragment is textured. When target is GL_POINT_SPRITE_OES,
pname must be GL_COORD_REPLACE_OES. When target is
GL_TEXTURE_ENV, pname can be GL_TEXTURE_ENV_MODE,
GL_TEXTURE_ENV_COLOR, GL_COMBINE_RGB, GL_COMBINE_ALPHA,
GL_RGB_SCALE, GL_ALPHA_SCALE,
GL_OPERAND0_RGB, GL_OPERAND1_RGB, GL_OPERAND2_RGB,
GL_OPERAND0_ALPHA, GL_OPERAND1_ALPHA, GL_OPERAND2_ALPHA,
GL_SRC0_RGB, GL_SRC1_RGB, GL_SRC2_RGB,
GL_SRC0_ALPHA, GL_SRC1_ALPHA, or GL_SRC2_ALPHA.

If pname is GL_TEXTURE_ENV_MODE,
then params is (or points to) the symbolic name of a texture function.
Six texture functions may be specified:
GL_ADD,
GL_MODULATE,
GL_DECAL,
GL_BLEND,
GL_REPLACE, or
GL_COMBINE.

The following table shows the correspondence of filtered texture
values
Rt,
Gt,
Bt,
At,
Lt
to texture source components.
Cs
and
As
are used by the texture functions described below.

Texture Base Internal Format

Cs

As

GL_ALPHA

(0, 0, 0)

At

GL_LUMINANCE

(
Lt,
Lt,
Lt
)

1

GL_LUMINANCE_ALPHA

(
Lt,
Lt,
Lt
)

At

GL_RGB

(
Rt,
Gt,
Bt
)

1

GL_RGBA

(
Rt,
Gt,
Bt
)

At

A texture function acts on the fragment to be textured using
the texture image value that applies to the fragment
(see glTexParameter)
and produces an RGBA color for that fragment.
The following table shows how the RGBA color is produced for each
of the first five texture functions that can be chosen.
C
is a triple of color values (RGB) and
A
is the associated alpha value.
RGBA values extracted from a texture image are in the range [0,1].
The subscript
p
refers to the color computed from the previous texture stage (or the incoming fragment if processing texture stage 0),
the subscript
s
to the texture source color,
the subscript
c
to the texture environment color,
and the subscript
v
indicates a value produced by the texture function.

Texture Base Internal Format

Value

GL_REPLACE Function

GL_MODULATE Function

GL_DECAL Function

GL_BLEND Function

GL_ADD Function

GL_ALPHA

Cv=

Cp

Cp

undefined

Cp

Cp

Av=

As

Ap⁢As

Av=Ap⁢As

Ap⁢As

GL_LUMINANCE

Cv=

Cs

Cp⁢Cs

undefined

Cp⁢1-Cs+Cc⁢Cs

Cp+Cs

(or 1)

Av=

Ap

Ap

Ap

Ap

GL_LUMINANCE_ALPHA

Cv=

Cs

Cp⁢Cs

undefined

Cp⁢1-Cs+Cc⁢Cs

Cp+Cs

(or 2)

Av=

As

Ap⁢As

Ap⁢As

Ap⁢As

GL_RGB

Cv=

Cs

Cp⁢Cs

Cs

Cp⁢1-Cs+Cc⁢Cs

Cp+Cs

(or 3)

Av=

Ap

Ap

Ap

Ap

Ap

GL_RGBA

Cv=

Cs

Cp⁢Cs

Cp⁢1-As+Cs⁢As

Cp⁢1-Cs+Cc⁢Cs

Cp+Cs

(or 4)

Av=

As

Ap⁢As

Ap

Ap⁢As

Ap⁢As

If pname is GL_TEXTURE_ENV_MODE, and params is GL_COMBINE, the
form of the texture function depends on the values of GL_COMBINE_RGB
and GL_COMBINE_ALPHA.

The following describes how the texture sources, as specified by
GL_SRC0_RGB, GL_SRC1_RGB, GL_SRC2_RGB,
GL_SRC0_ALPHA, GL_SRC1_ALPHA, and GL_SRC2_ALPHA,
are combined to produce a final texture color. In the following tables,
GL_SRC0_c is represented by
Arg0,
GL_SRC1_c is
represented by
Arg1,
and GL_SRC2_c is represented by
Arg2.

The scalar results for GL_DOT3_RGB and GL_DOT3_RGBA are placed
into each of the 3 (RGB) or 4 (RGBA) components on output.

Likewise, GL_COMBINE_ALPHA accepts any of GL_REPLACE,
GL_MODULATE, GL_ADD, GL_ADD_SIGNED, GL_INTERPOLATE, or
GL_SUBTRACT. The following table describes how alpha values are
combined:

GL_COMBINE_ALPHA

Texture Function

GL_REPLACE

Arg0

GL_MODULATE

Arg0×Arg1

GL_ADD

Arg0+Arg1

GL_ADD_SIGNED

Arg0+Arg1-0.5

GL_INTERPOLATE

Arg0×Arg2+Arg1×1-Arg2

GL_SUBTRACT

Arg0-Arg1

In the following tables, the value
Cs
represents the color sampled
from the currently bound texture,
Cc
represents the constant
texture-environment color,
Cf
represents the primary color of the
incoming fragment, and
Cp
represents the color computed from the
previous texture stage or
Cf
if processing texture stage 0. Likewise,
As,
Ac,
Af,
and
Ap
represent the respective
alpha values.

The following table describes the values assigned to
Arg0,
Arg1,
and
Arg2
based upon the RGB sources and operands:

GL_SRCn_RGB

GL_OPERANDn_RGB

Argument Value

GL_TEXTURE

GL_SRC_COLOR

Cs

GL_ONE_MINUS_SRC_COLOR

1-Cs

GL_SRC_ALPHA

As

GL_ONE_MINUS_SRC_ALPHA

1-As

GL_TEXTUREn

GL_SRC_COLOR

Cs

GL_ONE_MINUS_SRC_COLOR

1-Cs

GL_SRC_ALPHA

As

GL_ONE_MINUS_SRC_ALPHA

1-As

GL_CONSTANT

GL_SRC_COLOR

Cc

GL_ONE_MINUS_SRC_COLOR

1-Cc

GL_SRC_ALPHA

Ac

GL_ONE_MINUS_SRC_ALPHA

1-Ac

GL_PRIMARY_COLOR

GL_SRC_COLOR

Cf

GL_ONE_MINUS_SRC_COLOR

1-Cf

GL_SRC_ALPHA

Af

GL_ONE_MINUS_SRC_ALPHA

1-Af

GL_PREVIOUS

GL_SRC_COLOR

Cp

GL_ONE_MINUS_SRC_COLOR

1-Cp

GL_SRC_ALPHA

Ap

GL_ONE_MINUS_SRC_ALPHA

1-Ap

For GL_TEXTUREn sources,
Cs
and
As
represent the color
and alpha, respectively, produced from texture stage
n.

The follow table describes the values assigned to
Arg0,
Arg1,
and
Arg2
based upon the alpha sources and operands:

GL_SRCn_ALPHA

GL_OPERANDn_ALPHA

Argument Value

GL_TEXTURE

GL_SRC_ALPHA

As

GL_ONE_MINUS_SRC_ALPHA

1-As

GL_TEXTUREn

GL_SRC_ALPHA

As

GL_ONE_MINUS_SRC_ALPHA

1-As

GL_CONSTANT

GL_SRC_ALPHA

Ac

GL_ONE_MINUS_SRC_ALPHA

1-Ac

GL_PRIMARY_COLOR

GL_SRC_ALPHA

Af

GL_ONE_MINUS_SRC_ALPHA

1-Af

GL_PREVIOUS

GL_SRC_ALPHA

Ap

GL_ONE_MINUS_SRC_ALPHA

1-Ap

The RGB and alpha results of the texture function are multipled by the
values of GL_RGB_SCALE and GL_ALPHA_SCALE, respectively, and
clamped to the range
01.

If pname is GL_TEXTURE_ENV_COLOR,
params is a pointer to an array that holds an RGBA color consisting of four
values.
Integer color components are interpreted linearly such that the most
positive integer maps to 1.0,
and the most negative integer maps to -1.0.
The values are clamped to the range [0,1] when they are specified.
Cc
takes these four values.

If target is GL_POINT_SPRITE_OES and pname is GL_COORD_REPLACE_OES, the boolean value specified
is used to either enable or disable point sprite texture coordinate replacement. The default value is GL_FALSE.

Notes

glTexEnv controls
the texture environment for the current active texture unit, selected by
glActiveTexture.

GL_POINT_SPRITE_OES and GL_COORD_REPLACE_OES are available
only if the OpenGL ES version is 1.1 or greater.

Errors

GL_INVALID_ENUM is generated when target or pname is not
one of the accepted defined values,
or when params should have a defined constant value
(based on the value of pname)
and does not.

GL_INVALID_VALUE is generated if the params value for
GL_RGB_SCALE or GL_ALPHA_SCALE are not one of 1.0, 2.0,
or 4.0.