Name
glTexImage2D
- specify a two-dimensional texture imageC Specification
void glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid * pixels)
Parameters
target
- Specifies the target texture. Must be
GL_TEXTURE_2D
. level
- Specifies the level-of-detail number. Level 0 is the base image level. Level
n
is then
th mipmap reduction image. Must be greater or equal 0. internalformat
- Specifies the color components in the texture. Must be same as
format
. The following symbolic values are accepted:GL_ALPHA
,GL_RGB
,GL_RGBA
,GL_LUMINANCE
, orGL_LUMINANCE_ALPHA
. width
- Specifies the width of the texture image. Must be 2n + 2border for some integer n. All implementations support texture images that are at least 64 texels wide.
height
- Specifies the height of the texture image. Must be 2m + 2border for some integer m. All implementations support texture images that are at least 64 texels high.
border
- Specifies the width of the border. Must be 0. (glTexImage2D)
format
- Specifies the format of the pixel data. Must be same as
internalformat
. The following symbolic values are accepted:GL_ALPHA
,GL_RGB
,GL_RGBA
,GL_LUMINANCE
, andGL_LUMINANCE_ALPHA
. type
- Specifies the data type of the pixel data. The following symbolic values are accepted:
GL_UNSIGNED_BYTE
,GL_UNSIGNED_SHORT_5_6_5
,GL_UNSIGNED_SHORT_4_4_4_4
, andGL_UNSIGNED_SHORT_5_5_5_1
. pixels
- Specifies a pointer to the image data in memory.
Description for glTexImage2D
Texturing maps a portion of a specified texture image onto each graphical primitive for which texturing is enabled. To enable and disable two-dimensional texturing, callglEnable
and glDisable
with argument GL_TEXTURE_2D
. Two-dimensional texturing is initially disabled.To define texture images, call
glTexImage2D
. The arguments describe the parameters of the texture image, such as height, width, width of the border, level-of-detail number (see glTexParameter
), and number of color components provided. The last three arguments describe how the image is represented in memory.Data is read from
pixels
as a sequence of unsigned bytes or shorts, depending on type
. These values are grouped into sets of one, two, three, or four values, depending on format
, to form elements.When
type
is GL_UNSIGNED_BYTE
, each of these bytes is interpreted as one color component, depending on format
. When type
is one of GL_UNSIGNED_SHORT_5_6_5
, GL_UNSIGNED_SHORT_4_4_4_4
, GL_UNSIGNED_SHORT_5_5_5_1
, each unsigned value is interpreted as containing all the components for a single pixel, with the color components arranged according to format. (glTexImage2D)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.
By default, adjacent pixels are taken from adjacent memory locations, except that after all
width
pixels are read, the read pointer is advanced to the next four-byte boundary. The four-byte row alignment is specified by glPixelStore
with argument GL_UNPACK_ALIGNMENT
, and it can be set to one, two, four, or eight bytes.format
determines the composition of each element in pixels
. It can assume one of the following 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.
GL_RGB
- Each element is an RGB triple. The GL converts it to fixed-point or floating-point and assembles it into an RGBA element by attaching 1 for alpha.
GL_RGBA
- Each element contains all four components. The GL converts it to fixed-point or floating-point.
GL_LUMINANCE
- Each element is a single luminance value. The GL converts it to fixed-point or 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.
GL_LUMINANCE_ALPHA
- Each element is a luminance/alpha pair. The GL converts it to fixed-point or floating point, then assembles it into an RGBA element by replicating the luminance value three times for red, green, and blue.
Notes
pixels
may be NULL
. 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 the two-dimensional texture for the currently bound texture specified with glBindTexture
, and the current texture unit, specified with glActiveTexture
.Errors
GL_INVALID_ENUM
is generated if target
is not GL_TEXTURE_2D
.GL_INVALID_ENUM
is generated if format
is not an accepted constant.GL_INVALID_ENUM
is generated if type
is not a type constant.GL_INVALID_VALUE
is generated if level
is less than 0.GL_INVALID_VALUE
may be generated if level
is greater than log2max, where max is the returned value of GL_MAX_TEXTURE_SIZE
.GL_INVALID_VALUE
is generated if internalformat
is not an accepted constant.GL_INVALID_VALUE
is generated if width
or height
is less than 0 or greater than GL_MAX_TEXTURE_SIZE
, or if either cannot be represented as 2k + 2border for some integer k.GL_INVALID_VALUE
is generated if border
is not 0.GL_INVALID_OPERATION
is generated if internalformat
and format
are not the same.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 one of GL_UNSIGNED_SHORT_4_4_4_4
, or GL_UNSIGNED_SHORT_5_5_5_1
and format
is not GL_RGBA
.Associated Gets
glGetInteger
with argument GL_MAX_TEXTURE_SIZE
Copyright
Copyright © 2003 Silicon Graphics, Inc.This document is licensed under the SGI Free Software B License. For details, see http://oss.sgi.com/projects/FreeB/.
See Also
glActiveTexture
, glBindTexture
, glCopyTexImage2D
, glCopyTexSubImage2D
, glGetInteger
, glMatrixMode
, glPixelStore
, glTexEnv
, glTexSubImage2D
, glTexParameter
Example of glTexImage2D
{BYTE *pBuffer;//RGB Data storage
int bmpwidth, bmpheight;
TCHAR filename[100];
wcscpy(filename, L"\\Storage Card\\DieTexture.bmp");
LoadBmpFile(filename, &pBuffer, &bmpwidth, &bmpheight);
glBindTexture(GL_TEXTURE_2D, texture); // texture에 binding
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, bmpwidth, bmpheight, 0, GL_RGB, GL_UNSIGNED_BYTE, pBuffer);
delete pBuffer;
}