blob: e5a24d865ae434416ba194ac1563b0fd046acfbd [file] [log] [blame]
Brian Pauld4908132001-03-05 17:31:57 +00001/*
2 * Exercise GL_EXT_fog_coord
3 */
4
5
6#define GL_GLEXT_PROTOTYPES
7#include <stdio.h>
8#include <stdlib.h>
9#include <math.h>
10#include <GL/glut.h>
11
12static int Width = 600;
13static int Height = 200;
14static GLfloat Near = 5.0, Far = 25.0;
15
16
17static void Display( void )
18{
19 GLfloat t;
20
21 glClearColor(0.2, 0.2, 0.8, 0);
22 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
23
24 for (t = 0.0; t <= 1.0; t += 0.25) {
25 GLfloat f = -(Near + t * (Far - Near));
26 glFogCoordfEXT(f);
27
28 glPushMatrix();
29 glTranslatef(t * 10.0 - 5.0, 0, 0);
30 glBegin(GL_POLYGON);
31 glVertex2f(-1, -1);
32 glVertex2f( 1, -1);
33 glVertex2f( 1, 1);
34 glVertex2f(-1, 1);
35 glEnd();
36 glPopMatrix();
37 }
38 glutSwapBuffers();
39}
40
41
42static void Reshape( int width, int height )
43{
44 GLfloat ar = (float) width / (float) height;
45 Width = width;
46 Height = height;
47 glViewport( 0, 0, width, height );
48 glMatrixMode( GL_PROJECTION );
49 glLoadIdentity();
50 glFrustum( -ar, ar, -1.0, 1.0, Near, Far );
51 glMatrixMode( GL_MODELVIEW );
52 glLoadIdentity();
53 glTranslatef( 0.0, 0.0, -15.0 );
54}
55
56
57static void Key( unsigned char key, int x, int y )
58{
59 (void) x;
60 (void) y;
61 switch (key) {
62 case 27:
63 exit(0);
64 break;
65 }
66 glutPostRedisplay();
67}
68
69
70static void Init( void )
71{
72 /* setup lighting, etc */
73 if (!glutExtensionSupported("GL_EXT_fog_coord")) {
74 printf("Sorry, this program requires GL_EXT_fog_coord\n");
75 exit(1);
76 }
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);
81 glEnable(GL_FOG);
82 printf("Squares should be colored from white -> gray -> black.\n");
83}
84
85
86int main( int argc, char *argv[] )
87{
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 );
96 Init();
97 glutMainLoop();
98 return 0;
99}