<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "xhtml1-transitional.dtd"><!-- saved from url=(0013)about:internet -->
<?xml-stylesheet type="text/xsl" href="mathml.xsl"?><html xmlns="http://www.w3.org/1999/xhtml" xmlns:pref="http://www.w3.org/2002/Math/preference" pref:renderer="mathplayer-dl"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>glReadPixels</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1" /></head><body><div class="refentry"><a id="glReadPixels"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>glReadPixels — read a block of pixels from the color buffer</p></div><div class="refsynopsisdiv"><h2>C Specification</h2><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void <strong class="fsfunc">glReadPixels</strong>(</code></td><td>GLint <var class="pdparam">x</var>, </td></tr><tr><td> </td><td>GLint <var class="pdparam">y</var>, </td></tr><tr><td> </td><td>GLsizei <var class="pdparam">width</var>, </td></tr><tr><td> </td><td>GLsizei <var class="pdparam">height</var>, </td></tr><tr><td> </td><td>GLenum <var class="pdparam">format</var>, </td></tr><tr><td> </td><td>GLenum <var class="pdparam">type</var>, </td></tr><tr><td> </td><td>GLvoid * <var class="pdparam">pixels</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a id="parameters"></a><h2>Parameters</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term">
                <em class="parameter"><code>x</code></em>, <em class="parameter"><code>y</code></em>
                </span></dt><dd><p>Specify the window coordinates of the first pixel
                    that is read from the color buffer. This location is the
                    lower left corner of a rectangular block of pixels.</p></dd><dt><span class="term">
                <em class="parameter"><code>width</code></em>, <em class="parameter"><code>height</code></em>
                </span></dt><dd><p>Specify the dimensions of the pixel rectangle.
                    <em class="parameter"><code>width</code></em> and <em class="parameter"><code>height</code></em>
                    of one correspond to a single pixel.</p></dd><dt><span class="term">
                    <em class="parameter"><code>format</code></em>
                </span></dt><dd><p>Specifies the format of the pixel data. Must be either
                    <code class="constant">GL_RGBA</code> or the value of
                    <code class="constant">GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES</code>.</p></dd><dt><span class="term">
                    <em class="parameter"><code>type</code></em>
                </span></dt><dd><p>Specifies the data type of the pixel data. Must be either
                    <code class="constant">GL_UNSIGNED_BYTE</code> or the value of
                    <code class="constant">GL_IMPLEMENTATION_COLOR_READ_TYPE_OES</code>.</p></dd><dt><span class="term">
                    <em class="parameter"><code>pixels</code></em>
                </span></dt><dd><p>Returns the pixel data.</p></dd></dl></div></div><div class="refsect1"><a id="description"></a><h2>Description</h2><p><code class="function">glReadPixels</code>
        returns pixel data from the color buffer, starting with the
        pixel whose lower left corner is at location
        (<em class="parameter"><code>x</code></em>, <em class="parameter"><code>y</code></em>),
        into client memory starting at location
        <em class="parameter"><code>pixels</code></em>.
        The processing of the pixel data before it is placed into
        client memory can be controlled with
        <a class="citerefentry" href="glPixelStorei.xml"><span class="citerefentry"><span class="refentrytitle">glPixelStorei</span></span></a>.
        </p><p><code class="function">glReadPixels</code>
        returns values from each pixel with lower left corner at
        <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" overflow="scroll">
            <mml:mfenced>
                <mml:mrow><mml:mi>x</mml:mi><mml:mo>+</mml:mo><mml:mi>i</mml:mi></mml:mrow>
                <mml:mrow><mml:mi>y</mml:mi><mml:mo>+</mml:mo><mml:mi>j</mml:mi></mml:mrow>
            </mml:mfenced>
        </mml:math>
        for
        <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" overflow="scroll">
            <mml:mn>0</mml:mn><mml:mo>&lt;=</mml:mo><mml:mi>i</mml:mi><mml:mo>&lt;</mml:mo><mml:mi>width</mml:mi>
        </mml:math>
        and
        <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" overflow="scroll">
            <mml:mn>0</mml:mn><mml:mo>&lt;=</mml:mo><mml:mi>j</mml:mi><mml:mo>&lt;</mml:mo><mml:mi>height</mml:mi>
        </mml:math>.
        This pixel is said to be the <em class="replaceable"><code>i</code></em>th pixel
        in the <em class="replaceable"><code>j</code></em>th row.
        Pixels are returned in row order from the lowest to the
        highest row, left to right in each row.</p><p><em class="parameter"><code>format</code></em>
        specifies the format of the returned pixel values; accepted values are:</p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="constant">GL_ALPHA</code></span></dt><dd></dd><dt><span class="term"><code class="constant">GL_RGB</code></span></dt><dd></dd><dt><span class="term"><code class="constant">GL_RGBA</code></span></dt><dd></dd></dl></div><p>
            RGBA color components are read from the color buffer.
            Each color component is converted to floating point such that zero intensity
            maps to 0.0 and full intensity maps to 1.0.
        </p><p>Unneeded data is then discarded. For example,
        <code class="constant">GL_ALPHA</code>
        discards the red, green, and blue components, while
        <code class="constant">GL_RGB</code>
        discards only the alpha component.
        <code class="constant">GL_LUMINANCE</code>
        computes a single-component value as the sum of the red, green,
        and blue components, and
        <code class="constant">GL_LUMINANCE_ALPHA</code>
        does the same, while keeping alpha as a second value. The final
        values are clamped to the range [0, 1].</p><p>Finally, the components are converted to the proper, as
        specified by <em class="parameter"><code>type</code></em> where each
        component is multiplied by
        <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" overflow="scroll">
            <mml:msup><mml:mn>2</mml:mn><mml:mi>n</mml:mi></mml:msup><mml:mo>-</mml:mo><mml:mn>1</mml:mn>
        </mml:math>,
        where <em class="replaceable"><code>n</code></em> is the number of bits
        per component.</p><p>Return values are placed in memory as follows. If
        <em class="parameter"><code>format</code></em> is
        <code class="constant">GL_ALPHA</code>,
        a single value is returned and the data for the
        <em class="replaceable"><code>i</code></em>th pixel in the
        <em class="replaceable"><code>j</code></em>th row is placed in location
        <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" overflow="scroll">
            <mml:mi>j</mml:mi><mml:mo>*</mml:mo><mml:mi>width</mml:mi><mml:mo>+</mml:mo><mml:mi>i</mml:mi>
        </mml:math>.
        <code class="constant">GL_RGB</code> returns three values and
        <code class="constant">GL_RGBA</code> returns four values for each pixel, with all values
        corresponding to a single pixel occupying contiguous space in
        <em class="parameter"><code>pixels</code></em>.
        Storage parameter <code class="constant">GL_PACK_ALIGNMENT</code> set by
        <a class="citerefentry" href="glPixelStorei.xml"><span class="citerefentry"><span class="refentrytitle">glPixelStorei</span></span></a>,
        affects the way that data is written into memory. See
        <a class="citerefentry" href="glPixelStorei.xml"><span class="citerefentry"><span class="refentrytitle">glPixelStorei</span></span></a>
        for a description.</p></div><div class="refsect1"><a id="notes"></a><h2>Notes</h2><p>
            Only two <em class="parameter"><code>format</code></em>/<em class="parameter"><code>type</code></em> parameter pairs are
            accepted.  <code class="constant">GL_RGBA</code>/<code class="constant">GL_UNSIGNED_BYTE</code> is
            always accepted, and the other acceptable pair can be discovered by querying
            <code class="constant">GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES</code> and
            <code class="constant">GL_IMPLEMENTATION_COLOR_READ_TYPE_OES</code>.
        </p><p>Values for pixels that lie outside the window connected
        to the current GL context are undefined.</p><p>If an error is generated, no change is made to the
        contents of <em class="parameter"><code>pixels</code></em>.</p></div><div class="refsect1"><a id="errors"></a><h2>Errors</h2><p><code class="constant">GL_INVALID_ENUM</code> is generated if
        <em class="parameter"><code>format</code></em> is not
        <code class="constant">GL_RGBA</code> or the value of
        <code class="constant">GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES</code>.</p><p><code class="constant">GL_INVALID_ENUM</code> is generated if
        <em class="parameter"><code>type</code></em> is not
        <code class="constant">GL_UNSIGNED_BYTE</code> or the value of
        <code class="constant">GL_IMPLEMENTATION_COLOR_READ_TYPE_OES</code>.</p><p><code class="constant">GL_INVALID_VALUE</code> is generated if either
        <em class="parameter"><code>width</code></em> or
        <em class="parameter"><code>height</code></em> is negative.</p><p>
            <code class="constant">GL_INVALID_OPERATION</code> is generated if <em class="parameter"><code>type</code></em> is
            <code class="constant">GL_UNSIGNED_SHORT_5_6_5</code>
            and <em class="parameter"><code>format</code></em> is not <code class="constant">GL_RGB</code>.
        </p><p>
            <code class="constant">GL_INVALID_OPERATION</code> is generated if <em class="parameter"><code>type</code></em> is
            <code class="constant">GL_UNSIGNED_SHORT_4_4_4_4</code> or
            <code class="constant">GL_UNSIGNED_SHORT_5_5_5_1</code>
            and <em class="parameter"><code>format</code></em> is not <code class="constant">GL_RGBA</code>.
        </p><p>
            <code class="constant">GL_INVALID_OPERATION</code> is generated if <em class="parameter"><code>format</code></em>
            and <em class="parameter"><code>type</code></em> are neither <code class="constant">GL_RGBA</code> and
            <code class="constant">GL_UNSIGNED_BYTE</code>, respectively, nor the format/type pair
            returned by querying <code class="constant">GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES</code>
            and <code class="constant">GL_IMPLEMENTATION_COLOR_READ_TYPE_OES</code>.
        </p></div><div class="refsect1"><a id="associatedgets"></a><h2>Associated Gets</h2><p>
        <a class="citerefentry" href="glGet.xml"><span class="citerefentry"><span class="refentrytitle">glGet</span></span></a>
        with argument <code class="constant">GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES</code></p><p>
        <a class="citerefentry" href="glGet.xml"><span class="citerefentry"><span class="refentrytitle">glGet</span></span></a>
        with argument <code class="constant">GL_IMPLEMENTATION_COLOR_READ_TYPE_OES</code></p><p>
            <a class="citerefentry" href="glGet.xml"><span class="citerefentry"><span class="refentrytitle">glGet</span></span></a> with argument <code class="constant">GL_PACK_ALIGNMENT</code>
        </p></div><div class="refsect1"><a id="seealso"></a><h2>See Also</h2><p>
            <a class="citerefentry" href="glPixelStorei.xml"><span class="citerefentry"><span class="refentrytitle">glPixelStorei</span></span></a>
        </p></div><div class="refsect1"><a id="copyright"></a><h2>Copyright</h2><p>
            Copyright <span class="trademark"></span>© 2003-2004
            Silicon Graphics, Inc. This document is licensed under the SGI
            Free Software B License. For details, see
            <a class="ulink" href="http://oss.sgi.com/projects/FreeB/" target="_top">http://oss.sgi.com/projects/FreeB/</a>.
        </p></div></div></body></html>