2 * Exercise GL_EXT_fog_coord
10 #include "glut_wrap.h"
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
);
26 printf("glFogCoord(%4.1f)\n", f
);
30 glTranslatef(t
* 10.0 - 5.0, 0, 0);
43 static void Reshape( int width
, int height
)
45 GLfloat ar
= (float) width
/ (float) height
;
48 glViewport( 0, 0, width
, height
);
49 glMatrixMode( GL_PROJECTION
);
51 glFrustum( -ar
, ar
, -1.0, 1.0, Near
, Far
);
52 glMatrixMode( GL_MODELVIEW
);
54 glTranslatef( 0.0, 0.0, -15.0 );
58 static void Key( unsigned char key
, int x
, int y
)
71 static void Init( void )
73 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
74 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION
));
75 /* setup lighting, etc */
76 if (!glutExtensionSupported("GL_EXT_fog_coord")) {
77 printf("Sorry, this program requires GL_EXT_fog_coord\n");
80 glFogi(GL_FOG_COORDINATE_SOURCE_EXT
, GL_FOG_COORDINATE_EXT
);
81 glFogi(GL_FOG_MODE
, GL_LINEAR
);
82 glFogf(GL_FOG_START
, Near
);
83 glFogf(GL_FOG_END
, Far
);
85 printf("Squares should be colored from white -> gray -> black.\n");
89 int main( int argc
, char *argv
[] )
91 glutInit( &argc
, argv
);
92 glutInitWindowPosition( 0, 0 );
93 glutInitWindowSize( Width
, Height
);
94 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
95 glutCreateWindow(argv
[0]);
97 glutReshapeFunc( Reshape
);
98 glutKeyboardFunc( Key
);
99 glutDisplayFunc( Display
);