Graphics Reference
In-Depth Information
format
specifies the pixel format that you would like returned.
Three formats are available:
GL_RGBA
,
GL_RGBA_INTEGER
, and
the value returned by querying
GL_IMPLEMENTATION_COLOR_
READ_FORMAT
, which is an implementation-specific pixel format.
type
specifies the data type of the pixels returned. Five types are
available:
GL_UNSIGNED_BYTE
,
GL_UNSIGNED_INT
,
GL_INT
,
GL_FLOAT
, and the value returned from querying
GL_IMPLEMENTATION_COLOR_READ_TYPE
, which is
an implementation-specific pixel type.
pixels
a contiguous array of bytes that contain the values read from
the color buffer after
glReadPixels
returns.
Aside from the fixed format (
GL_RGBA
and
GL_RGBA_INTEGER
) and type
(
GL_UNSIGNED_BYTE
,
GL_UNSIGNED_INT
,
GL_INT
, and
GL_FLOAT
),
notice
that there are implementation-dependent values that should return the
best format and type combination for the implementation you're using.
The implementation-specific values can be queried as follows:
GLint readType, readFormat;
GLubyte *pixels;
glGetIntegerv ( GL_IMPLEMENTATION_COLOR_READ_TYPE,
&readType );
glGetIntegerv ( GL_IMPLEMENTATION_COLOR_READ_FORMAT,
&readFormat );
unsigned int bytesPerPixel = 0;
switch ( readType )
{
case GL_UNSIGNED_BYTE:
case GL_BYTE:
switch ( readFormat )
{
case GL_RGBA:
bytesPerPixel = 4;
break;
case GL_RGB:
case GL_RGB_INTEGER:
bytesPerPixel = 3;
break;
case GL_RG:
case GL_RG_INTEGER:
case GL_LUMINANCE_ALPHA:
(continues)