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.

crossbar.c 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. * (C) Copyright IBM Corporation 2005
  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. * \file crossbar.c
  26. *
  27. * Simple test of GL_ARB_texture_env_crossbar functionality. Several squares
  28. * are drawn with different texture combine modes, but all should be rendered
  29. * with the same final color.
  30. *
  31. * \author Ian Romanick <idr@us.ibm.com>
  32. */
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include <string.h>
  36. #include <GL/glew.h>
  37. #include <GL/glut.h>
  38. static const GLint tests[][8] = {
  39. { 1, GL_REPLACE, GL_PRIMARY_COLOR, GL_PRIMARY_COLOR,
  40. 2, GL_REPLACE, GL_TEXTURE, GL_PRIMARY_COLOR },
  41. { 3, GL_REPLACE, GL_PRIMARY_COLOR, GL_PRIMARY_COLOR,
  42. 2, GL_SUBTRACT, GL_TEXTURE0, GL_TEXTURE1 },
  43. { 2, GL_REPLACE, GL_PRIMARY_COLOR, GL_PRIMARY_COLOR,
  44. 2, GL_REPLACE, GL_TEXTURE0, GL_TEXTURE0 },
  45. { 2, GL_REPLACE, GL_PRIMARY_COLOR, GL_PRIMARY_COLOR,
  46. 1, GL_SUBTRACT, GL_TEXTURE0, GL_TEXTURE1 },
  47. { 3, GL_ADD, GL_TEXTURE1, GL_TEXTURE1,
  48. 2, GL_MODULATE, GL_TEXTURE1, GL_PREVIOUS },
  49. { 3, GL_ADD, GL_TEXTURE1, GL_TEXTURE1,
  50. 4, GL_MODULATE, GL_TEXTURE0, GL_PREVIOUS },
  51. };
  52. #define NUM_TESTS (sizeof(tests) / sizeof(tests[0]))
  53. static int Width = 100 * (NUM_TESTS + 1);
  54. static int Height = 200;
  55. static const GLfloat Near = 5.0, Far = 25.0;
  56. static void Display( void )
  57. {
  58. unsigned i;
  59. glClearColor(0.2, 0.2, 0.8, 0);
  60. glClear( GL_COLOR_BUFFER_BIT );
  61. glPushMatrix();
  62. /* This is the "reference" square.
  63. */
  64. glActiveTexture( GL_TEXTURE0 );
  65. glDisable( GL_TEXTURE_2D );
  66. glActiveTexture( GL_TEXTURE1 );
  67. glDisable( GL_TEXTURE_2D );
  68. glTranslatef(-(NUM_TESTS * 1.5), 0, 0);
  69. glBegin(GL_QUADS);
  70. glColor3f( 0.5, 0.5, 0.5 );
  71. glVertex2f(-1, -1);
  72. glVertex2f( 1, -1);
  73. glVertex2f( 1, 1);
  74. glVertex2f(-1, 1);
  75. glEnd();
  76. for ( i = 0 ; i < NUM_TESTS ; i++ ) {
  77. glActiveTexture( GL_TEXTURE0 );
  78. glEnable( GL_TEXTURE_2D );
  79. glBindTexture( GL_TEXTURE_2D, tests[i][0] );
  80. glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
  81. glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB, tests[i][1] );
  82. glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB, tests[i][2] );
  83. glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB, tests[i][3] );
  84. glActiveTexture( GL_TEXTURE1 );
  85. glEnable( GL_TEXTURE_2D );
  86. glBindTexture( GL_TEXTURE_2D, tests[i][4] );
  87. glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
  88. glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB, tests[i][5] );
  89. glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB, tests[i][6] );
  90. glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB, tests[i][7] );
  91. glCallList(1);
  92. }
  93. glPopMatrix();
  94. glutSwapBuffers();
  95. }
  96. static void Reshape( int width, int height )
  97. {
  98. GLfloat ar = (float) width / (float) height;
  99. Width = width;
  100. Height = height;
  101. glViewport( 0, 0, width, height );
  102. glMatrixMode( GL_PROJECTION );
  103. glLoadIdentity();
  104. glFrustum( -ar, ar, -1.0, 1.0, Near, Far );
  105. glMatrixMode( GL_MODELVIEW );
  106. glLoadIdentity();
  107. glTranslatef( 0.0, 0.0, -15.0 );
  108. }
  109. static void Key( unsigned char key, int x, int y )
  110. {
  111. (void) x;
  112. (void) y;
  113. switch (key) {
  114. case 27:
  115. exit(0);
  116. break;
  117. }
  118. glutPostRedisplay();
  119. }
  120. static void Init( void )
  121. {
  122. const char * const ver_string = (const char * const)
  123. glGetString( GL_VERSION );
  124. float ver = strtod( ver_string, NULL );
  125. GLint tex_units;
  126. GLint temp[ 256 ];
  127. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  128. printf("GL_VERSION = %s\n", ver_string);
  129. if ( (!glutExtensionSupported("GL_ARB_multitexture")
  130. && (ver < 1.3))
  131. || (!glutExtensionSupported("GL_ARB_texture_env_combine")
  132. && !glutExtensionSupported("GL_EXT_texture_env_combine")
  133. && (ver < 1.3))
  134. || (!glutExtensionSupported("GL_ARB_texture_env_crossbar")
  135. && !glutExtensionSupported("GL_NV_texture_env_combine4")
  136. && (ver < 1.4)) ) {
  137. printf("\nSorry, this program requires GL_ARB_multitexture and either\n"
  138. "GL_ARB_texture_env_combine or GL_EXT_texture_env_combine (or OpenGL 1.3).\n"
  139. "Either GL_ARB_texture_env_crossbar or GL_NV_texture_env_combine4 (or\n"
  140. "OpenGL 1.4) are also required.\n");
  141. exit(1);
  142. }
  143. glGetIntegerv( GL_MAX_TEXTURE_UNITS, & tex_units );
  144. if ( tex_units < 2 ) {
  145. printf("\nSorry, this program requires at least 2 texture units.\n");
  146. exit(1);
  147. }
  148. printf("\nAll %lu squares should be the same color.\n", (unsigned long) NUM_TESTS + 1);
  149. (void) memset( temp, 0x00, sizeof( temp ) );
  150. glBindTexture( GL_TEXTURE_2D, 1 );
  151. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
  152. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
  153. glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0,
  154. GL_RGBA, GL_UNSIGNED_BYTE, temp );
  155. (void) memset( temp, 0x7f, sizeof( temp ) );
  156. glBindTexture( GL_TEXTURE_2D, 2 );
  157. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
  158. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
  159. glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0,
  160. GL_RGBA, GL_UNSIGNED_BYTE, temp );
  161. (void) memset( temp, 0xff, sizeof( temp ) );
  162. glBindTexture( GL_TEXTURE_2D, 3 );
  163. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
  164. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
  165. glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0,
  166. GL_RGBA, GL_UNSIGNED_BYTE, temp );
  167. (void) memset( temp, 0x3f, sizeof( temp ) );
  168. glBindTexture( GL_TEXTURE_2D, 4 );
  169. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
  170. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
  171. glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0,
  172. GL_RGBA, GL_UNSIGNED_BYTE, temp );
  173. glNewList( 1, GL_COMPILE );
  174. glTranslatef(3.0, 0, 0);
  175. glBegin(GL_QUADS);
  176. glColor3f( 0.9, 0.0, 0.0 );
  177. glMultiTexCoord2f( GL_TEXTURE0, 0.5, 0.5 );
  178. glMultiTexCoord2f( GL_TEXTURE1, 0.5, 0.5 );
  179. glVertex2f(-1, -1);
  180. glVertex2f( 1, -1);
  181. glVertex2f( 1, 1);
  182. glVertex2f(-1, 1);
  183. glEnd();
  184. glEndList();
  185. }
  186. int main( int argc, char *argv[] )
  187. {
  188. glutInit( &argc, argv );
  189. glutInitWindowPosition( 0, 0 );
  190. glutInitWindowSize( Width, Height );
  191. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
  192. glutCreateWindow( "GL_ARB_texture_env_crossbar test" );
  193. glewInit();
  194. glutReshapeFunc( Reshape );
  195. glutKeyboardFunc( Key );
  196. glutDisplayFunc( Display );
  197. Init();
  198. glutMainLoop();
  199. return 0;
  200. }