glReadPixels

read a block of pixels from the frame buffer

Signature

glReadPixels( GLint ( x ) , GLint ( y ) , GLsizei ( width ) , GLsizei ( height ) , GLenum ( format ) , GLenum ( type ) , GLvoid * ( data ) )-> void
glReadPixels( x , y , width , height , format , type , array = None , outputType = <type 'str'> )
Read specified pixels from the current display buffer

    x,y,width,height -- location and dimensions of the image to read
        from the buffer
    format -- pixel format for the resulting data
    type -- data-format for the resulting data
    array -- optional array/offset into which to store the value
    outputType -- default (bytes) provides string output of the
        results iff OpenGL.UNSIGNED_BYTE_IMAGES_AS_STRING is True
        and type == GL_UNSIGNED_BYTE.  Any other value will cause
        output in the default array output format.

    returns the pixel data array in the format defined by the
    format, type and outputType
    
glReadPixelsf( x , y , width , height , format , type = GL_FLOAT , array = None , outputType = <type 'str'> )
Read specified pixels from the current display buffer

        This typed version returns data in your specified default
        array data-type format, or in the passed array, which will
        be converted to the array-type required by the format.
        
glReadPixelsi( x , y , width , height , format , type = GL_INT , array = None , outputType = <type 'str'> )
Read specified pixels from the current display buffer

        This typed version returns data in your specified default
        array data-type format, or in the passed array, which will
        be converted to the array-type required by the format.
        
glReadPixelss( x , y , width , height , format , type = GL_SHORT , array = None , outputType = <type 'str'> )
Read specified pixels from the current display buffer

        This typed version returns data in your specified default
        array data-type format, or in the passed array, which will
        be converted to the array-type required by the format.
        
glReadPixelsui( x , y , width , height , format , type = GL_UNSIGNED_INT , array = None , outputType = <type 'str'> )
Read specified pixels from the current display buffer

        This typed version returns data in your specified default
        array data-type format, or in the passed array, which will
        be converted to the array-type required by the format.
        
glReadPixelsus( x , y , width , height , format , type = GL_UNSIGNED_SHORT , array = None , outputType = <type 'str'> )
Read specified pixels from the current display buffer

        This typed version returns data in your specified default
        array data-type format, or in the passed array, which will
        be converted to the array-type required by the format.
        

Parameters

VariablesDescription
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.
width, height
Specify the dimensions of the pixel rectangle. width and height of one correspond to a single pixel.
format
Specifies the format of the pixel data. The following symbolic values are accepted: GL_STENCIL_INDEX , GL_DEPTH_COMPONENT , GL_DEPTH_STENCIL , GL_RED , GL_GREEN , GL_BLUE , GL_RGB , GL_BGR , GL_RGBA , and GL_BGRA .
type
Specifies the data type of the pixel data. Must be one of GL_UNSIGNED_BYTE , GL_BYTE , GL_UNSIGNED_SHORT , GL_SHORT , GL_UNSIGNED_INT , GL_INT , GL_HALF_FLOAT , 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 , GL_UNSIGNED_INT_2_10_10_10_REV , GL_UNSIGNED_INT_24_8 , GL_UNSIGNED_INT_10F_11F_11F_REV , GL_UNSIGNED_INT_5_9_9_9_REV , or GL_FLOAT_32_UNSIGNED_INT_24_8_REV .
data
Returns the pixel data.

Sample Code References

The following code samples have been found which appear to reference the functions described here. Take care that the code may be old, broken or not even use PyOpenGL.

glReadPixels
OpenGLContext tests/readpixelsleak.py Lines: 25
OpenGLContext tests/saveimage.py Lines: 106, 154
OpenGLContext tests/pbodemo.py Lines: 24
OpenGLContext OpenGLContext/passes/flatcore.py Lines: 258, 263
OpenGLContext OpenGLContext/passes/_flat.py Lines: 536, 541
OpenGLContext OpenGLContext/passes/flatcompat.py Lines: 274, 279
OpenGLContext OpenGLContext/debug/bufferimage.py Lines: 66
OpenGL-Demo PyOpenGL-Demo/GLUT/tom/conesave.py Lines: 34
{LGPL} VisionEgg VisionEgg/Core.py Lines: 470
{LGPL} PyMT examples/apps/3Ddrawing/3Ddrawing.py Lines: 159
{LGPL} PyMT pymt/modules/keybinding.py Lines: 34, 37
{LGPL} PyMT pymt/modules/recordvideo.py Lines: 9, 20
{LGPL} PyMT pymt/modules/mjpegserver.py Lines: 32, 161
{LGPL} PyMT pymt/graphx/fbo.py Lines: 20, 252
Visvis core/axes.py Lines: 45
Visvis functions/getframe.py Lines: 49
{GPL3} OpenGL-Programmable 01-direct.py Lines: 109
{GPL3} OpenGL-Programmable 06-perpixel.py Lines: 213
{GPL3} OpenGL-Programmable 09-gles2.py Lines: 263
{GPL3} OpenGL-Programmable 03-array.py Lines: 120
{GPL3} OpenGL-Programmable 10-gl3.2core.py Lines: 273
{GPL3} OpenGL-Programmable 08-pbo.py Lines: 241
{GPL3} OpenGL-Programmable 02-displaylist.py Lines: 118
{GPL3} OpenGL-Programmable 05-shader.py Lines: 205
{GPL3} OpenGL-Programmable 07-attrib.py Lines: 224
{GPL3} OpenGL-Programmable 04-vbo.py Lines: 139