<!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>gluPerspective</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /></head><body><div class="refentry" lang="en" xml:lang="en"><a id="gluPerspective"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>gluPerspective — set up a perspective projection matrix</p></div><div class="refsynopsisdiv"><h2>C Specification</h2><div class="funcsynopsis"><table border="0" summary="Function synopsis" cellspacing="0" cellpadding="0"><tr><td><code class="funcdef">void <b class="fsfunc">gluPerspective</b>(</code></td><td>GLdouble  </td><td><var class="pdparam">fovy</var>, </td></tr><tr><td> </td><td>GLdouble  </td><td><var class="pdparam">aspect</var>, </td></tr><tr><td> </td><td>GLdouble  </td><td><var class="pdparam">zNear</var>, </td></tr><tr><td> </td><td>GLdouble  </td><td><var class="pdparam">zFar</var><code>)</code>;</td></tr></table></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="parameters"></a><h2>Parameters</h2><div class="variablelist"><dl><dt><span class="term"><em class="parameter"><code>fovy</code></em></span></dt><dd><p>
                    Specifies the field of view angle, in degrees, in the <span class="emphasis"><em>y</em></span> direction.
                </p></dd><dt><span class="term"><em class="parameter"><code>aspect</code></em></span></dt><dd><p>
                    Specifies the aspect ratio that determines
                    the field of view in the <span class="emphasis"><em>x</em></span> direction.
                    The aspect ratio is the ratio of <span class="emphasis"><em>x</em></span> (width) to <span class="emphasis"><em>y</em></span> (height).
                </p></dd><dt><span class="term"><em class="parameter"><code>zNear</code></em></span></dt><dd><p>
                    Specifies the distance from the viewer to the near clipping plane
                    (always positive).
                </p></dd><dt><span class="term"><em class="parameter"><code>zFar</code></em></span></dt><dd><p>
                    Specifies the distance from the viewer to the far clipping plane
                    (always positive).
                </p></dd></dl></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="description"></a><h2>Description</h2><p>
            <code class="function">gluPerspective</code> specifies a viewing frustum into the world coordinate system.
            In general, the aspect ratio in <code class="function">gluPerspective</code> should match the aspect ratio
            of the associated viewport. For example, 
            <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" overflow="scroll">
                
                <mml:mrow>
                    <mml:mi mathvariant="italic">aspect</mml:mi>
                    <mml:mo>=</mml:mo>
                    <mml:mn>2.0</mml:mn>
                </mml:mrow>
            </mml:math>
            means 
            the viewer's
            angle of view is twice as wide in <span class="emphasis"><em>x</em></span> as it is in <span class="emphasis"><em>y</em></span>.
            If the viewport is
            twice as wide as it is tall, it displays the image without distortion.
        </p><p>
            The matrix generated by <code class="function">gluPerspective</code> is multipled by the current matrix,
            just as if <a class="citerefentry" href="glMultMatrix.xml"><span class="citerefentry"><span class="refentrytitle">glMultMatrix</span></span></a> were called with the generated matrix.
            To load the perspective matrix onto the current matrix stack instead,
            precede the call to <code class="function">gluPerspective</code> with a call to <a class="citerefentry" href="glLoadIdentity.xml"><span class="citerefentry"><span class="refentrytitle">glLoadIdentity</span></span></a>.
        </p><p>
            Given <span class="emphasis"><em>f</em></span> defined as follows:
        </p><p>
            </p><div class="informalequation"><mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" overflow="scroll">
                
                <mml:mrow>
                    <mml:mi mathvariant="italic">f</mml:mi>
                    <mml:mo>=</mml:mo>
                    <mml:mrow>
                        <mml:mi mathvariant="italic">cotangent</mml:mi>
                        <mml:mo>⁡</mml:mo>
                        <mml:mfenced open="(" close=")">
                            <mml:mfrac>
                                <mml:mi mathvariant="italic">fovy</mml:mi>
                                <mml:mn>2</mml:mn>
                            </mml:mfrac>
                        </mml:mfenced>
                    </mml:mrow>
                </mml:mrow>
            </mml:math></div><p>
            The generated matrix is
        </p><p>
            </p><div class="informalequation"><mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" overflow="scroll">
                
                <mml:mfenced open="(" close=")">
                    <mml:mtable>
                        <mml:mtr>
                            <mml:mtd>
                                <mml:mfrac>
                                    <mml:mi mathvariant="italic">f</mml:mi>
                                    <mml:mi mathvariant="italic">aspect</mml:mi>
                                </mml:mfrac>
                            </mml:mtd>
                            <mml:mtd>
                                <mml:mn>0</mml:mn>
                            </mml:mtd>
                            <mml:mtd>
                                <mml:mn>0</mml:mn>
                            </mml:mtd>
                            <mml:mtd>
                                <mml:mn>0</mml:mn>
                            </mml:mtd>
                        </mml:mtr>
                        <mml:mtr>
                            <mml:mtd>
                                <mml:mn>0</mml:mn>
                            </mml:mtd>
                            <mml:mtd>
                                <mml:mi mathvariant="italic">f</mml:mi>
                            </mml:mtd>
                            <mml:mtd>
                                <mml:mn>0</mml:mn>
                            </mml:mtd>
                            <mml:mtd>
                                <mml:mn>0</mml:mn>
                            </mml:mtd>
                        </mml:mtr>
                        <mml:mtr>
                            <mml:mtd>
                                <mml:mn>0</mml:mn>
                            </mml:mtd>
                            <mml:mtd>
                                <mml:mn>0</mml:mn>
                            </mml:mtd>
                            <mml:mtd>
                                <mml:mfrac>
                                    <mml:mfenced open="" close="">
                                        <mml:mrow>
                                            <mml:mi mathvariant="italic">zFar</mml:mi>
                                            <mml:mo>+</mml:mo>
                                            <mml:mi mathvariant="italic">zNear</mml:mi>
                                        </mml:mrow>
                                    </mml:mfenced>
                                    <mml:mfenced open="" close="">
                                        <mml:mrow>
                                            <mml:mi mathvariant="italic">zNear</mml:mi>
                                            <mml:mo>-</mml:mo>
                                            <mml:mi mathvariant="italic">zFar</mml:mi>
                                        </mml:mrow>
                                    </mml:mfenced>
                                </mml:mfrac>
                            </mml:mtd>
                            <mml:mtd>
                                <mml:mfrac>
                                    <mml:mfenced open="" close="">
                                        <mml:mrow>
                                            <mml:mn>2</mml:mn>
                                            <mml:mo>×</mml:mo>
                                            <mml:mi mathvariant="italic">zFar</mml:mi>
                                            <mml:mo>×</mml:mo>
                                            <mml:mi mathvariant="italic">zNear</mml:mi>
                                        </mml:mrow>
                                    </mml:mfenced>
                                    <mml:mfenced open="" close="">
                                        <mml:mrow>
                                            <mml:mi mathvariant="italic">zNear</mml:mi>
                                            <mml:mo>-</mml:mo>
                                            <mml:mi mathvariant="italic">zFar</mml:mi>
                                        </mml:mrow>
                                    </mml:mfenced>
                                </mml:mfrac>
                            </mml:mtd>
                        </mml:mtr>
                        <mml:mtr>
                            <mml:mtd>
                                <mml:mn>0</mml:mn>
                            </mml:mtd>
                            <mml:mtd>
                                <mml:mn>0</mml:mn>
                            </mml:mtd>
                            <mml:mtd>
                                <mml:mn>-1</mml:mn>
                            </mml:mtd>
                            <mml:mtd>
                                <mml:mn>0</mml:mn>
                            </mml:mtd>
                        </mml:mtr>
                    </mml:mtable>
                </mml:mfenced>
            </mml:math></div><p>
        </p></div><div class="refsect1" lang="en" xml:lang="en"><a id="notes"></a><h2>Notes</h2><p>
            Depth buffer precision is affected by the values specified for
            <em class="parameter"><code>zNear</code></em> and <em class="parameter"><code>zFar</code></em>.
            The greater the ratio of <em class="parameter"><code>zFar</code></em> to <em class="parameter"><code>zNear</code></em> is,
            the less effective the depth buffer will be at distinguishing between
            surfaces that are near each other.
            If 
        </p><p>
            <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" overflow="scroll">
                
                <mml:mrow>
                    <mml:mi mathvariant="italic">r</mml:mi>
                    <mml:mo>=</mml:mo>
                    <mml:mfrac>
                        <mml:mi mathvariant="italic">zFar</mml:mi>
                        <mml:mi mathvariant="italic">zNear</mml:mi>
                    </mml:mfrac>
                </mml:mrow>
            </mml:math>
        </p><p>
        </p><p>
            roughly 
            <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" overflow="scroll">
                
                <mml:mrow>
                    <mml:msub><mml:mi mathvariant="italic">log</mml:mi>
                    <mml:mn>2</mml:mn>
                    </mml:msub>
                    <mml:mo>⁡</mml:mo>
                    <mml:mfenced open="(" close=")">
                        <mml:mi mathvariant="italic">r</mml:mi>
                    </mml:mfenced>
                </mml:mrow>
            </mml:math>
            bits of depth buffer precision are lost.
            Because 
            <mml:math xmlns:mml="http://www.w3.org/1998/Math/MathML" overflow="scroll"><mml:mi mathvariant="italic">r</mml:mi></mml:math>
            approaches infinity as <em class="parameter"><code>zNear</code></em> approaches 0,
            <em class="parameter"><code>zNear</code></em> must never be set to 0.
        </p></div><div class="refsect1" lang="en" xml:lang="en"><a id="seealso"></a><h2>See Also</h2><p>
            <a class="citerefentry" href="gluOrtho2D.xml"><span class="citerefentry"><span class="refentrytitle">gluOrtho2D</span></span></a>,
            <a class="citerefentry" href="glFrustum.xml"><span class="citerefentry"><span class="refentrytitle">glFrustum</span></span></a>,
            <a class="citerefentry" href="glLoadIdentity.xml"><span class="citerefentry"><span class="refentrytitle">glLoadIdentity</span></span></a>,
            <a class="citerefentry" href="glMultMatrix.xml"><span class="citerefentry"><span class="refentrytitle">glMultMatrix</span></span></a>
        </p></div><div class="refsect1" lang="en" xml:lang="en"><a id="Copyright"></a><h2>Copyright</h2><p>
            Copyright <span class="trademark"></span>© 1991-2006
            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>
