The glTexImage2D function specifies a two-dimensional texture image.
void glTexImage2D(
GLenum target,
GLint level,
GLint components,
GLsizei width,
GLsizei height,
GLint border,
GLenum format,
GLenum type,
const GLvoid *pixels
);
GL_BGR_EXT provides a format that matches the memory layout of Windows device-independent bitmaps (DIBs). Thus your applications can use the same data with Win32 function calls and OpenGL pixel function calls.
GL_BGRA_EXT provides a format that matches the memory layout of Windows device-independent bitmaps (DIBs). Thus your applications can use the same data with Win32 function calls and OpenGL pixel function calls.
The glTexImage2D function specifies a two-dimensional texture image. Texturing maps a portion of a specified texture image onto each graphical primitive for which texturing is enabled. Two-dimensional texturing is enabled and disabled using glEnable and glDisable with argument GL_TEXTURE_2D.
Texture images are defined with 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 the way the image is represented in memory. These arguments are identical to the pixel formats used for glDrawPixels.
Data is read from pixels as a sequence of signed or unsigned bytes, shorts or longs, or single-precision floating-point values, depending on type. These values are grouped into sets of one, two, three, or four values, depending on format, to form elements. If type is GL_BITMAP, the data is considered as a string of unsigned bytes (and format must be GL_COLOR_INDEX). Each data byte is treated as eight 1-bit elements, with bit ordering determined by GL_UNPACK_LSB_FIRST (see glPixelStore). Please see glDrawPixels for a description of the acceptable values for the type parameter.
A texture image can have up to four components per texture element, depending on components. A one-component texture image uses only the red component of the RGBA color extracted from pixels. A two-component image uses the R and A values. A three-component image uses the R, G, and B values. A four-component image uses all of the RGBA components.
Texturing has no effect in color-index mode.
The texture image can be represented by the same data formats as the pixels in a glDrawPixels command, except that GL_STENCIL_INDEX and GL_DEPTH_COMPONENT cannot be used. The glPixelStore and glPixelTransfer modes affect texture images in exactly the way they affect glDrawPixels.
A texture image with zero height or width indicates the null texture. If the null texture is specified for level-of-detail 0, it is as if texturing were disabled.
The following functions retrieve information related to glTexImage2D:
glIsEnabled with argument GL_TEXTURE_2D
The following are the error codes generated and their conditions.
Error Code | Condition |
---|---|
GL_INVALID_ENUM | target was not GL_TEXTURE_2D. |
GL_INVALID_ENUM | format was not an accepted format constant. Format constants other than GL_STENCIL_INDEX and GL_DEPTH_COMPONENT were accepted. |
GL_INVALID_ENUM | type was not a type constant. |
GL_INVALID_ENUM | type was GL_BITMAP and format was not GL_COLOR_INDEX. |
GL_INVALID_VALUE | level was less than zero or greater than log (2) max, where max was the returned value of GL_MAX_TEXTURE_SIZE. |
GL_INVALID_VALUE | components was not 1, 2, 3, or 4. |
GL_INVALID_VALUE | width or height was less than zero or greater than 2 + GL_MAX_TEXTURE_SIZE, or if either could not be represented as 2^k + 2(border) for some integer value of k. |
GL_INVALID_VALUE | border was not 0 or 1. |
GL_INVALID_OPERATION | glTexImage2D was called between a call to glBegin and the corresponding call to glEnd. |
Windows NT: Use version 3.5 and later.
Windows: Use Windows 95 and later.
Windows CE: Unsupported.
Header: Declared in gl.h.
Import Library: Link with opengl32.lib.
glBegin, glDrawPixels, glEnd, glFog, glIsEnabled, glPixelStore, glPixelTransfer, glTexEnv, glTexGen, glTexImage1D, glTexParameter