GLREADPIXELS(3G)
okay so this is the GLREADPIXELS(3G) page, and she is here to teach you how to grab a whole block of pixels out of the frame buffer, bestie. iconic behavior, no cap π
β¨
πΈ NAME πΈ
glReadPixels β read a block of pixels from the frame buffer. literally what it says on the tin, and I am obsessed π«Ά
π» C SPECIFICATION π»
void glReadPixels( GLint x,
GLint y,
GLsizei width,
GLsizei height,
GLenum format,
GLenum type,
GLvoid *pixels )
delim $$
π PARAMETERS π
x,yβ specify the window coordinates of the first pixel that is read from the frame buffer. This location is the lower left corner of a rectangular block of pixels. corner girlie πwidth,heightβ specify the dimensions of the pixel rectangle.widthandheightof one correspond to a single pixel. one by one is still a block, okay? β¨formatβ specifies the of the pixel data. yes, there is a lil blank in the original right there, and I am not inventing a word for it π. The following symbolic values are accepted:GL_COLOR_INDEX,GL_STENCIL_INDEX,GL_DEPTH_COMPONENT,GL_RED,GL_GREEN,GL_BLUE,GL_ALPHA,GL_RGB,GL_BGR,GL_RGBA,GL_BGRA,GL_LUMINANCE, andGL_LUMINANCE_ALPHA.typeβ specifies the data type of the pixel data. Must be one ofGL_UNSIGNED_BYTE,GL_BYTE,GL_BITMAP,GL_UNSIGNED_SHORT,GL_SHORT,GL_UNSIGNED_INT,GL_INT,GL_FLOAT,GL_UNSIGNED_BYTE_3_3_2,GL_UNSIGNED_BYTE_2_3_3_REV,GL_UNSIGNED_SHORT_5_6_5,GL_UNSIGNED_SHORT_5_6_5_REV,GL_UNSIGNED_SHORT_4_4_4_4,GL_UNSIGNED_SHORT_4_4_4_4_REV,GL_UNSIGNED_SHORT_5_5_5_1,GL_UNSIGNED_SHORT_1_5_5_5_REV,GL_UNSIGNED_INT_8_8_8_8,GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2, orGL_UNSIGNED_INT_2_10_10_10_REV.pixelsβ returns the pixel data. thatβs the whole point, bestie π
β¨ DESCRIPTION β¨
glReadPixels returns pixel data from the frame buffer, starting with the pixel whose lower left corner is at location (x, y), into client memory starting at location pixels. Several parameters control the processing of the pixel data before it is placed into client memory. These parameters are set with three commands: glPixelStore, glPixelTransfer, and glPixelMap. This reference page describes the effects on glReadPixels of most, but not all of the parameters specified by these three commands. yes, βmost, but not allβ β she said what she said π«Ά
When the GL_ARB_imaging extension is supported, the pixel data may be processed by additional operations including color table lookup, color matrix transformations, convolutions, histograms and minimum and maximun pixel value computations. (that βmaximunβ is the originalβs typo, not mine, I promise π)
glReadPixels returns 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 $i$th pixel in the $j$th row. Pixels are returned in row order from the lowest to the highest row, left to right in each row. row by row, left to right, main character energy π
format specifies the for the returned pixel values (another blank in the original, bestie π); accepted values are:
GL_COLOR_INDEXβ Color indices are read from the color buffer selected byglReadBuffer. Each index is converted to fixed point, shifted left or right depending on the value and sign ofGL_INDEX_SHIFT, and added toGL_INDEX_OFFSET. IfGL_MAP_COLORisGL_TRUE, indices are replaced by their mappings in the tableGL_PIXEL_MAP_I_TO_I.GL_STENCIL_INDEXβ Stencil values are read from the stencil buffer. Each index is converted to fixed point, shifted left or right depending on the value and sign ofGL_INDEX_SHIFT, and added toGL_INDEX_OFFSET. IfGL_MAP_STENCILisGL_TRUE, indices are replaced by their mappings in the tableGL_PIXEL_MAP_S_TO_S.GL_DEPTH_COMPONENTβ Depth values are read from the depth buffer. Each component is converted to floating point such that the minimum depth value maps to 0 and the maximum value maps to 1. Each component is then multiplied byGL_DEPTH_SCALE, added toGL_DEPTH_BIAS, and finally clamped to the range[0,1].GL_RED,GL_GREEN,GL_BLUE,GL_ALPHA,GL_RGB,GL_BGR,GL_RGBA,GL_BGRA,GL_LUMINANCE,GL_LUMINANCE_ALPHAβ Processing differs depending on whether color buffers store color indices or RGBA color components. If color indices are stored, they are read from the color buffer selected byglReadBuffer. Each index is converted to fixed point, shifted left or right depending on the value and sign ofGL_INDEX_SHIFT, and added toGL_INDEX_OFFSET. Indices are then replaced by the red, green, blue, and alpha values obtained by indexing the tablesGL_PIXEL_MAP_I_TO_R,GL_PIXEL_MAP_I_TO_G,GL_PIXEL_MAP_I_TO_B, andGL_PIXEL_MAP_I_TO_A. Each table must be of size$2 sup n$, but$n$may be different for different tables. Before an index is used to look up a value in a table of size$2 sup n$, it must be masked against$2 sup n - 1$.
If RGBA color components are stored in the color buffers, they are read from the color buffer selected by glReadBuffer. Each color component is converted to floating point such that zero intensity maps to 0.0 and full intensity maps to 1.0. Each component is then multiplied by GL_c_SCALE and added to GL_c_BIAS, where c is RED, GREEN, BLUE, or ALPHA. Finally, if GL_MAP_COLOR is GL_TRUE, each component is clamped to the range [0, 1], scaled to the size of its corresponding table, and is then replaced by its mapping in the table GL_PIXEL_MAP_c_TO_c, where c is R, G, B, or A.
Unneeded data is then discarded. For example, GL_RED discards the green, blue, and alpha components, while GL_RGB discards only the alpha component. GL_LUMINANCE computes a single-component value as the sum of the red, green, and blue components, and GL_LUMINANCE_ALPHA does the same, while keeping alpha as a second value. The final values are clamped to the range [0, 1].
The shift, scale, bias, and lookup factors just described are all specified by glPixelTransfer. The lookup table contents themselves are specified by glPixelMap. okay so those two are the backstage crew for this whole production π
Finally, the indices or components are converted to the proper , as specified by type. (again, the blank is in the original β Iβm preserving the vibe, not fixing it π). If format is GL_COLOR_INDEX or GL_STENCIL_INDEX and type is not GL_FLOAT, each index is masked with the mask value given in the following table. If type is GL_FLOAT, then each integer index is converted to single-precision floating-point .
If format is GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA, GL_RGB, GL_BGR, GL_RGBA, GL_BGRA, GL_LUMINANCE, or GL_LUMINANCE_ALPHA and type is not GL_FLOAT, each component is multiplied by the multiplier shown in the following table. If type is GL_FLOAT, then each component is passed as is (or converted to the client's single-precision floating-point if it is different from the one used by the GL). table time, bestie β stay with me π₯
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
type index mask component conversion
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
GL_UNSIGNED_BYTE $2"^"8 - 1$ $(2"^"8 - 1) c$
GL_BYTE $2"^"7 - 1$ $[(2"^"8 - 1) c - 1] / 2$
GL_BITMAP $1$ $1$
GL_UNSIGNED_SHORT $2"^"16 - 1$ $(2"^"16 - 1) c$
GL_SHORT $2"^"15 - 1$ $[(2"^"16 - 1) c - 1] / 2$
GL_UNSIGNED_INT $2"^"32 - 1$ $(2"^"32 - 1) c$
GL_INT $2"^"31 - 1$ $[(2"^"32 - 1) c - 1] / 2$
GL_FLOAT none $c$
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Return values are placed in memory as follows. If format is GL_COLOR_INDEX, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT, GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA, or GL_LUMINANCE, a single value is returned and the data for the $i$th pixel in the $j$th row is placed in location $(j)~"width"~+~i$. GL_RGB and GL_BGR return three values, GL_RGBA and GL_BGRA return four values, and GL_LUMINANCE_ALPHA returns two values for each pixel, with all values corresponding to a single pixel occupying contiguous space in pixels. Storage parameters set by glPixelStore, such as GL_PACK_LSB_FIRST and GL_PACK_SWAP_BYTES, affect the way that data is written into memory. See glPixelStore for a description. memory layout girlies, we love to see it π
π NOTES π
Values for pixels that lie outside the window connected to the current GL context are undefined. not cute-undefined, actually undefined, so donβt come for me if you poke outside the window π
If an error is generated, no change is made to the contents of pixels. at least sheβs polite about it π«Ά
π¨ ERRORS π¨
GL_INVALID_ENUMis generated ifformatortypeis not an accepted value.GL_INVALID_ENUMis generated iftypeisGL_BITMAPandformatis notGL_COLOR_INDEXorGL_STENCIL_INDEX.GL_INVALID_VALUEis generated if eitherwidthorheightis negative.GL_INVALID_OPERATIONis generated ifformatisGL_COLOR_INDEXand the color buffers store RGBA color components.GL_INVALID_OPERATIONis generated ifformatisGL_STENCIL_INDEXand there is no stencil buffer.GL_INVALID_OPERATIONis generated ifformatisGL_DEPTH_COMPONENTand there is no depth buffer.GL_INVALID_OPERATIONis generated ifglReadPixelsis executed between the execution ofglBeginand the corresponding execution ofglEnd.GL_INVALID_OPERATIONis generated iftypeis one ofGL_UNSIGNED_BYTE_3_3_2,GL_UNSIGNED_BYTE_2_3_3_REV,GL_UNSIGNED_SHORT_5_6_5, orGL_UNSIGNED_SHORT_5_6_5_REVandformatis notGL_RGB.GL_INVALID_OPERATIONis generated iftypeis one ofGL_UNSIGNED_SHORT_4_4_4_4,GL_UNSIGNED_SHORT_4_4_4_4_REV,GL_UNSIGNED_SHORT_5_5_5_1,GL_UNSIGNED_SHORT_1_5_5_5_REV,GL_UNSIGNED_INT_8_8_8_8,GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2, orGL_UNSIGNED_INT_2_10_10_10_REVandformatis neitherGL_RGBAnorGL_BGRA.
The formatsGL_BGR, andGL_BGRAand typesGL_UNSIGNED_BYTE_3_3_2,GL_UNSIGNED_BYTE_2_3_3_REV,GL_UNSIGNED_SHORT_5_6_5,GL_UNSIGNED_SHORT_5_6_5_REV,GL_UNSIGNED_SHORT_4_4_4_4,GL_UNSIGNED_SHORT_4_4_4_4_REV,GL_UNSIGNED_SHORT_5_5_5_1,GL_UNSIGNED_SHORT_1_5_5_5_REV,GL_UNSIGNED_INT_8_8_8_8,GL_UNSIGNED_INT_8_8_8_8_REV,GL_UNSIGNED_INT_10_10_10_2, andGL_UNSIGNED_INT_2_10_10_10_REVare available only if the GL version is 1.2 or greater. version check, bestie β no cap π
π ASSOCIATED GETS π
glGet with argument GL_INDEX_MODE.
π«Ά SEE ALSO π«Ά
glCopyPixels(3G)glDrawPixels(3G)glPixelMap(3G)glPixelStore(3G)glPixelTransfer(3G)glReadBuffer(3G)
cute sign-off time: source/version is GLREADPIXELS(3G), the footer just says GLREADPIXELS(3G) and there is no date in this copyβs footer, so thatβs the whole sparkly saga β mwah πβ¨π«Ά
π¦ where this page comes from
- opensuse-leap 16.0: Mesa-libGL-devel 24.1.7-160000.3.1 Β· MIT
- opensuse-leap 16.0: Mesa-libGL-devel 24.3.3-160000.3.1 Β· MIT
- opensuse-leap 16.0: Mesa-libGL-devel 24.3.3-160000.3.1 Β· MIT
- opensuse-leap 16.0: Mesa-libGL-devel 24.3.3-160000.3.1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms