2 * Copyright (c) 1993-2003, Silicon Graphics, Inc.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose and without fee is hereby granted, provided that the above
7 * copyright notice appear in all copies and that both the copyright
8 * notice and this permission notice appear in supporting documentation,
9 * and that the name of Silicon Graphics, Inc. not be used in
10 * advertising or publicity pertaining to distribution of the software
11 * without specific, written prior permission.
13 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" AND
14 * WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
16 * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
17 * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
18 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19 * OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, LOSS OF
20 * PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF THIRD
21 * PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN ADVISED OF
22 * THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON ANY THEORY OF
23 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE POSSESSION, USE
24 * OR PERFORMANCE OF THIS SOFTWARE.
26 * US Government Users Restricted Rights
27 * Use, duplication, or disclosure by the Government is subject to
28 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
29 * (c)(1)(ii) of the Rights in Technical Data and Computer Software
30 * clause at DFARS 252.227-7013 and/or in similar or successor clauses
31 * in the FAR or the DOD or NASA FAR Supplement. Unpublished - rights
32 * reserved under the copyright laws of the United States.
34 * Contractor/manufacturer is:
35 * Silicon Graphics, Inc.
36 * 1500 Crittenden Lane
37 * Mountain View, CA 94043
38 * United State of America
40 * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
46 * This program demonstrates the use of explicit fog
47 * coordinates. You can press the keyboard and change
48 * the fog coordinate value at any vertex. You can
49 * also switch between using explicit fog coordinates
50 * and the default fog generation mode.
52 * Pressing the 'f' and 'b' keys move the viewer forward
54 * Pressing 'c' initiates the default fog generation.
55 * Pressing capital 'C' restores explicit fog coordinates.
56 * Pressing '1', '2', '3', '8', '9', and '0' add or
57 * subtract from the fog coordinate values at one of the
58 * three vertices of the triangle.
67 static GLfloat f1
, f2
, f3
;
71 static void init(void)
73 GLfloat fogColor
[4] = {0.0, 0.25, 0.25, 1.0};
79 glFogi (GL_FOG_MODE
, GL_EXP
);
80 glFogfv (GL_FOG_COLOR
, fogColor
);
81 glFogf (GL_FOG_DENSITY
, 0.25);
82 glHint (GL_FOG_HINT
, GL_DONT_CARE
);
83 glFogi(GL_FOG_COORDINATE_SOURCE_EXT
, GL_FOG_COORDINATE_EXT
);
84 glClearColor(0.0, 0.25, 0.25, 1.0); /* fog color */
87 /* display() draws a triangle at an angle.
89 static void display(void)
91 glClear(GL_COLOR_BUFFER_BIT
);
93 glColor3f (1.0f
, 0.75f
, 0.0f
);
94 glBegin (GL_TRIANGLES
);
96 glVertex3f (2.0f
, -2.0f
, 0.0f
);
98 glVertex3f (-2.0f
, 0.0f
, -5.0f
);
100 glVertex3f (0.0f
, 2.0f
, -10.0f
);
106 static void reshape(int w
, int h
)
108 glViewport(0, 0, (GLsizei
) w
, (GLsizei
) h
);
109 glMatrixMode(GL_PROJECTION
);
111 gluPerspective (45.0, 1.0, 0.25, 25.0);
112 glMatrixMode(GL_MODELVIEW
);
114 glTranslatef (0.0, 0.0, -5.0);
117 static void keyboard(unsigned char key
, int x
, int y
)
121 glFogi(GL_FOG_COORDINATE_SOURCE_EXT
, GL_FRAGMENT_DEPTH_EXT
);
125 glFogi(GL_FOG_COORDINATE_SOURCE_EXT
, GL_FOG_COORDINATE_EXT
);
159 glMatrixMode (GL_MODELVIEW
);
160 glTranslatef (0.0, 0.0, -0.25);
164 glMatrixMode (GL_MODELVIEW
);
165 glTranslatef (0.0, 0.0, 0.25);
178 * Open window with initial window size, title bar,
179 * RGBA display mode, depth buffer, and handle input events.
181 int main(int argc
, char** argv
)
183 glutInit(&argc
, argv
);
184 glutInitDisplayMode (GLUT_DOUBLE
| GLUT_RGB
);
185 glutInitWindowSize(500, 500);
186 glutCreateWindow(argv
[0]);
189 glutReshapeFunc (reshape
);
190 glutKeyboardFunc (keyboard
);
191 glutDisplayFunc (display
);