2 * Exercise GL_EXT_fog_coord
6 #define GL_GLEXT_PROTOTYPES
12 static int Width
= 600;
13 static int Height
= 200;
14 static GLfloat Near
= 5.0, Far
= 25.0;
17 static void Display( void )
21 glClearColor(0.2, 0.2, 0.8, 0);
22 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
24 for (t
= 0.0; t
<= 1.0; t
+= 0.25) {
25 GLfloat f
= -(Near
+ t
* (Far
- Near
));
29 glTranslatef(t
* 10.0 - 5.0, 0, 0);
42 static void Reshape( int width
, int height
)
44 GLfloat ar
= (float) width
/ (float) height
;
47 glViewport( 0, 0, width
, height
);
48 glMatrixMode( GL_PROJECTION
);
50 glFrustum( -ar
, ar
, -1.0, 1.0, Near
, Far
);
51 glMatrixMode( GL_MODELVIEW
);
53 glTranslatef( 0.0, 0.0, -15.0 );
57 static void Key( unsigned char key
, int x
, int y
)
70 static void Init( void )
72 /* setup lighting, etc */
73 if (!glutExtensionSupported("GL_EXT_fog_coord")) {
74 printf("Sorry, this program requires GL_EXT_fog_coord\n");
77 glFogi(GL_FOG_COORDINATE_SOURCE_EXT
, GL_FOG_COORDINATE_EXT
);
78 glFogi(GL_FOG_MODE
, GL_LINEAR
);
79 glFogf(GL_FOG_START
, Near
);
80 glFogf(GL_FOG_END
, Far
);
82 printf("Squares should be colored from white -> gray -> black.\n");
86 int main( int argc
, char *argv
[] )
88 glutInit( &argc
, argv
);
89 glutInitWindowPosition( 0, 0 );
90 glutInitWindowSize( Width
, Height
);
91 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
92 glutCreateWindow(argv
[0]);
93 glutReshapeFunc( Reshape
);
94 glutKeyboardFunc( Key
);
95 glutDisplayFunc( Display
);