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