<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook V4.2//EN" "DTD/docbook/docbookx.dtd">
<!--
License Applicability. Except to the extent portions of this file are
made subject to an alternative license as permitted in the SGI Free
Software License B, Version 1.1 (the "License"), the contents of this
file are subject only to the provisions of the License. You may not use
this file except in compliance with the License. You may obtain a copy
of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
http://oss.sgi.com/projects/FreeB
Note that, as provided in the License, the Software is distributed on an
"AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
Original Code. The Original Code is: OpenGL ES Reference Manual,
Version 1.0, released September 2003, developed by Silicon Graphics,
Inc. The Original Code is Copyright (c) 2003 Silicon Graphics, Inc.
Copyright in any portions created by third parties is as indicated
elsewhere herein. All Rights Reserved.
-->
<refentry id="glFog">
<refmeta>
<refentrytitle>glFog</refentrytitle>
<manvolnum>3G</manvolnum>
</refmeta>
<refnamediv>
<refdescriptor>glFog</refdescriptor>
<refname>glFogf</refname>
<refname>glFogx</refname>
<refname>glFogfv</refname>
<refname>glFogxv</refname>
<refpurpose>specify fog parameters</refpurpose>
</refnamediv>
<refsynopsisdiv>
<title>C Specification</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>glFogf</function></funcdef>
<paramdef>GLenum <parameter>pname</parameter></paramdef>
<paramdef>GLfloat <parameter>param</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>void <function>glFogx</function></funcdef>
<paramdef>GLenum <parameter>pname</parameter></paramdef>
<paramdef>GLfixed <parameter>param</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>Parameters</title>
<variablelist>
<varlistentry>
<term>
<parameter>pname</parameter>
</term>
<listitem>
<para>Specifies a single-valued fog parameter.
<constant>GL_FOG_MODE</constant>,
<constant>GL_FOG_DENSITY</constant>,
<constant>GL_FOG_START</constant>, and
<constant>GL_FOG_END</constant> are accepted.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<parameter>param</parameter>
</term>
<listitem>
<para>Specifies the value that
<parameter>pname</parameter>
will be set to.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsynopsisdiv>
<title>C Specification</title>
<funcsynopsis>
<funcprototype>
<funcdef>void <function>glFogfv</function></funcdef>
<paramdef>GLenum <parameter>pname</parameter></paramdef>
<paramdef>const GLfloat * <parameter>params</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>void <function>glFogxv</function></funcdef>
<paramdef>GLenum <parameter>pname</parameter></paramdef>
<paramdef>const GLfixed * <parameter>params</parameter></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1>
<title>Parameters</title>
<variablelist>
<varlistentry>
<term>
<parameter>pname</parameter>
</term>
<listitem>
<para>Specifies a fog parameter.
<constant>GL_FOG_MODE</constant>,
<constant>GL_FOG_DENSITY</constant>,
<constant>GL_FOG_START</constant>,
<constant>GL_FOG_END</constant>, and
<constant>GL_FOG_COLOR</constant> are accepted.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<parameter>params</parameter>
</term>
<listitem>
<para>Specifies the value or values to be assigned to
<parameter>pname</parameter>.
<constant>GL_FOG_COLOR</constant>
requires an array of four values. All other parameters
accept an array containing only a single value.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>Description</title>
<para>If fog is enabled, fog affects
rasterized geometry, bitmaps, and pixel blocks, but not buffer
clear operations. To enable and disable fog, call
<citerefentry><refentrytitle>glEnable</refentrytitle></citerefentry> and
<citerefentry><refentrytitle>glDisable</refentrytitle></citerefentry>
with argument <constant>GL_FOG</constant>.
Fog is initially disabled.
</para>
<para>
<function>glFog</function> assigns the value or values in
<parameter>params</parameter> to the fog parameter specified by
<parameter>pname</parameter>. The following values are accepted for
<parameter>pname</parameter>:</para>
<variablelist>
<varlistentry>
<term>
<constant>GL_FOG_MODE</constant>
</term>
<listitem>
<para>
<parameter>params</parameter>
is a single fixed-point or floating-point value that
specifies the equation to be used to compute the fog
blend factor <replaceable>f</replaceable>.
Three symbolic constants are accepted:
<constant>GL_LINEAR</constant>,
<constant>GL_EXP</constant>, and
<constant>GL_EXP2</constant>.
The equations corresponding to these symbolic constants
are defined below. The initial fog mode is
<constant>GL_EXP</constant>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>GL_FOG_DENSITY</constant>
</term>
<listitem>
<para>
<parameter>params</parameter>
is a single fixed-point or floating-point value that
specifies <replaceable>density</replaceable>,
the fog density used in both exponential fog equations.
Only nonnegative densities are accepted. The initial fog
density is 1.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>GL_FOG_START</constant>
</term>
<listitem>
<para>
<parameter>params</parameter>
is a single fixed-point or floating-point value that
specifies <replaceable>start</replaceable>,
the near distance used in the linear fog equation. The
initial near distance is 0.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>GL_FOG_END</constant>
</term>
<listitem>
<para>
<parameter>params</parameter>
is a single fixed-point or floating-point value that
specifies <replaceable>end</replaceable>,
the far distance used in the linear fog equation. The
initial far distance is 1.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<constant>GL_FOG_COLOR</constant>
</term>
<listitem>
<para>
<parameter>params</parameter>
contains four fixed-point or floating-point values that specify
<inlineequation><math>
<msub><mi>C</mi><mi>f</mi></msub>
</math></inlineequation>,
the fog color. Both fixed-point and floating-point
values are mapped directly. After conversion, all color
components are clamped to the range [0, 1]. The initial
fog color is (0, 0, 0, 0).</para>
</listitem>
</varlistentry>
</variablelist>
<para>Fog blends a fog color with each rasterized pixel
fragment's posttexturing color using a blending factor
<replaceable>f</replaceable>. Factor <replaceable>f</replaceable>
is computed in one of three ways, depending on the fog mode.
Let <replaceable>z</replaceable>
be the distance in eye coordinates from the origin to the
fragment being fogged. The equation for <constant>GL_LINEAR</constant>
fog is</para>
<informalequation><math>
<mi>f</mi><mo>=</mo>
<mfrac>
<mrow><mi>end</mi><mo>-</mo><mi>z</mi></mrow>
<mrow><mi>end</mi><mo>-</mo><mi>start</mi></mrow>
</mfrac>
</math></informalequation>
<para>The equation for <constant>GL_EXP</constant> fog is</para>
<informalequation><math>
<mi>f</mi><mo>=</mo>
<msup>
<mi>e</mi>
<mrow><mo>-</mo><mo>(</mo><mi>density</mi><mo>-</mo><mi>z</mi><mo>)</mo></mrow>
</msup>
</math></informalequation>
<para>The equation for <constant>GL_EXP2</constant> fog is</para>
<informalequation><math>
<mi>f</mi><mo>=</mo>
<msup>
<mi>e</mi>
<msup>
<mrow><mo>-</mo><mo>(</mo><mi>density</mi><mo>-</mo><mi>z</mi><mo>)</mo></mrow>
<mn>2</mn>
</msup>
</msup>
</math></informalequation>
<para>Regardless of the fog mode, <replaceable>f</replaceable>
is clamped to the range [0, 1] after it is computed. Then,
the fragment's red, green, and blue colors, represented by
<inlineequation><math>
<msub><mi>C</mi><mi>r</mi></msub>
</math></inlineequation>,
are replaced by</para>
<informalequation><math>
<msub><mi>C'</mi><mi>r</mi></msub><mo>=</mo>
<mi>f</mi>
<msub>
<mi>C</mi>
<mi>r</mi>
</msub>
<mo>+</mo>
<mfenced><mrow><mn>1</mn><mo>-</mo><mi>f</mi></mrow></mfenced>
<msub>
<mi>C</mi>
<mi>f</mi>
</msub>
</math></informalequation>
<para>Fog does not affect a fragment's alpha component.</para>
</refsect1>
<refsect1>
<title>Errors</title>
<para><constant>GL_INVALID_ENUM</constant> is generated if
<parameter>pname</parameter> is not an accepted value, or if
<parameter>pname</parameter> is
<constant>GL_FOG_MODE</constant> and
<parameter>params</parameter> is not an accepted value.</para>
<para><constant>GL_INVALID_VALUE</constant> is generated if
<parameter>pname</parameter> is
<constant>GL_FOG_DENSITY</constant>, and
<parameter>params</parameter> is negative.</para>
</refsect1>
<refsect1>
<title>See Also</title>
<para>
<citerefentry><refentrytitle>glEnable</refentrytitle></citerefentry>
</para>
</refsect1>
</refentry>