Brian Paul | d490813 | 2001-03-05 17:31:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Exercise GL_EXT_fog_coord |
| 3 | */ |
| 4 | |
| 5 | |
Brian Paul | d490813 | 2001-03-05 17:31:57 +0000 | [diff] [blame] | 6 | #include <stdio.h> |
| 7 | #include <stdlib.h> |
| 8 | #include <math.h> |
Keith Whitwell | a58065d | 2009-03-10 13:11:23 +0000 | [diff] [blame] | 9 | #include <GL/glew.h> |
Brian Paul | d490813 | 2001-03-05 17:31:57 +0000 | [diff] [blame] | 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) { |
Brian Paul | 64d6dda | 2004-02-16 16:44:40 +0000 | [diff] [blame] | 25 | GLfloat f = Near + t * (Far - Near); |
| 26 | printf("glFogCoord(%4.1f)\n", f); |
Brian Paul | d490813 | 2001-03-05 17:31:57 +0000 | [diff] [blame] | 27 | glFogCoordfEXT(f); |
| 28 | |
| 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(); |
| 38 | } |
| 39 | glutSwapBuffers(); |
| 40 | } |
| 41 | |
| 42 | |
| 43 | static void Reshape( int width, int height ) |
| 44 | { |
| 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 ); |
| 55 | } |
| 56 | |
| 57 | |
| 58 | static void Key( unsigned char key, int x, int y ) |
| 59 | { |
| 60 | (void) x; |
| 61 | (void) y; |
| 62 | switch (key) { |
| 63 | case 27: |
| 64 | exit(0); |
| 65 | break; |
| 66 | } |
| 67 | glutPostRedisplay(); |
| 68 | } |
| 69 | |
| 70 | |
| 71 | static void Init( void ) |
| 72 | { |
Brian Paul | 64d6dda | 2004-02-16 16:44:40 +0000 | [diff] [blame] | 73 | printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); |
| 74 | printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); |
Brian Paul | d490813 | 2001-03-05 17:31:57 +0000 | [diff] [blame] | 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); |
| 79 | } |
| 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"); |
| 86 | } |
| 87 | |
| 88 | |
| 89 | int main( int argc, char *argv[] ) |
| 90 | { |
| 91 | glutInit( &argc, argv ); |
| 92 | glutInitWindowPosition( 0, 0 ); |
| 93 | glutInitWindowSize( Width, Height ); |
| 94 | glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); |
| 95 | glutCreateWindow(argv[0]); |
Keith Whitwell | a58065d | 2009-03-10 13:11:23 +0000 | [diff] [blame] | 96 | glewInit(); |
Brian Paul | d490813 | 2001-03-05 17:31:57 +0000 | [diff] [blame] | 97 | glutReshapeFunc( Reshape ); |
| 98 | glutKeyboardFunc( Key ); |
| 99 | glutDisplayFunc( Display ); |
| 100 | Init(); |
| 101 | glutMainLoop(); |
| 102 | return 0; |
| 103 | } |