Clone of mesa.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

fog.c 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * Copyright 2005 Eric Anholt
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. *
  24. * Authors:
  25. * Eric Anholt <anholt@FreeBSD.org>
  26. * Brian Paul (fogcoord.c used as a skeleton)
  27. */
  28. /*
  29. * Test to exercise fog modes and for comparison with GL_EXT_fog_coord.
  30. */
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include <math.h>
  34. #include <GL/glew.h>
  35. #include <GL/glut.h>
  36. static int Width = 600;
  37. static int Height = 600;
  38. static GLfloat Near = 0.0, Far = 1.0;
  39. GLboolean has_fogcoord;
  40. static void drawString( const char *string )
  41. {
  42. glRasterPos2f(0, .5);
  43. while ( *string ) {
  44. glutBitmapCharacter( GLUT_BITMAP_TIMES_ROMAN_10, *string );
  45. string++;
  46. }
  47. }
  48. static void Display( void )
  49. {
  50. GLint i, depthi;
  51. GLfloat fogcolor[4] = {1, 1, 1, 1};
  52. glEnable(GL_FOG);
  53. glFogfv(GL_FOG_COLOR, fogcolor);
  54. glClearColor(0.2, 0.2, 0.8, 0);
  55. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  56. glPushMatrix();
  57. for (i = 0; i < 6; i++) {
  58. if (i >= 3 && !has_fogcoord)
  59. break;
  60. glPushMatrix();
  61. for (depthi = 0; depthi < 5; depthi++) {
  62. GLfloat depth = Near + (Far - Near) * depthi / 4;
  63. switch (i % 3) {
  64. case 0:
  65. glFogi(GL_FOG_MODE, GL_LINEAR);
  66. glFogf(GL_FOG_START, Near);
  67. glFogf(GL_FOG_END, Far);
  68. break;
  69. case 1:
  70. glFogi(GL_FOG_MODE, GL_EXP);
  71. glFogf(GL_FOG_DENSITY, 2);
  72. break;
  73. case 2:
  74. glFogi(GL_FOG_MODE, GL_EXP2);
  75. glFogf(GL_FOG_DENSITY, 2);
  76. break;
  77. }
  78. glColor4f(0, 0, 0, 0);
  79. if (i < 3) {
  80. if (has_fogcoord)
  81. glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FRAGMENT_DEPTH_EXT);
  82. glBegin(GL_POLYGON);
  83. glVertex3f(0, 0, depth);
  84. glVertex3f(1, 0, depth);
  85. glVertex3f(1, 1, depth);
  86. glVertex3f(0, 1, depth);
  87. glEnd();
  88. } else {
  89. glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);
  90. glFogCoordfEXT(depth);
  91. glBegin(GL_POLYGON);
  92. glVertex3f(0, 0, (Near + Far) / 2);
  93. glVertex3f(1, 0, (Near + Far) / 2);
  94. glVertex3f(1, 1, (Near + Far) / 2);
  95. glVertex3f(0, 1, (Near + Far) / 2);
  96. glEnd();
  97. }
  98. glTranslatef(1.5, 0, 0);
  99. }
  100. glTranslatef(.1, 0, 0);
  101. switch (i) {
  102. case 0:
  103. drawString("GL_LINEAR");
  104. break;
  105. case 1:
  106. drawString("GL_EXP");
  107. break;
  108. case 2:
  109. drawString("GL_EXP2");
  110. break;
  111. case 3:
  112. drawString("GL_FOGCOORD GL_LINEAR");
  113. break;
  114. case 4:
  115. drawString("GL_FOGCOORD GL_EXP");
  116. break;
  117. case 5:
  118. drawString("GL_FOGCOORD GL_EXP2");
  119. break;
  120. }
  121. glPopMatrix();
  122. glTranslatef(0, 1.5, 0);
  123. }
  124. glPopMatrix();
  125. glutSwapBuffers();
  126. }
  127. static void Reshape( int width, int height )
  128. {
  129. Width = width;
  130. Height = height;
  131. glViewport( 0, 0, width, height );
  132. glMatrixMode( GL_PROJECTION );
  133. glLoadIdentity();
  134. glOrtho( 0, 11, 9, 0, -Near, -Far );
  135. glMatrixMode( GL_MODELVIEW );
  136. glLoadIdentity();
  137. glTranslatef(.25, .25, 0);
  138. }
  139. static void Key( unsigned char key, int x, int y )
  140. {
  141. (void) x;
  142. (void) y;
  143. switch (key) {
  144. case 27:
  145. exit(0);
  146. break;
  147. }
  148. glutPostRedisplay();
  149. }
  150. static void Init( void )
  151. {
  152. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  153. printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
  154. /* setup lighting, etc */
  155. has_fogcoord = glutExtensionSupported("GL_EXT_fog_coord");
  156. if (!has_fogcoord) {
  157. printf("Some output of this program requires GL_EXT_fog_coord\n");
  158. }
  159. }
  160. int main( int argc, char *argv[] )
  161. {
  162. glutInit( &argc, argv );
  163. glutInitWindowPosition( 0, 0 );
  164. glutInitWindowSize( Width, Height );
  165. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
  166. glutCreateWindow(argv[0]);
  167. glewInit();
  168. glutReshapeFunc( Reshape );
  169. glutKeyboardFunc( Key );
  170. glutDisplayFunc( Display );
  171. Init();
  172. glutMainLoop();
  173. return 0;
  174. }