2 * Copyright 2005 Eric Anholt
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Eric Anholt <anholt@FreeBSD.org>
26 * Brian Paul (fogcoord.c used as a skeleton)
30 * Test to exercise fog modes and for comparison with GL_EXT_fog_coord.
39 static int Width
= 600;
40 static int Height
= 600;
41 static GLfloat Near
= 0.0, Far
= 1.0;
42 GLboolean has_fogcoord
;
44 static void drawString( const char *string
)
48 glutBitmapCharacter( GLUT_BITMAP_TIMES_ROMAN_10
, *string
);
53 static void Display( void )
56 GLfloat fogcolor
[4] = {1, 1, 1, 1};
59 glFogfv(GL_FOG_COLOR
, fogcolor
);
61 glClearColor(0.2, 0.2, 0.8, 0);
62 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
65 for (i
= 0; i
< 6; i
++) {
66 if (i
>= 3 && !has_fogcoord
)
70 for (depthi
= 0; depthi
< 5; depthi
++) {
71 GLfloat depth
= Near
+ (Far
- Near
) * depthi
/ 4;
75 glFogi(GL_FOG_MODE
, GL_LINEAR
);
76 glFogf(GL_FOG_START
, Near
);
77 glFogf(GL_FOG_END
, Far
);
80 glFogi(GL_FOG_MODE
, GL_EXP
);
81 glFogf(GL_FOG_DENSITY
, 2);
84 glFogi(GL_FOG_MODE
, GL_EXP2
);
85 glFogf(GL_FOG_DENSITY
, 2);
89 glColor4f(0, 0, 0, 0);
92 glFogi(GL_FOG_COORDINATE_SOURCE_EXT
, GL_FRAGMENT_DEPTH_EXT
);
95 glVertex3f(0, 0, depth
);
96 glVertex3f(1, 0, depth
);
97 glVertex3f(1, 1, depth
);
98 glVertex3f(0, 1, depth
);
101 glFogi(GL_FOG_COORDINATE_SOURCE_EXT
, GL_FOG_COORDINATE_EXT
);
102 glFogCoordfEXT(depth
);
105 glVertex3f(0, 0, (Near
+ Far
) / 2);
106 glVertex3f(1, 0, (Near
+ Far
) / 2);
107 glVertex3f(1, 1, (Near
+ Far
) / 2);
108 glVertex3f(0, 1, (Near
+ Far
) / 2);
111 glTranslatef(1.5, 0, 0);
114 glTranslatef(.1, 0, 0);
117 drawString("GL_LINEAR");
120 drawString("GL_EXP");
123 drawString("GL_EXP2");
126 drawString("GL_FOGCOORD GL_LINEAR");
129 drawString("GL_FOGCOORD GL_EXP");
132 drawString("GL_FOGCOORD GL_EXP2");
137 glTranslatef(0, 1.5, 0);
145 static void Reshape( int width
, int height
)
149 glViewport( 0, 0, width
, height
);
151 glMatrixMode( GL_PROJECTION
);
153 glOrtho( 0, 11, 9, 0, -Near
, -Far
);
155 glMatrixMode( GL_MODELVIEW
);
157 glTranslatef(.25, .25, 0);
161 static void Key( unsigned char key
, int x
, int y
)
174 static void Init( void )
176 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
177 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION
));
178 /* setup lighting, etc */
179 has_fogcoord
= glutExtensionSupported("GL_EXT_fog_coord");
181 printf("Some output of this program requires GL_EXT_fog_coord\n");
186 int main( int argc
, char *argv
[] )
188 glutInit( &argc
, argv
);
189 glutInitWindowPosition( 0, 0 );
190 glutInitWindowSize( Width
, Height
);
191 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
192 glutCreateWindow(argv
[0]);
194 glutReshapeFunc( Reshape
);
195 glutKeyboardFunc( Key
);
196 glutDisplayFunc( Display
);