编辑:谦虚网互动百科 时间:2020-04-01 12:05:51
编辑 锁定
x, y
Specify the window coordinates of the first pixel that is read from the framebuffer. This location is the lower left corner of a rectangular block ofpixels.
glReadPixels - read a block of pixels from the frame buffer
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.
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.
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.
Returns the pixel data.
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:
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.
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.
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].
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);
GL_INDEX 单个颜色索引
GL_RGB 先是红色分量,再是绿色分量,然后是蓝色分量
GL_RED 单个红色分量
GL_GREEN 单个绿色分量
GL_BLUE 单个蓝色分量
GL_ALPHA 单个Alpha值
GL_LUMINANCE_ALPHA 先是亮度分量,然后是Alpha值
+++++++++++++++++++ 数据类型+++++++++++++++++++
GL_BYTE 8位整数
GL_BITMAP 无符号的8位整数数组中的单个数位
GL_SHORT 16位整数
GL_INT 32位整数
GL_FLOAT 单精度浮点数
图像的每个元素按上面表给出的数据类型存储。若元素表示连续的值,如红、绿、蓝或亮度分量,每个值都按比例放缩使之适合于可用的位数。例如,红色分量是0.0到1.0之 间的浮点值。若它需要放到无符号单字节整数中,也仅有8位精度保存下来,其他无符号整数类型同理。对于有符号的数据类型还要少一位,例如颜色索引存到有符号的8位整数中,它的第一位被0xfe屏蔽掉了(即这个掩码包含7个1)。若类型是GL_FLOAT,索引值简单地转化成单精度浮点值,例如索引17转化成17.0,同理。
计算机学 动画 其他