glCopyPixels function
The glCopyPixels function copies pixels in the framebuffer.
Syntax
void WINAPI glCopyPixels(
GLint x,
GLint y,
GLsizei width,
GLsizei height,
GLenum type
);
Parameters
-
x
-
The window x-plane coordinate of the lower-left corner of the rectangular region of pixels to be copied.
-
y
-
The window y-plane coordinate of the lower-left corner of the rectangular region of pixels to be copied.
-
width
-
The width dimension of the rectangular region of pixels to be copied. Must be nonnegative.
-
height
-
The height dimension of the rectangular region of pixels to be copied. Must be nonnegative.
-
type
-
Specifies whether glCopyPixels is to copy color values, depth values, or stencil values. The acceptable symbolic constants are.
Value Meaning - GL_COLOR
The glCopyPixels function reads indexes or RGBA colors from the buffer currently specified as the read source buffer (see glReadBuffer).
If OpenGL 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 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, 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.
- 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 zero 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 lookup table GL_PIXEL_MAP_c_TO_c, and then replaced by the value that it references in that table; c is R, G, B, or A, respectively. The resulting indexes or RGBA colors are then converted to fragments by attaching the current raster position z-coordinate and texture coordinates to each pixel, and then assigning window coordinates (xr + i, yr + j), where (xr , yr ) is the current raster position, and the pixel was the pixel in the i position in the j 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 framebuffer.
- 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 pixel in the i position in the j 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 framebuffer.- GL_STENCIL
Stencil indexes 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, zero 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 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 indexes are then written to the stencil buffer such that the index read from the i location of the j 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.
Return value
This function does not return a value.
Error codes
The following error codes can be retrieved by the glGetError function.
Name | Meaning |
---|---|
|
type was not an accepted value. |
|
Either width or height was negative. |
|
type was GL_DEPTH and there was no depth buffer. |
|
type was GL_STENCIL and there was no stencil buffer. |
|
The function was called between a call to glBegin and the corresponding call to glEnd. |
Remarks
The glCopyPixels function copies a screen-aligned rectangle of pixels from the specified framebuffer 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.
Several parameters control the processing of the pixel data while it is being copied. These parameters are set with three functions: glPixelTransfer, glPixelMap, and glPixelZoom. This topic describes the effects on glCopyPixels of most, but not all, of the parameters specified by these three functions.
The glCopyPixels function copies values from each pixel with the lower-left corner at (x + i, y + j) for 0 = i < width and 0 = j < height. This pixel is said to be the i pixel in the j 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 rasterization described thus far assumes pixel zoom factors of 1.0. If you use glPixelZoom 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 i location in the j row of the source pixel rectangle, then fragments are generated for pixels whose centers are in the rectangle with corners at
(xr + zoom? i, yr + zoomy j)
and
(xr + zoom? (i + 1), yr + zoomy (j + 1))
where zoom? is the value of GL_ZOOM_X and zoomy is the value of GL_ZOOM_Y.
Modes specified by glPixelStore have no effect on the operation of glCopyPixels.
The following functions retrieve information related to glCopyPixels:
glGet with argument GL_CURRENT_RASTER_POSITION
glGet with argument GL_CURRENT_RASTER_POSITION_VALID
To copy the color pixel in the lower-left corner of the window to the current raster position, use
glCopyPixels( 0, 0, 1, 1, GL_COLOR );
Requirements
Requirement | Value |
---|---|
Minimum supported client |
Windows 2000 Professional [desktop apps only] |
Minimum supported server |
Windows 2000 Server [desktop apps only] |
Header |
|
Library |
|
DLL |
|