2
/* Copyright (c) Mark J. Kilgard, 1994. */
5
* (c) Copyright 1993, Silicon Graphics, Inc.
7
* Permission to use, copy, modify, and distribute this software for
8
* any purpose and without fee is hereby granted, provided that the above
9
* copyright notice appear in all copies and that both the copyright notice
10
* and this permission notice appear in supporting documentation, and that
11
* the name of Silicon Graphics, Inc. not be used in advertising
12
* or publicity pertaining to distribution of the software without specific,
13
* written prior permission.
15
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
16
* AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
17
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
18
* FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19
* GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
20
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
21
* KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
22
* LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
23
* THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
24
* ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
25
* ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
26
* POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
28
* US Government Users Restricted Rights
29
* Use, duplication, or disclosure by the Government is subject to
30
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
31
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
32
* clause at DFARS 252.227-7013 and/or in similar or successor
33
* clauses in the FAR or the DOD or NASA FAR Supplement.
34
* Unpublished-- rights reserved under the copyright laws of the
35
* United States. Contractor/manufacturer is Silicon Graphics,
36
* Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
38
* OpenGL(TM) is a trademark of Silicon Graphics, Inc.
42
* This program draws 5 red teapots, each at a different
43
* z distance from the eye, in different types of fog.
44
* Pressing the left mouse button chooses between 3 types of
45
* fog: exponential, exponential squared, and linear.
46
* In this program, there is a fixed density value, as well
47
* as fixed start and end values for the linear fog.
60
glFogf(GL_FOG_START, 1.0);
61
glFogf(GL_FOG_END, 5.0);
65
glFogi(GL_FOG_MODE, mode);
73
/* Initialize z-buffer, projection matrix, light source,
74
* and lighting model. Do not specify a material property here.
81
GLfloat local_view[] =
84
glEnable(GL_DEPTH_TEST);
87
glLightfv(GL_LIGHT0, GL_POSITION, position);
88
glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view);
91
glEnable(GL_LIGHTING);
93
glEnable(GL_AUTO_NORMAL);
94
glEnable(GL_NORMALIZE);
101
glFogi(GL_FOG_MODE, fogMode);
102
glFogfv(GL_FOG_COLOR, fogColor);
103
glFogf(GL_FOG_DENSITY, 0.35);
104
glHint(GL_FOG_HINT, GL_DONT_CARE);
105
glClearColor(0.5, 0.5, 0.5, 1.0);
110
renderRedTeapot(GLfloat x, GLfloat y, GLfloat z)
115
glTranslatef(x, y, z);
120
glMaterialfv(GL_FRONT, GL_AMBIENT, mat);
124
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat);
128
glMaterialfv(GL_FRONT, GL_SPECULAR, mat);
129
glMaterialf(GL_FRONT, GL_SHININESS, 0.6 * 128.0);
130
glutSolidTeapot(1.0);
134
/* display() draws 5 teapots at different z positions.
139
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
140
renderRedTeapot(-4.0, -0.5, -1.0);
141
renderRedTeapot(-2.0, -0.5, -2.0);
142
renderRedTeapot(0.0, -0.5, -3.0);
143
renderRedTeapot(2.0, -0.5, -4.0);
144
renderRedTeapot(4.0, -0.5, -5.0);
149
myReshape(int w, int h)
151
glViewport(0, 0, w, h);
152
glMatrixMode(GL_PROJECTION);
155
glOrtho(-6.0, 6.0, -2.0 * ((GLfloat) h * 3) / (GLfloat) w,
156
2.0 * ((GLfloat) h * 3) / (GLfloat) w, 0.0, 10.0);
158
glOrtho(-6.0 * (GLfloat) w / ((GLfloat) h * 3),
159
6.0 * (GLfloat) w / ((GLfloat) h * 3), -2.0, 2.0, 0.0, 10.0);
160
glMatrixMode(GL_MODELVIEW);
165
key(unsigned char k, int x, int y)
168
case 27: /* Escape */
178
* Open window with initial window size, title bar,
179
* RGBA display mode, depth buffer, and handle input events.
182
main(int argc, char **argv)
184
glutInit(&argc, argv);
185
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
186
glutInitWindowSize(450, 150);
187
glutCreateWindow(argv[0]);
189
glutReshapeFunc(myReshape);
190
glutDisplayFunc(display);
191
glutCreateMenu(selectFog);
192
glutAddMenuEntry("Fog EXP", GL_EXP);
193
glutAddMenuEntry("Fog EXP2", GL_EXP2);
194
glutAddMenuEntry("Fog LINEAR", GL_LINEAR);
195
glutAddMenuEntry("Quit", 0);
196
glutAttachMenu(GLUT_RIGHT_BUTTON);
197
glutKeyboardFunc(key);
199
return 0; /* ANSI C requires main to return int. */