1991-2006
Silicon Graphics, Inc.
glTexImage2D
3G
glTexImage2D
specify a two-dimensional texture image
C Specification
void glTexImage2D
GLenum target
GLint level
GLint internalformat
GLsizei width
GLsizei height
GLint border
GLenum format
GLenum type
const GLvoid * data
Parameters
target
Specifies the target texture of the active texture unit.
Must be GL_TEXTURE_2D,
GL_TEXTURE_CUBE_MAP_POSITIVE_X,
GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
GL_TEXTURE_CUBE_MAP_POSITIVE_Z, or
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z.
level
Specifies the level-of-detail number.
Level 0 is the base image level.
Level n is the nth mipmap reduction image.
internalformat
Specifies the internal format of the texture.
Must be one of the following symbolic constants:
GL_ALPHA,
GL_LUMINANCE,
GL_LUMINANCE_ALPHA,
GL_RGB,
GL_RGBA.
width
Specifies the width of the texture image.
All implementations support 2D texture images that are at least 64 texels
wide and cube-mapped texture images that are at least 16 texels wide.
height
Specifies the height of the texture image
All implementations support 2D texture images that are at least 64 texels
high and cube-mapped texture images that are at least 16 texels high.
border
Specifies the width of the border.
Must be 0.
format
Specifies the format of the texel data. Must match internalformat.
The following symbolic values are accepted:
GL_ALPHA,
GL_RGB,
GL_RGBA,
GL_LUMINANCE, and
GL_LUMINANCE_ALPHA.
type
Specifies the data type of the texel data.
The following symbolic values are accepted:
GL_UNSIGNED_BYTE,
GL_UNSIGNED_SHORT_5_6_5,
GL_UNSIGNED_SHORT_4_4_4_4, and
GL_UNSIGNED_SHORT_5_5_5_1.
data
Specifies a pointer to the image data in memory.
Description
Texturing maps a portion of a specified texture image
onto each graphical primitive for which texturing is
active. Texturing is active when the current fragment shader or
vertex shader makes use of built-in texture lookup
functions.
To define texture images, call glTexImage2D.
The arguments describe the parameters of the texture image,
such as height,
width,
level-of-detail number
(see glTexParameter),
and format.
The last three arguments describe how the image is represented in memory.
Data is read from data as a sequence of unsigned bytes or shorts,
depending on type.
When type is GL_UNSIGNED_BYTE,
each of the bytes is interpreted as one color component.
When type is one of
GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_4_4_4_4, or
GL_UNSIGNED_SHORT_5_5_5_1, each unsigned short value is interpreted as
containing all the components for a single texel, with the color
components arranged according to format.
Color components are treated as groups of one, two, three, or four
values, again based on format. Groups of
components are referred to as texels.
width
×
height
texels are read from memory,
starting at location data.
By default, these texels are taken from adjacent memory locations,
except that after all width texels are read,
the read pointer is advanced to the next four-byte boundary.
The four-byte row alignment is specified by glPixelStorei with
argument GL_UNPACK_ALIGNMENT,
and it can be set to one, two, four, or eight bytes.
The first element corresponds to the lower left corner of the texture
image.
Subsequent elements progress left-to-right through the remaining texels
in the lowest row of the texture image, and then in successively higher
rows of the texture image.
The final element corresponds to the upper right corner of the texture
image.
format determines the composition of each element in data.
It can assume one of these symbolic values:
GL_ALPHA
Each element is a single alpha component.
The GL converts it to floating point and assembles it into an RGBA element
by attaching 0 for red, green, and blue.
Each component is then clamped to the range [0,1].
GL_RGB
Each element is an RGB triple.
The GL converts it to floating point and assembles it into an RGBA element
by attaching 1 for alpha.
Each component is then clamped to the range [0,1].
GL_RGBA
Each element contains all four components. The GL converts it to floating point, then
each component is clamped to the range [0,1].
GL_LUMINANCE
Each element is a single luminance value.
The GL converts it to floating point,
then assembles it into an RGBA element by replicating the luminance value
three times for red, green, and blue and attaching 1 for alpha.
Each component is then clamped to the range [0,1].
GL_LUMINANCE_ALPHA
Each element is a luminance/alpha pair.
The GL converts it to floating point,
then assembles it into an RGBA element by replicating the luminance value
three times for red, green, and blue.
Each component is then clamped to the range [0,1].
Color components are converted to floating point based on the type.
When type is GL_UNSIGNED_BYTE,
each component is divided by
2
8
-
1
.
When type is GL_UNSIGNED_SHORT_5_6_5,
GL_UNSIGNED_SHORT_4_4_4_4, or GL_UNSIGNED_SHORT_5_5_5_1,
each component is divided by
2
N
-
1
,
where N
is the number of bits in the bitfield.
Notes
internalformat must match format.
No conversion between formats is supported during texture image processing.
type may be used as a hint to specify how much
precision is desired, but a GL implementation may choose to store the texture
array at any internal resolution it chooses.
data may be a null pointer.
In this case, texture memory is
allocated to accommodate a texture of width width and height height.
You can then download subtextures to initialize this
texture memory.
The image is undefined if the user tries to apply
an uninitialized portion of the texture image to a primitive.
glTexImage2D
specifies a two-dimensional or cube-map texture for the current texture unit,
specified with glActiveTexture.
Errors
GL_INVALID_ENUM is generated if target is not GL_TEXTURE_2D,
GL_TEXTURE_CUBE_MAP_POSITIVE_X,
GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
GL_TEXTURE_CUBE_MAP_POSITIVE_Z, or
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z.
GL_INVALID_ENUM is generated if format
or type is not an accepted value.
GL_INVALID_VALUE is generated if target is one of the six cube map 2D image targets and the width and height parameters are not equal.
GL_INVALID_VALUE is generated if level is less than 0.
GL_INVALID_VALUE may be generated if level is greater than
log
2
⁡
max
,
where max is the returned value of
GL_MAX_TEXTURE_SIZE when target
is GL_TEXTURE_2D or GL_MAX_CUBE_MAP_TEXTURE_SIZE when
target is not GL_TEXTURE_2D.
GL_INVALID_VALUE is generated if internalformat is not an
accepted format.
GL_INVALID_VALUE is generated if width or height is less than 0
or greater than GL_MAX_TEXTURE_SIZE when target
is GL_TEXTURE_2D or GL_MAX_CUBE_MAP_TEXTURE_SIZE when
target is not GL_TEXTURE_2D.
GL_INVALID_VALUE is generated if border is not 0.
GL_INVALID_OPERATION is generated if format does
not match internalformat.
GL_INVALID_OPERATION is generated if type is
GL_UNSIGNED_SHORT_5_6_5
and format is not GL_RGB.
GL_INVALID_OPERATION is generated if type is
GL_UNSIGNED_SHORT_4_4_4_4 or
GL_UNSIGNED_SHORT_5_5_5_1
and format is not GL_RGBA.
Associated Gets
glGet
with argument GL_MAX_TEXTURE_SIZE or
GL_MAX_CUBE_MAP_TEXTURE_SIZE
See Also
glActiveTexture,
glCompressedTexImage2D,
glCompressedTexSubImage2D,
glCopyTexImage2D,
glCopyTexSubImage2D,
glPixelStorei,
glTexSubImage2D,
glTexParameter
Copyright
Copyright 1991-2006
Silicon Graphics, Inc. This document is licensed under the SGI
Free Software B License. For details, see
http://oss.sgi.com/projects/FreeB/.