[ Previous | Next | Contents | Glossary | Home | Search ]
OpenGL 1.1 for AIX: Reference Manual

glCopyPixels Subroutine

Purpose

Copies pixels in the frame buffer.

Library

OpenGL C bindings library: libGL.a

C Syntax

void glCopyPixels(GLint xCoordinate, 
                  GLint yCoordinate
                  GLsizei Width,
                  GLsizei Height,
                  GLenum Type)

Parameters

xCoordinate Specifies the x window coordinate of the lower left corner of the rectangular region of pixels to be copied.
yCoordinate Specifies the y window coordinate of the lower left corner of the rectangular region of pixels to be copied.
Width Specifies the width of the rectangular region of pixels to be copied. This parameter does not accept a negative value.
Height Specifies the height of the rectangular region of pixels to be copied. This parameter does not accept a negative value.
Type Specifies whether color values, depth values, or stencil values are to be copied. Symbolic constants GL_COLOR, GL_DEPTH, and GL_STENCIL are accepted.

Description

The glCopyPixels subroutine copies a screen-aligned rectangle of pixels from the specified frame buffer location to a region relative to the current raster position. Its operation is well defined only if the entire pixel source region is within the exposed portion of the window. Results of copies from outside the window, or from regions of the window that are not exposed, are hardware-dependent and undefined.

The x and y parameters specify the window coordinates of the lower left corner of the rectangular region to be copied. The Width and Height parameters specify the dimensions of the rectangular region to be copied. Both Width and Height must be nonnegative numbers.

Several parameters control the processing of the pixel data while it is being copied. These parameters are set with three subroutines: glPixelTransfer, glPixelMap, and glPixelZoom. This article describes the effects on glCopyPixels of most, but not all, of the parameters specified by these three subroutines.

The glCopyPixels subroutine copies values from each pixel with lower left corner at (x + i, y + j) for 0 <= i <Width and 0 <= j <Height. This pixel is said to be the ith pixel in the jth row. Pixels are copied in row order from the lowest to the highest row, left to right in each row.

The Type parameter specifies whether color, depth, or stencil data is to be copied. The details of the transfer for each data type are as follows.

GL_COLOR Indices or red, green, blue, alpha (RGBA) colors are read from the buffer currently specified as the read source buffer. (See the glReadBuffer subroutine.) If the GL is in color index mode, each index that is read from this buffer is converted to a fixed-point format with an unspecified number of bits to the right of the binary point. Each index is then shifted left by GL_INDEX_SHIFT bits and added to GL_INDEX_OFFSET. If GL_INDEX_SHIFT is negative, the shift is to the right. In either case, 0 (zero) bits fill otherwise unspecified bit locations in the result. If GL_MAP_COLOR is True, the index is replaced with the value that it references in lookup table GL_PIXEL_MAP_I_TO_I. Whether the lookup replacement of the index is done or not, the integer part of the index is then ANDed with 2b -1, where b is the number of bits in a color index buffer.

If the GL is in RGBA mode, the red, green, blue, and alpha components of each pixel that is read are converted to an internal floating-point format with unspecified precision. The conversion maps the largest representable component value to 1.0, and component value 0 to 0.0. The resulting floating-point color values are then multiplied by GL_c_SCALE and added to GL_c_BIAS, where c is RED, GREEN, BLUE, and ALPHA for the respective color components. The results are clamped to the range [0,1]. If GL_MAP_COLOR is True, each color component is scaled by the size of the lookup table GL_PIXEL_MAP_c_TO_c, then replaced by the value that it references in that table. c is R, G, B, or A, respectively.

The resulting indices or RGBA colors are then converted to fragments by attaching the current raster position z coordinate and texture coordinates to each pixel, then assigning window coordinates (xr + i , yr + j), where (xr, yr) is the current raster position, and the pixel was the ith pixel in the jth row. These pixel fragments are then treated just like the fragments generated by rasterizing points, lines, or polygons. Texture mapping, fog, and all the fragment operations are applied before the fragments are written to the frame buffer.

