WIP - port to Mali EGL
[mesa-demos/mali.git] / src / tests / fogcoord.c
blob408e6ca3d9ac86a3cbddbc4264a3dc9d4d902611
1 /*
2 * Exercise GL_EXT_fog_coord
3 */
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <math.h>
9 #include <GL/glew.h>
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 )
19 GLfloat t;
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);
27 glFogCoordfEXT(f);
29 glPushMatrix();
30 glTranslatef(t * 10.0 - 5.0, 0, 0);
31 glBegin(GL_POLYGON);
32 glVertex2f(-1, -1);
33 glVertex2f( 1, -1);
34 glVertex2f( 1, 1);
35 glVertex2f(-1, 1);
36 glEnd();
37 glPopMatrix();
39 glutSwapBuffers();
43 static void Reshape( int width, int height )
45 GLfloat ar = (float) width / (float) height;
46 Width = width;
47 Height = height;
48 glViewport( 0, 0, width, height );
49 glMatrixMode( GL_PROJECTION );
50 glLoadIdentity();
51 glFrustum( -ar, ar, -1.0, 1.0, Near, Far );
52 glMatrixMode( GL_MODELVIEW );
53 glLoadIdentity();
54 glTranslatef( 0.0, 0.0, -15.0 );
58 static void Key( unsigned char key, int x, int y )
60 (void) x;
61 (void) y;
62 switch (key) {
63 case 27:
64 exit(0);
65 break;
67 glutPostRedisplay();
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");
78 exit(1);
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);
84 glEnable(GL_FOG);
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]);
96 glewInit();
97 glutReshapeFunc( Reshape );
98 glutKeyboardFunc( Key );
99 glutDisplayFunc( Display );
100 Init();
101 glutMainLoop();
102 return 0;