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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. printf("glFogCoord(%4.1f)\n", f);
  20. glFogCoordfEXT(f);
  21. glPushMatrix();
  22. glTranslatef(t * 10.0 - 5.0, 0, 0);
  23. glBegin(GL_POLYGON);
  24. glVertex2f(-1, -1);
  25. glVertex2f( 1, -1);
  26. glVertex2f( 1, 1);
  27. glVertex2f(-1, 1);
  28. glEnd();
  29. glPopMatrix();
  30. }
  31. glutSwapBuffers();
  32. }
  33. static void Reshape( int width, int height )
  34. {
  35. GLfloat ar = (float) width / (float) height;
  36. Width = width;
  37. Height = height;
  38. glViewport( 0, 0, width, height );
  39. glMatrixMode( GL_PROJECTION );
  40. glLoadIdentity();
  41. glFrustum( -ar, ar, -1.0, 1.0, Near, Far );
  42. glMatrixMode( GL_MODELVIEW );
  43. glLoadIdentity();
  44. glTranslatef( 0.0, 0.0, -15.0 );
  45. }
  46. static void Key( unsigned char key, int x, int y )
  47. {
  48. (void) x;
  49. (void) y;
  50. switch (key) {
  51. case 27:
  52. exit(0);
  53. break;
  54. }
  55. glutPostRedisplay();
  56. }
  57. static void Init( void )
  58. {
  59. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  60. printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
  61. /* setup lighting, etc */
  62. if (!glutExtensionSupported("GL_EXT_fog_coord")) {
  63. printf("Sorry, this program requires GL_EXT_fog_coord\n");
  64. exit(1);
  65. }
  66. glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);
  67. glFogi(GL_FOG_MODE, GL_LINEAR);
  68. glFogf(GL_FOG_START, Near);
  69. glFogf(GL_FOG_END, Far);
  70. glEnable(GL_FOG);
  71. printf("Squares should be colored from white -> gray -> black.\n");
  72. }
  73. int main( int argc, char *argv[] )
  74. {
  75. glutInit( &argc, argv );
  76. glutInitWindowPosition( 0, 0 );
  77. glutInitWindowSize( Width, Height );
  78. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
  79. glutCreateWindow(argv[0]);
  80. glutReshapeFunc( Reshape );
  81. glutKeyboardFunc( Key );
  82. glutDisplayFunc( Display );
  83. Init();
  84. glutMainLoop();
  85. return 0;
  86. }