Clone of mesa.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

anisotropic.c 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /* $Id: anisotropic.c,v 1.1 2001/03/22 15:24:15 gareth Exp $ */
  2. /*
  3. * GL_ARB_texture_filter_anisotropic demo
  4. *
  5. * Gareth Hughes
  6. * March 2001
  7. *
  8. * Copyright (C) 2000 Brian Paul All Rights Reserved.
  9. *
  10. * Permission is hereby granted, free of charge, to any person obtaining a
  11. * copy of this software and associated documentation files (the "Software"),
  12. * to deal in the Software without restriction, including without limitation
  13. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  14. * and/or sell copies of the Software, and to permit persons to whom the
  15. * Software is furnished to do so, subject to the following conditions:
  16. *
  17. * The above copyright notice and this permission notice shall be included
  18. * in all copies or substantial portions of the Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  21. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  23. * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  24. * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  25. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. */
  27. /* This is a fairly early version. All it does is draw a couple of
  28. * textured quads with different forms of texture filtering. Eventually,
  29. * you'll be able to adjust the maximum anisotropy and so on.
  30. */
  31. #include <math.h>
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include <GL/glut.h>
  35. #define TEXTURE_SIZE 256
  36. static GLubyte image[TEXTURE_SIZE][TEXTURE_SIZE][3];
  37. static GLfloat repeat = 1.0;
  38. static GLfloat texcoords[] = {
  39. 0.0, 0.0,
  40. 0.0, 1.0,
  41. 1.0, 0.0,
  42. 1.0, 1.0
  43. };
  44. static GLfloat vertices[] = {
  45. -400.0, -400.0, 0.0,
  46. -400.0, 400.0, -7000.0,
  47. 400.0, -400.0, 0.0,
  48. 400.0, 400.0, -7000.0
  49. };
  50. static GLfloat maxAnisotropy;
  51. static void init( void )
  52. {
  53. int i, j;
  54. if ( !glutExtensionSupported( "GL_EXT_texture_filter_anisotropic" ) ) {
  55. fprintf( stderr, "Sorry, this demo requires GL_EXT_texture_filter_anisotropic.\n" );
  56. exit( 0 );
  57. }
  58. glClearColor( 0.0, 0.0, 0.0, 0.0 );
  59. glShadeModel( GL_SMOOTH );
  60. /* Init the vertex arrays.
  61. */
  62. glEnableClientState( GL_VERTEX_ARRAY );
  63. glEnableClientState( GL_TEXTURE_COORD_ARRAY );
  64. glVertexPointer( 3, GL_FLOAT, 0, vertices );
  65. glTexCoordPointer( 2, GL_FLOAT, 0, texcoords );
  66. /* Init the texture environment.
  67. */
  68. glEnable( GL_TEXTURE_2D );
  69. glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );
  70. glMatrixMode( GL_TEXTURE );
  71. glScalef( repeat, repeat, 0 );
  72. glMatrixMode( GL_MODELVIEW );
  73. glGetFloatv( GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy );
  74. printf( "Maximum supported anisotropy: %.2f\n", maxAnisotropy );
  75. /* Make the texture image.
  76. */
  77. glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
  78. for ( i = 0 ; i < TEXTURE_SIZE ; i++ ) {
  79. for ( j = 0 ; j < TEXTURE_SIZE ; j++ ) {
  80. if ( (i/4 + j/4) & 1 ) {
  81. image[i][j][0] = 0;
  82. image[i][j][1] = 0;
  83. image[i][j][2] = 0;
  84. } else {
  85. image[i][j][0] = 255;
  86. image[i][j][1] = 255;
  87. image[i][j][2] = 255;
  88. }
  89. }
  90. }
  91. gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGB, TEXTURE_SIZE, TEXTURE_SIZE,
  92. GL_RGB, GL_UNSIGNED_BYTE, image );
  93. }
  94. static void display( void )
  95. {
  96. GLint vp[4], w, h;
  97. glClear( GL_COLOR_BUFFER_BIT );
  98. glGetIntegerv( GL_VIEWPORT, vp );
  99. w = vp[2] / 2;
  100. h = vp[3] / 2;
  101. /* Upper left corner:
  102. */
  103. glViewport( 1, h + 1, w - 2, h - 2 );
  104. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  105. glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy );
  106. glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
  107. /* Upper right corner:
  108. */
  109. glViewport( w + 1, h + 1, w - 2, h - 2 );
  110. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
  111. glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy );
  112. glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
  113. /* Lower left corner:
  114. */
  115. glViewport( 1, 1, w - 2, h - 2 );
  116. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR );
  117. glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy );
  118. glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
  119. /* Lower right corner:
  120. */
  121. glViewport( w + 1, 1, w - 2, h - 2 );
  122. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
  123. glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy );
  124. glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
  125. glViewport( vp[0], vp[1], vp[2], vp[3] );
  126. glutSwapBuffers();
  127. }
  128. static void reshape( int w, int h )
  129. {
  130. glViewport( 0, 0, (GLsizei) w, (GLsizei) h );
  131. glMatrixMode( GL_PROJECTION );
  132. glLoadIdentity();
  133. glFrustum( -1.0, 1.0, -1.0, 1.0, 10.0, 10000.0 );
  134. glMatrixMode( GL_MODELVIEW );
  135. glLoadIdentity();
  136. glTranslatef( 0.0, 0.0, -10.0 );
  137. }
  138. static void key( unsigned char key, int x, int y )
  139. {
  140. (void) x; (void) y;
  141. switch ( key ) {
  142. case 27:
  143. exit( 0 );
  144. }
  145. glutPostRedisplay();
  146. }
  147. static void usage( void )
  148. {
  149. /* Nothing yet... */
  150. }
  151. int main( int argc, char **argv )
  152. {
  153. glutInit( &argc, argv );
  154. glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB );
  155. glutInitWindowSize( 600, 300 );
  156. glutInitWindowPosition( 0, 0 );
  157. glutCreateWindow( "Anisotropic Texture Filter Demo" );
  158. init();
  159. glutDisplayFunc( display );
  160. glutReshapeFunc( reshape );
  161. glutKeyboardFunc( key );
  162. usage();
  163. glutMainLoop();
  164. return 0;
  165. }