Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fogcoord.c 2.1KB

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