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 demonstrates fog in color index mode.
43 * Three cones are drawn at different z values in a linear
44 * fog. 32 contiguous colors (from 16 to 47) are loaded
50 /* Initialize color map and fog. Set screen clear color
51 * to end of color ramp.
61 glEnable(GL_DEPTH_TEST
);
63 for (i
= 0; i
< NUM_COLORS
; i
++) {
65 shade
= (GLfloat
) (NUM_COLORS
- i
) / (GLfloat
) NUM_COLORS
;
66 glutSetColor(16 + i
, shade
, shade
, shade
);
70 glFogi(GL_FOG_MODE
, GL_LINEAR
);
71 glFogi(GL_FOG_INDEX
, NUM_COLORS
);
72 glFogf(GL_FOG_START
, 0.0);
73 glFogf(GL_FOG_END
, 4.0);
74 glHint(GL_FOG_HINT
, GL_NICEST
);
75 glClearIndex((GLfloat
) (NUM_COLORS
+ RAMPSTART
- 1));
78 /* display() renders 3 cones at different z positions.
83 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
85 glTranslatef(-1.0, -1.0, -1.0);
86 glRotatef(-90.0, 1.0, 0.0, 0.0);
88 glutSolidCone(1.0, 2.0, 10, 10);
92 glTranslatef(0.0, -1.0, -2.25);
93 glRotatef(-90.0, 1.0, 0.0, 0.0);
95 glutSolidCone(1.0, 2.0, 10, 10);
99 glTranslatef(1.0, -1.0, -3.5);
100 glRotatef(-90.0, 1.0, 0.0, 0.0);
102 glutSolidCone(1.0, 2.0, 10, 10);
108 myReshape(int w
, int h
)
110 glViewport(0, 0, w
, h
);
111 glMatrixMode(GL_PROJECTION
);
114 glOrtho(-2.0, 2.0, -2.0 * (GLfloat
) h
/ (GLfloat
) w
,
115 2.0 * (GLfloat
) h
/ (GLfloat
) w
, 0.0, 10.0);
117 glOrtho(-2.0 * (GLfloat
) w
/ (GLfloat
) h
,
118 2.0 * (GLfloat
) w
/ (GLfloat
) h
, -2.0, 2.0, 0.0, 10.0);
119 glMatrixMode(GL_MODELVIEW
);
124 key(unsigned char k
, int x
, int y
)
127 case 27: /* Escape */
137 * Open window with initial window size, title bar,
138 * RGBA display mode, depth buffer, and handle input events.
141 main(int argc
, char **argv
)
143 glutInit(&argc
, argv
);
144 glutInitDisplayMode(GLUT_SINGLE
| GLUT_INDEX
| GLUT_DEPTH
);
145 glutCreateWindow(argv
[0]);
147 glutReshapeFunc(myReshape
);
148 glutDisplayFunc(display
);
149 glutKeyboardFunc(key
);
151 return 0; /* ANSI C requires main to return int. */