Graphics Reference
In-Depth Information
This application sets the unpack alignment to 1, meaning that each row
of pixels begins on a byte boundary (in other words, the data is tightly
packed). The full definition for
glPixelStorei
is given next.
void
glPixelStorei
(GLenum
pname,
GLint
param
)
specifies the pixel storage type to set. The following options
impact how data is unpacked from memory when calling
glTexImage2D
,
glTexImage3D
,
glTexSubImage2D
, and
glTexSubImage3D
:
GL_UNPACK_ROW_LENGTH
,
GL_UNPACK_IMAGE_HEIGHT
,
GL_UNPACK_SKIP_PIXELS
,
GL_UNPACK_SKIP_ROWS
,
GL_UNPACK_SKIP_IMAGES
,
GL_UNPACK_ALIGNMENT
pname
The following options impact how data is packed into memory
when calling
glReadPixels
:
GL_PACK_ROW_LENGTH
,
GL_PACK_IMAGE_HEIGHT
,
GL_PACK_SKIP_PIXELS
,
GL_PACK_SKIP_ROWS
,
GL_PACK_SKIP_IMAGES
,
GL_PACK_ALIGNMENT
All of these options are described in Table 9-2.
specifies the integer value for the pack or unpack option.
param
The
GL_PACK_xxxxx
arguments to
glPixelStorei
do not have any impact
on texture image uploading. The pack options are used by
glReadPixels
,
which is described in Chapter 11, “Fragment Operations.” The pack
and unpack options set by
glPixelStorei
are global state and are not
stored or associated with a texture object. In practice, it is rare to use any
options other than
GL_UNPACK_ALIGNMENT
for specifying textures. For
completeness, the full list of pixel storage options is provided in Table 9-2.
Returning to the program in Example 9-1, after defining the image data,
a texture object is generated using
glGenTextures
and then that object
is bound to the
GL_TEXTURE_2D
target using
glBindTexture
. Finally, the
image data is loaded into the texture object using
glTexImage2D
. The
format is set as
GL_RGB
, which signifies that the image data is composed
of (R, G, B) triplets. The type is set as
GL_UNSIGNED_BYTE
, which signifies
that each channel of the data is stored in an 8-bit unsigned byte. There
are a number of other options for loading texture data, including the
different formats described in Table 9-1. All of the texture formats are
described later in this chapter in the
Texture Formats
section.