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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 blendsquare.c
  26. *
  27. * Simple test of GL_NV_blend_square 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/glew.h>
  36. #include <GL/glut.h>
  37. static int Width = 400;
  38. static int Height = 200;
  39. static const GLfloat Near = 5.0, Far = 25.0;
  40. static void Display( void )
  41. {
  42. glClearColor(0.2, 0.2, 0.8, 0);
  43. glClear( GL_COLOR_BUFFER_BIT );
  44. glPushMatrix();
  45. glTranslatef(-4.5, 0, 0);
  46. glBlendFunc( GL_ONE, GL_ZERO );
  47. glBegin(GL_QUADS);
  48. glColor3f( 0.5 * 0.5, 0.5 * 0.5, 0.5 * 0.5 );
  49. glVertex2f(-1, -1);
  50. glVertex2f( 1, -1);
  51. glVertex2f( 1, 1);
  52. glVertex2f(-1, 1);
  53. glEnd();
  54. glTranslatef(3.0, 0, 0);
  55. glBlendFunc( GL_ONE, GL_ZERO );
  56. glBegin(GL_QUADS);
  57. glColor3f( 0.5, 0.5, 0.5 );
  58. glVertex2f(-1, -1);
  59. glVertex2f( 1, -1);
  60. glVertex2f( 1, 1);
  61. glVertex2f(-1, 1);
  62. glEnd();
  63. glBlendFunc( GL_DST_COLOR, GL_ZERO );
  64. glBegin(GL_QUADS);
  65. glVertex2f(-1, -1);
  66. glVertex2f( 1, -1);
  67. glVertex2f( 1, 1);
  68. glVertex2f(-1, 1);
  69. glEnd();
  70. glTranslatef(3.0, 0, 0);
  71. glBlendFunc( GL_SRC_COLOR, GL_ZERO );
  72. glBegin(GL_QUADS);
  73. glVertex2f(-1, -1);
  74. glVertex2f( 1, -1);
  75. glVertex2f( 1, 1);
  76. glVertex2f(-1, 1);
  77. glEnd();
  78. glTranslatef(3.0, 0, 0);
  79. glBlendFunc( GL_ONE, GL_ZERO );
  80. glBegin(GL_QUADS);
  81. glVertex2f(-1, -1);
  82. glVertex2f( 1, -1);
  83. glVertex2f( 1, 1);
  84. glVertex2f(-1, 1);
  85. glEnd();
  86. glBlendFunc( GL_ZERO, GL_DST_COLOR );
  87. glBegin(GL_QUADS);
  88. glVertex2f(-1, -1);
  89. glVertex2f( 1, -1);
  90. glVertex2f( 1, 1);
  91. glVertex2f(-1, 1);
  92. glEnd();
  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. const double version = strtod( ver_string, NULL );
  125. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  126. printf("GL_VERSION = %s\n", ver_string);
  127. if ( (version < 1.4) && !glutExtensionSupported("GL_NV_blend_square")) {
  128. printf("Sorry, this program requires either OpenGL 1.4 or GL_NV_blend_square\n");
  129. exit(1);
  130. }
  131. printf("\nAll 4 squares should be the same color. The two on the left are drawn\n"
  132. "without NV_blend_square functionality, and the two on the right are drawn\n"
  133. "with NV_blend_square functionality. If the two on the left are dark, but\n"
  134. "the two on the right are not, then NV_blend_square is broken.\n");
  135. glEnable( GL_BLEND );
  136. glBlendEquation( GL_FUNC_ADD );
  137. }
  138. int main( int argc, char *argv[] )
  139. {
  140. glutInit( &argc, argv );
  141. glutInitWindowPosition( 0, 0 );
  142. glutInitWindowSize( Width, Height );
  143. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
  144. glutCreateWindow( "GL_NV_blend_square test" );
  145. glewInit();
  146. glutReshapeFunc( Reshape );
  147. glutKeyboardFunc( Key );
  148. glutDisplayFunc( Display );
  149. Init();
  150. glutMainLoop();
  151. return 0;
  152. }