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.

blendminmax.c 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * (C) Copyright IBM Corporation 2004
  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 blendminmax.c
  26. *
  27. * Simple test of GL_EXT_blend_minmax functionality. Four squares are drawn
  28. * with different blending modes, but all should be rendered with the same
  29. * final color.
  30. *
  31. * \author Ian Romanick <idr@us.ibm.com>
  32. */
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include <GL/glut.h>
  36. static int Width = 400;
  37. static int Height = 200;
  38. static const GLfloat Near = 5.0, Far = 25.0;
  39. static void Display( void )
  40. {
  41. glClearColor(0.2, 0.2, 0.8, 0);
  42. glClear( GL_COLOR_BUFFER_BIT );
  43. glPushMatrix();
  44. /* This is the "reference" square.
  45. */
  46. glTranslatef(-4.5, 0, 0);
  47. glBlendEquation( GL_FUNC_ADD );
  48. glBlendFunc( GL_ONE, GL_ZERO );
  49. glBegin(GL_QUADS);
  50. glColor3f( 0.5, 0.5, 0.5 );
  51. glVertex2f(-1, -1);
  52. glVertex2f( 1, -1);
  53. glVertex2f( 1, 1);
  54. glVertex2f(-1, 1);
  55. glEnd();
  56. /* GL_MIN and GL_MAX are supposed to ignore the blend function setting.
  57. * To test that, we set the blend function to GL_ZERO for both color and
  58. * alpha each time GL_MIN or GL_MAX is used.
  59. *
  60. * Apple ships an extension called GL_ATI_blend_weighted_minmax (supported
  61. * on Mac OS X 10.2 and later). I believe the difference with that
  62. * extension is that it uses the blend function. However, I have no idea
  63. * what the enums are for it. The extension is listed at Apple's developer
  64. * site, but there is no documentation.
  65. *
  66. * http://developer.apple.com/opengl/extensions.html
  67. */
  68. glTranslatef(3.0, 0, 0);
  69. glBlendEquation( GL_FUNC_ADD );
  70. glBlendFunc( GL_ONE, GL_ZERO );
  71. glBegin(GL_QUADS);
  72. glColor3f( 0.5, 0.5, 0.5 );
  73. glVertex2f(-1, -1);
  74. glVertex2f( 1, -1);
  75. glVertex2f( 1, 1);
  76. glVertex2f(-1, 1);
  77. glEnd();
  78. glBlendEquation( GL_MAX );
  79. glBlendFunc( GL_ZERO, GL_ZERO );
  80. glBegin(GL_QUADS);
  81. glColor3f( 0.2, 0.2, 0.2 );
  82. glVertex2f(-1, -1);
  83. glVertex2f( 1, -1);
  84. glVertex2f( 1, 1);
  85. glVertex2f(-1, 1);
  86. glEnd();
  87. glTranslatef(3.0, 0, 0);
  88. glBlendEquation( GL_FUNC_ADD );
  89. glBlendFunc( GL_ONE, GL_ZERO );
  90. glBegin(GL_QUADS);
  91. glColor3f( 0.5, 0.5, 0.5 );
  92. glVertex2f(-1, -1);
  93. glVertex2f( 1, -1);
  94. glVertex2f( 1, 1);
  95. glVertex2f(-1, 1);
  96. glEnd();
  97. glBlendEquation( GL_MIN );
  98. glBlendFunc( GL_ZERO, GL_ZERO );
  99. glBegin(GL_QUADS);
  100. glColor3f( 0.8, 0.8, 0.8 );
  101. glVertex2f(-1, -1);
  102. glVertex2f( 1, -1);
  103. glVertex2f( 1, 1);
  104. glVertex2f(-1, 1);
  105. glEnd();
  106. glTranslatef(3.0, 0, 0);
  107. glBlendEquation( GL_FUNC_ADD );
  108. glBlendFunc( GL_ONE, GL_ZERO );
  109. glBegin(GL_QUADS);
  110. glColor3f( 0.8, 0.8, 0.8 );
  111. glVertex2f(-1, -1);
  112. glVertex2f( 1, -1);
  113. glVertex2f( 1, 1);
  114. glVertex2f(-1, 1);
  115. glEnd();
  116. glBlendEquation( GL_MIN );
  117. glBlendFunc( GL_ZERO, GL_ZERO );
  118. glBegin(GL_QUADS);
  119. glColor3f( 0.5, 0.5, 0.5 );
  120. glVertex2f(-1, -1);
  121. glVertex2f( 1, -1);
  122. glVertex2f( 1, 1);
  123. glVertex2f(-1, 1);
  124. glEnd();
  125. glPopMatrix();
  126. glutSwapBuffers();
  127. }
  128. static void Reshape( int width, int height )
  129. {
  130. GLfloat ar = (float) width / (float) height;
  131. Width = width;
  132. Height = height;
  133. glViewport( 0, 0, width, height );
  134. glMatrixMode( GL_PROJECTION );
  135. glLoadIdentity();
  136. glFrustum( -ar, ar, -1.0, 1.0, Near, Far );
  137. glMatrixMode( GL_MODELVIEW );
  138. glLoadIdentity();
  139. glTranslatef( 0.0, 0.0, -15.0 );
  140. }
  141. static void Key( unsigned char key, int x, int y )
  142. {
  143. (void) x;
  144. (void) y;
  145. switch (key) {
  146. case 27:
  147. exit(0);
  148. break;
  149. }
  150. glutPostRedisplay();
  151. }
  152. static void Init( void )
  153. {
  154. const char * const ver_string = (const char * const)
  155. glGetString( GL_VERSION );
  156. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  157. printf("GL_VERSION = %s\n", ver_string);
  158. if ( !glutExtensionSupported("GL_ARB_imaging") && !glutExtensionSupported("GL_EXT_blend_minmax")) {
  159. printf("Sorry, this program requires either GL_ARB_imaging or GL_EXT_blend_minmax.\n");
  160. exit(1);
  161. }
  162. printf("\nAll 4 squares should be the same color.\n");
  163. glEnable( GL_BLEND );
  164. }
  165. int main( int argc, char *argv[] )
  166. {
  167. glutInit( &argc, argv );
  168. glutInitWindowPosition( 0, 0 );
  169. glutInitWindowSize( Width, Height );
  170. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
  171. glutCreateWindow( "GL_EXT_blend_minmax test" );
  172. glutReshapeFunc( Reshape );
  173. glutKeyboardFunc( Key );
  174. glutDisplayFunc( Display );
  175. Init();
  176. glutMainLoop();
  177. return 0;
  178. }