GL_EXT_fog_coord test
[mesa.git] / progs / tests / fogcoord.c
1 /*
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
12 static int Width = 600;
13 static int Height = 200;
14 static GLfloat Near = 5.0, Far = 25.0;
15
16
17 static 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
42 static 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
57 static 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
70 static 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
86 int 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 }