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.

bumpmap.c 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * Copyright (c) 2009 VMware, Inc.
  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. * on the rights to use, copy, modify, merge, publish, distribute, sub
  9. * license, and/or sell copies of the Software, and to permit persons to whom
  10. * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
  19. * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
  20. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  21. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  22. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. /**
  25. * Simple test for testing ATI_envmap_bumpmap support.
  26. */
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include <math.h>
  31. #include <GL/glut.h>
  32. #include "readtex.h"
  33. static PFNGLGETTEXBUMPPARAMETERFVATIPROC glGetTexBumpParameterfvATI_func = NULL;
  34. static PFNGLGETTEXBUMPPARAMETERIVATIPROC glGetTexBumpParameterivATI_func = NULL;
  35. static PFNGLTEXBUMPPARAMETERFVATIPROC glTexBumpParameterfvATI_func = NULL;
  36. static const char *TexFile = "../images/arch.rgb";
  37. static const GLfloat Near = 5.0, Far = 25.0;
  38. static void Display( void )
  39. {
  40. /* together with the construction of dudv map, do fixed translation
  41. in y direction (up), some cosine deformation in x and more
  42. deformation in y dir */
  43. GLfloat bumpMatrix[4] = {0.1, 0.0, 0.2, 0.1};
  44. glClearColor(0.2, 0.2, 0.8, 0);
  45. glClear( GL_COLOR_BUFFER_BIT );
  46. glPushMatrix();
  47. /* this is the base map */
  48. glActiveTexture( GL_TEXTURE0 );
  49. glEnable( GL_TEXTURE_2D );
  50. glBindTexture( GL_TEXTURE_2D, 1 );
  51. glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
  52. glTexEnvf( GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE );
  53. glTexEnvf( GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE );
  54. /* bump map */
  55. glActiveTexture( GL_TEXTURE1 );
  56. glEnable( GL_TEXTURE_2D );
  57. glBindTexture( GL_TEXTURE_2D, 2 );
  58. glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
  59. glTexEnvf( GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_BUMP_ENVMAP_ATI );
  60. glTexEnvf( GL_TEXTURE_ENV, GL_BUMP_TARGET_ATI, GL_TEXTURE0);
  61. glTexBumpParameterfvATI_func(GL_BUMP_ROT_MATRIX_ATI, bumpMatrix);
  62. glCallList(1);
  63. glPopMatrix();
  64. glutSwapBuffers();
  65. }
  66. static void Reshape( int width, int height )
  67. {
  68. GLfloat ar = (float) width / (float) height;
  69. glViewport( 0, 0, width, height );
  70. glMatrixMode( GL_PROJECTION );
  71. glLoadIdentity();
  72. glFrustum( -ar, ar, -1.0, 1.0, Near, Far );
  73. glMatrixMode( GL_MODELVIEW );
  74. glLoadIdentity();
  75. glTranslatef( 0.0, 0.0, -6.0 );
  76. }
  77. static void Key( unsigned char key, int x, int y )
  78. {
  79. (void) x;
  80. (void) y;
  81. switch (key) {
  82. case 27:
  83. exit(0);
  84. break;
  85. }
  86. glutPostRedisplay();
  87. }
  88. static void Init( void )
  89. {
  90. const char * const ver_string = (const char * const)
  91. glGetString( GL_VERSION );
  92. GLfloat temp[16][16][2];
  93. GLubyte *image = NULL;
  94. GLint imgWidth, imgHeight;
  95. GLenum imgFormat;
  96. GLint i,j;
  97. GLint param, paramArray[16];
  98. GLfloat paramMat[4];
  99. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  100. printf("GL_VERSION = %s\n", ver_string);
  101. if ( !glutExtensionSupported("GL_ATI_envmap_bumpmap")) {
  102. printf("\nSorry, this program requires GL_ATI_envmap_bumpmap\n");
  103. exit(1);
  104. }
  105. glGetTexBumpParameterfvATI_func = glutGetProcAddress("glGetTexBumpParameterfvATI");
  106. glGetTexBumpParameterivATI_func = glutGetProcAddress("glGetTexBumpParameterivATI");
  107. glTexBumpParameterfvATI_func = glutGetProcAddress("glTexBumpParameterfvATI");
  108. glGetTexBumpParameterivATI_func(GL_BUMP_ROT_MATRIX_SIZE_ATI, &param);
  109. printf("BUMP_ROT_MATRIX_SIZE_ATI = %d\n", param);
  110. glGetTexBumpParameterivATI_func(GL_BUMP_NUM_TEX_UNITS_ATI, &param);
  111. printf("BUMP_NUM_TEX_UNITS_ATI = %d\n", param);
  112. glGetTexBumpParameterfvATI_func(GL_BUMP_ROT_MATRIX_ATI, paramMat);
  113. printf("initial rot matrix %f %f %f %f\n", paramMat[0], paramMat[1], paramMat[2], paramMat[3]);
  114. glGetTexBumpParameterivATI_func(GL_BUMP_TEX_UNITS_ATI, paramArray);
  115. printf("units supporting bump mapping: ");
  116. for (i = 0; i < param; i++)
  117. printf("%d ", paramArray[i] - GL_TEXTURE0);
  118. printf("\n");
  119. image = LoadRGBImage(TexFile, &imgWidth, &imgHeight, &imgFormat);
  120. if (!image) {
  121. printf("Couldn't read %s\n", TexFile);
  122. exit(0);
  123. }
  124. glBindTexture( GL_TEXTURE_2D, 1 );
  125. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
  126. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
  127. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
  128. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
  129. glTexImage2D( GL_TEXTURE_2D, 0, imgFormat, imgWidth, imgHeight, 0,
  130. imgFormat, GL_UNSIGNED_BYTE, image );
  131. for (j = 0; j < 16; j++) {
  132. for (i = 0; i < 16; i++) {
  133. temp[j][i][0] = cos((float)(i) * 3.1415 / 16.0);
  134. temp[j][i][1] = -0.5;
  135. }
  136. }
  137. glBindTexture( GL_TEXTURE_2D, 2 );
  138. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
  139. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
  140. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
  141. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
  142. glTexImage2D( GL_TEXTURE_2D, 0, GL_DU8DV8_ATI, 16, 16, 0,
  143. GL_DUDV_ATI, GL_FLOAT, temp );
  144. glNewList( 1, GL_COMPILE );
  145. glBegin(GL_QUADS);
  146. glColor3f( 0.9, 0.0, 0.0 );
  147. glMultiTexCoord2f( GL_TEXTURE0, 0.0, 0.0 );
  148. glMultiTexCoord2f( GL_TEXTURE1, 0.0, 0.0 );
  149. glVertex2f(-1, -1);
  150. glMultiTexCoord2f( GL_TEXTURE0, 1.0, 0.0 );
  151. glMultiTexCoord2f( GL_TEXTURE1, 1.0, 0.0 );
  152. glVertex2f( 1, -1);
  153. glMultiTexCoord2f( GL_TEXTURE0, 1.0, 1.0 );
  154. glMultiTexCoord2f( GL_TEXTURE1, 1.0, 1.0 );
  155. glVertex2f( 1, 1);
  156. glMultiTexCoord2f( GL_TEXTURE0, 0.0, 1.0 );
  157. glMultiTexCoord2f( GL_TEXTURE1, 0.0, 1.0 );
  158. glVertex2f(-1, 1);
  159. glEnd();
  160. glEndList();
  161. }
  162. int main( int argc, char *argv[] )
  163. {
  164. glutInit( &argc, argv );
  165. glutInitWindowPosition( 0, 0 );
  166. glutInitWindowSize( 400, 400 );
  167. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
  168. glutCreateWindow( "GL_ATI_envmap_bumpmap test" );
  169. glutReshapeFunc( Reshape );
  170. glutKeyboardFunc( Key );
  171. glutDisplayFunc( Display );
  172. Init();
  173. glutMainLoop();
  174. return 0;
  175. }