glReadPixels是一个函数。
glReadPixels
NAME
glReadPixels - read a block of pixels from the frame buffer
C SPECIFICATION
void glReadPixels( GLint x, GLint y, GLsizei width,GLsizei height, GLenum format, GLenum type, GLvoid *pixels)
width, height
Specify the dimensions of the pixel rectangle. width and heightof one correspond to a single pixel.
format
Specifies the format of the pixel data. The following symbolic values areaccepted: GL_COLOR_INDEX, GL_STENCIL_INDEX, GL_DEPTH_COMPONENT,GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA, GL_RGB,GL_RGBA, GL_LUMINANCE, and GL_LUMINANCE_ALPHA.
type
Specifies the data type of the pixel data. Must be one of GL_UNSIGNED_BYTE,GL_BYTE, GL_BITMAP, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT,GL_INT, or GL_FLOAT.
pixels
Returns the pixel data.
DESCRIPTION
glReadPixels returns pixeldata from the frame buffer, starting with the pixel whose lower left corner isat location (x, y), into client memory starting at location pixels.Several parameters control the processing of the pixel data before it is placedinto client memory. These parameters are set with three commands: glPixelStore, glPixelTransfer,and glPixelMap. Thisreference page describes the effects on glReadPixels of most, but notall of the parameters specified by these three commands.
glReadPixels returns valuesfrom each pixel with lower left-hand 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 arereturned in row order from the lowest to the highest row, left to right in eachrow.
format specifies the format for thereturned pixel values. Accepted values for format are as follows:
GL_COLOR_INDEX
Color indices are read from the color buffer selected by glReadBuffer. Eachindex is converted to fixed point, shifted left or right depending on the valueand sign of GL_INDEX_SHIFT, and added to GL_INDEX_OFFSET. If GL_MAP_COLORis GL_TRUE, indices are replaced by their mappings in the table GL_PIXEL_MAP_I_TO_I.
GL_STENCIL_INDEX
Stencil values are read from the stencil buffer. Each index is converted tofixed point, shifted left or right depending on the value and sign of GL_INDEX_SHIFT,and added to GL_INDEX_OFFSET. If GL_MAP_STENCIL is GL_TRUE,indices are replaced by their mappings in the table GL_PIXEL_MAP_S_TO_S.
GL_DEPTH_COMPONENT
Depth values are read from the depth buffer. Each component is converted tofloating point such that the minimum depth value maps to 0.0 and the maximumvalue maps to 1.0. Each component is then multiplied by GL_DEPTH_SCALE,added to GL_DEPTH_BIAS, and finally clamped to the range [0,1].
GL_RED
GL_GREEN
GL_BLUE
GL_ALPHA
GL_RGB
GL_RGBA
GL_LUMINANCE
GL_LUMINANCE_ALPHA
Processing differs depending on whether color buffers store color indices orRGBA color components. If color indices are stored, they are read from thecolor buffer selected by glReadBuffer.Each index is converted to fixed point, shifted left or right depending on thevalue and sign of GL_INDEX_SHIFT, and added to GL_INDEX_OFFSET.Indices are then replaced by the red, green, blue, and alpha values obtained byindexing the GL_PIXEL_MAP_I_TO_R, GL_PIXEL_MAP_I_TO_G, GL_PIXEL_MAP_I_TO_B,and GL_PIXEL_MAP_I_TO_A tables.
If RGBA color components are stored in the color buffers, they are read fromthe color buffer selected by glReadBuffer.Each color component is converted to floating point such that zero intensitymaps to 0.0 and full intensity maps to 1.0. Each component is then multipliedby GL_c_SCALE and added to GL_c_BIAS, where c is GL_RED,GL_GREEN, GL_BLUE, and GL_ALPHA. Each component is clampedto the range [0,1]. Finally, if GL_MAP_COLOR is GL_TRUE, eachcolor component c is replaced by its mapping in the table GL_PIXEL_MAP_c_TO_c,where c again is GL_RED, GL_GREEN, GL_BLUE, and GL_ALPHA.Each component is scaled to the size its corresponding table before the lookupis performed.
Finally, unneeded data is discarded. For example, GL_RED discards thegreen, blue, and alpha components, while GL_RGB discards only the alphacomponent. GL_LUMINANCE computes a single component value as the sum ofthe red, green, and blue components, and GL_LUMINANCE_ALPHA does thesame, while keeping alpha as a second value.
The shift, scale, bias, and lookup factors described above are allspecified by glPixelTransfer.The lookup table contents themselves are specified by glPixelMap.
The final step involves converting the indices or components to the properformat, as specified by type. If format is GL_COLOR_INDEX orGL_STENCIL_INDEX and type is not GL_FLOAT, each index ismasked 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 format.
Ifformat is GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA,GL_RGB, GL_RGBA, GL_LUMINANCE, or GL_LUMINANCE_ALPHAand type is not GL_FLOAT, each component is multiplied by themultiplier shown in the following table. If type is GL_FLOAT, then eachcomponent is passed as is (or converted to the client's single-precisionfloating-point format if it is different from the one used by the GL).
【中文版】
glReadPixels - 从
帧缓存里读取一个像素块
void glReadPixels(GLint x,GLint y,GLsizesi width,GLsizei height,GLenum format,GLenum type,GLvoid *pixel);
函数参数(x, y)定义图像区域左下角点的坐标,width和height分别是图像的高度和宽度,*pixel是一个
指针,指向存储图像数据的
数组。参数format指出所读象素
数据元素的格式(索引值或R、G、B、A值,如下面表所示),而参数type指出每个元素的数据类型(也见下面表)。
写入象素数据:
void glDrawPixels(GLsizesi width,GLsizei height,GLenum format,GLenum type,GLvoid *pixel);
函数参数format和type与glReadPixels( )有相同的意义,pixel指向的
数组包含所要画的象素数据。注意,调用这个函数前必须先设置当前光栅位置,若当前光栅位置无效,则给出该函数时不画任何图形,并且当前光栅位置仍然保持无效。
+++++++++++
像素格式表++++++++++++++++++++++
GL_INDEX 单个颜色索引
GL_RGB 先是红色分量,再是绿色分量,然后是蓝色分量
GL_RED 单个红色分量
GL_GREEN 单个绿色分量
GL_BLUE 单个蓝色分量
GL_ALPHA 单个Alpha值
GL_LUMINANCE_ALPHA 先是亮度分量,然后是Alpha值
GL_STENCIL_INDEX 单个的模板索引
GL_DEPTH_COMPONENT 单个深度分量
++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++ 数据类型+++++++++++++++++++
GL_UNSIGNED_BYTE 无符号的8位整数
GL_BYTE 8位整数
GL_BITMAP 无符号的8位整数数组中的单个数位
GL_UNSIGNED_SHORT 无符号的16位整数
GL_SHORT 16位整数
GL_UNSIGNED_INT 无符号的32位整数
GL_INT 32位整数
+++++++++++++++++++++++++++++++++++++++
图像的每个元素按上面表给出的数据类型存储。若元素表示连续的值,如红、绿、蓝或亮度分量,每个值都按比例放缩使之适合于可用的位数。例如,红色分量是0.0到1.0之 间的浮点值。若它需要放到无符号单字节整数中,也仅有8位精度保存下来,其他
无符号整数类型同理。对于有符号的数据类型还要少一位,例如颜色索引存到有符号的8位整数中,它的第一位被0xfe屏蔽掉了(即这个掩码包含7个1)。若类型是GL_FLOAT,索引值简单地转化成单精度浮点值,例如索引17转化成17.0,同理。