
<refentry id="gluPerspective">
    <refmeta>
        <refmetainfo>
            <copyright>
                <year>1991-2006</year>
                <holder>Silicon Graphics, Inc.</holder>
            </copyright>
        </refmetainfo>
        <refentrytitle>gluPerspective</refentrytitle>
        <manvolnum>3G</manvolnum>
    </refmeta>
    <refnamediv>
        <refname>gluPerspective</refname>
        <refpurpose>set up a perspective projection matrix</refpurpose>
    </refnamediv>
    <refsynopsisdiv><title>C Specification</title>
        <funcsynopsis>
            <funcprototype>
                <funcdef>void <function>gluPerspective</function></funcdef>
                <paramdef>GLdouble <parameter>fovy</parameter></paramdef>
                <paramdef>GLdouble <parameter>aspect</parameter></paramdef>
                <paramdef>GLdouble <parameter>zNear</parameter></paramdef>
                <paramdef>GLdouble <parameter>zFar</parameter></paramdef>
            </funcprototype>
        </funcsynopsis>
    </refsynopsisdiv>
    <!-- eqn: ignoring delim $$ -->
    <refsect1 id="parameters"><title>Parameters</title>
        <variablelist>
        <varlistentry>
            <term><parameter>fovy</parameter></term>
            <listitem>
                <para>
                    Specifies the field of view angle, in degrees, in the <emphasis>y</emphasis> direction.
                </para>
            </listitem>
        </varlistentry>
        <varlistentry>
            <term><parameter>aspect</parameter></term>
            <listitem>
                <para>
                    Specifies the aspect ratio that determines
                    the field of view in the <emphasis>x</emphasis> direction.
                    The aspect ratio is the ratio of <emphasis>x</emphasis> (width) to <emphasis>y</emphasis> (height).
                </para>
            </listitem>
        </varlistentry>
        <varlistentry>
            <term><parameter>zNear</parameter></term>
            <listitem>
                <para>
                    Specifies the distance from the viewer to the near clipping plane
                    (always positive).
                </para>
            </listitem>
        </varlistentry>
        <varlistentry>
            <term><parameter>zFar</parameter></term>
            <listitem>
                <para>
                    Specifies the distance from the viewer to the far clipping plane
                    (always positive).
                </para>
            </listitem>
        </varlistentry>
        </variablelist>
    </refsect1>
    <refsect1 id="description"><title>Description</title>
        <para>
            <function>gluPerspective</function> specifies a viewing frustum into the world coordinate system.
            In general, the aspect ratio in <function>gluPerspective</function> should match the aspect ratio
            of the associated viewport. For example, 
            <inlineequation><mml:math>
                <!-- eqn: aspect  =  2.0:-->
                <mml:mrow>
                    <mml:mi mathvariant="italic">aspect</mml:mi>
                    <mml:mo>=</mml:mo>
                    <mml:mn>2.0</mml:mn>
                </mml:mrow>
            </mml:math></inlineequation>
            means 
            the viewer's
            angle of view is twice as wide in <emphasis>x</emphasis> as it is in <emphasis>y</emphasis>.
            If the viewport is
            twice as wide as it is tall, it displays the image without distortion.
        </para>
        <para>
            The matrix generated by <function>gluPerspective</function> is multipled by the current matrix,
            just as if <citerefentry><refentrytitle>glMultMatrix</refentrytitle></citerefentry> were called with the generated matrix.
            To load the perspective matrix onto the current matrix stack instead,
            precede the call to <function>gluPerspective</function> with a call to <citerefentry><refentrytitle>glLoadIdentity</refentrytitle></citerefentry>.
        </para>
        <para>
            Given <emphasis>f</emphasis> defined as follows:
        </para>
        <para>
            <informalequation><mml:math>
                <!-- eqn: f   =  cotangent(fovy over 2):-->
                <mml:mrow>
                    <mml:mi mathvariant="italic">f</mml:mi>
                    <mml:mo>=</mml:mo>
                    <mml:mrow>
                        <mml:mi mathvariant="italic">cotangent</mml:mi>
                        <mml:mo>&af;</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></informalequation>
            The generated matrix is
        </para>
        <para>
            <informalequation><mml:math>
                <!-- eqn: left (    matrix {    ccol { f over aspect above 0 above 0 above 0 }    ccol { 0 above f above 0 above 0 }    ccol { 0 above 0 above {zFar + zNear} over {zNear - zFar} above -1 }    ccol { 0 above 0 above {2 * zFar * zNear} over {zNear - zFar} above 0} }      right ):-->
                <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>&times;</mml:mo>
                                            <mml:mi mathvariant="italic">zFar</mml:mi>
                                            <mml:mo>&times;</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></informalequation>
        </para>
    </refsect1>
    <refsect1 id="notes"><title>Notes</title>
        <para>
            Depth buffer precision is affected by the values specified for
            <parameter>zNear</parameter> and <parameter>zFar</parameter>.
            The greater the ratio of <parameter>zFar</parameter> to <parameter>zNear</parameter> is,
            the less effective the depth buffer will be at distinguishing between
            surfaces that are near each other.
            If 
        </para>
        <para>
            <inlineequation><mml:math>
                <!-- eqn: r  =  zFar over zNear:-->
                <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></inlineequation>
        </para>
        <para>
        </para>
        <para>
            roughly 
            <inlineequation><mml:math>
                <!-- eqn: log sub 2 (r):-->
                <mml:mrow>
                    <mml:msub><mml:mi mathvariant="italic">log</mml:mi>
                    <mml:mn>2</mml:mn>
                    </mml:msub>
                    <mml:mo>&af;</mml:mo>
                    <mml:mfenced open="(" close=")">
                        <mml:mi mathvariant="italic">r</mml:mi>
                    </mml:mfenced>
                </mml:mrow>
            </mml:math></inlineequation>
            bits of depth buffer precision are lost.
            Because 
            <inlineequation><mml:math><mml:mi mathvariant="italic">r</mml:mi></mml:math></inlineequation>
            approaches infinity as <parameter>zNear</parameter> approaches 0,
            <parameter>zNear</parameter> must never be set to 0.
        </para>
    </refsect1>
    <refsect1 id="seealso"><title>See Also</title>
        <para>
            <citerefentry><refentrytitle>gluOrtho2D</refentrytitle></citerefentry>,
            <citerefentry><refentrytitle>glFrustum</refentrytitle></citerefentry>,
            <citerefentry><refentrytitle>glLoadIdentity</refentrytitle></citerefentry>,
            <citerefentry><refentrytitle>glMultMatrix</refentrytitle></citerefentry>
        </para>
    </refsect1>
    <refsect1 id="Copyright"><title>Copyright</title>
        <para>
            Copyright <trademark class="copyright"></trademark> 1991-2006
            Silicon Graphics, Inc. This document is licensed under the SGI
            Free Software B License. For details, see
            <ulink url="http://oss.sgi.com/projects/FreeB/">http://oss.sgi.com/projects/FreeB/</ulink>.
        </para>
    </refsect1>
</refentry>