GL_DEPTH Depth values are read from the depth buffer and converted directly to an internal floating-point format with unspecified precision. The resulting floating-point depth value is then multiplied by GL_DEPTH_SCALE and added to GL_DEPTH_BIAS. The result is clamped to the range [0,1].

The resulting depth components are then converted to fragments by attaching the current raster position color or color index and texture coordinates to each pixel, then assigning window coordinates (xr + i , yr + j), where (xr, yr) is the current raster position, and the pixel was the ith pixel in the jth row. These pixel fragments are then treated just like the fragments generated by rasterizing points, lines, or polygons. Texture mapping, fog, and all the fragment operations are applied before the fragments are written to the frame buffer.

GL_STENCIL Stencil indices are read from the stencil buffer and converted to an internal fixed-point format with an unspecified number of bits to the right of the binary point. Each fixed-point index is then shifted left by GL_INDEX_SHIFT bits and added to GL_INDEX_OFFSET. If GL_INDEX_SHIFT is negative, the shift is to the right. In either case, 0 bits fill otherwise unspecified bit locations in the result. If GL_MAP_STENCIL is True, the index is replaced with the value that it references in the lookup table GL_PIXEL_MAP_S_TO_S. Whether the lookup replacement of the index is done or not, the integer part of the index is then ANDed with 2b -1, where b is the number of bits in the stencil buffer. The resulting stencil indices are then written to the stencil buffer such that the index read from the ith location of the jth row is written to location (xr + i, yr + j), where (xr, yr) is the current raster position. Only the pixel ownership test, the scissor test, and the stencil writemask affect these writes.

The rasterization described thus far assumes pixel zoom factors of 1.0. If glPixelZoom is used to change the x and y pixel zoom factors, pixels are converted to fragments as follows. If (xr, yr) is the current raster position, and a given pixel is in the ith location in the jth row of the source pixel rectangle, fragments are generated for pixels whose centers are in the rectangle with corners at

Unmapped format: variant of paragraph
(xr + zoomx i, yr + zoomy j)
Unmapped format: variant of paragraph
and
Unmapped format: variant of paragraph
(xr + zoomx (i + 1), yr + zoomy ( j + 1 )),

where zoom x is the value of GL_ZOOM_X and zoomy is the value of GL_ZOOM_Y.

Notes

Modes specified by glPixelStore have no effect on the operation of glCopyPixels.

Errors

GL_INVALID_ENUM Type is not an accepted value.
GL_INVALID_VALUE Either Width or Height is negative.
GL_INVALID_OPERATION Type is GL_DEPTH and there is no depth buffer.
GL_INVALID_OPERATION Type is GL_STENCIL and there is no stencil buffer.
GL_INVALID_OPERATION The glCopyPixels subroutine is called between a call to glBegin and the corresponding call to glEnd.

Associated Gets

Associated gets for the glCopyPixels subroutine are as follows. (See the glGet subroutine for more information.)

glGet with argument GL_CURRENT_RASTER_POSITION.

glGet with argument GL_CURRENT_RASTER_POSITION_VALID.

Examples

To copy the color pixel in the lower left corner of the window to the current raster position, enter the following:

glCopyPixels(0, 0, 1, 1, GL_COLOR);

Files

/usr/include/GL/gl.h Contains C language constants, variable type definitions, and ANSI function prototypes for OpenGL.

Related Information

The glBegin or glEnd subroutine, glDepthFunc subroutine, glDrawBuffer subroutine, glDrawPixels subroutine, glPixelMap subroutine, glPixelTransfer subroutine, glPixelZoom subroutine, glRasterPos subroutine, glReadBuffer subroutine, glReadPixels subroutine, glStencilFunc subroutine.

OpenGL Overview.


[ Previous | Next | Contents | Glossary | Home | Search ]