Convert libGL and DRI drivers to require libdrm.
[mesa-demos.git] / src / tests / blendminmax.c
blob2aab1a39d290e5e562e59b42bfd984cb882ac83c
1 /*
2 * (C) Copyright IBM Corporation 2004
3 * All Rights Reserved.
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:
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.
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.
25 /**
26 * \file blendminmax.c
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.
32 * \author Ian Romanick <idr@us.ibm.com>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <GL/glut.h>
39 static int Width = 400;
40 static int Height = 200;
41 static const GLfloat Near = 5.0, Far = 25.0;
44 static void Display( void )
46 glClearColor(0.2, 0.2, 0.8, 0);
47 glClear( GL_COLOR_BUFFER_BIT );
49 glPushMatrix();
51 /* This is the "reference" square.
54 glTranslatef(-4.5, 0, 0);
55 glBlendEquation( GL_FUNC_ADD );
56 glBlendFunc( GL_ONE, GL_ZERO );
57 glBegin(GL_QUADS);
58 glColor3f( 0.5, 0.5, 0.5 );
59 glVertex2f(-1, -1);
60 glVertex2f( 1, -1);
61 glVertex2f( 1, 1);
62 glVertex2f(-1, 1);
63 glEnd();
66 /* GL_MIN and GL_MAX are supposed to ignore the blend function setting.
67 * To test that, we set the blend function to GL_ZERO for both color and
68 * alpha each time GL_MIN or GL_MAX is used.
70 * Apple ships an extension called GL_ATI_blend_weighted_minmax (supported
71 * on Mac OS X 10.2 and later). I believe the difference with that
72 * extension is that it uses the blend function. However, I have no idea
73 * what the enums are for it. The extension is listed at Apple's developer
74 * site, but there is no documentation.
76 * http://developer.apple.com/opengl/extensions.html
79 glTranslatef(3.0, 0, 0);
80 glBlendEquation( GL_FUNC_ADD );
81 glBlendFunc( GL_ONE, GL_ZERO );
82 glBegin(GL_QUADS);
83 glColor3f( 0.5, 0.5, 0.5 );
84 glVertex2f(-1, -1);
85 glVertex2f( 1, -1);
86 glVertex2f( 1, 1);
87 glVertex2f(-1, 1);
88 glEnd();
90 glBlendEquation( GL_MAX );
91 glBlendFunc( GL_ZERO, GL_ZERO );
92 glBegin(GL_QUADS);
93 glColor3f( 0.2, 0.2, 0.2 );
94 glVertex2f(-1, -1);
95 glVertex2f( 1, -1);
96 glVertex2f( 1, 1);
97 glVertex2f(-1, 1);
98 glEnd();
101 glTranslatef(3.0, 0, 0);
102 glBlendEquation( GL_FUNC_ADD );
103 glBlendFunc( GL_ONE, GL_ZERO );
104 glBegin(GL_QUADS);
105 glColor3f( 0.5, 0.5, 0.5 );
106 glVertex2f(-1, -1);
107 glVertex2f( 1, -1);
108 glVertex2f( 1, 1);
109 glVertex2f(-1, 1);
110 glEnd();
112 glBlendEquation( GL_MIN );
113 glBlendFunc( GL_ZERO, GL_ZERO );
114 glBegin(GL_QUADS);
115 glColor3f( 0.8, 0.8, 0.8 );
116 glVertex2f(-1, -1);
117 glVertex2f( 1, -1);
118 glVertex2f( 1, 1);
119 glVertex2f(-1, 1);
120 glEnd();
123 glTranslatef(3.0, 0, 0);
124 glBlendEquation( GL_FUNC_ADD );
125 glBlendFunc( GL_ONE, GL_ZERO );
126 glBegin(GL_QUADS);
127 glColor3f( 0.8, 0.8, 0.8 );
128 glVertex2f(-1, -1);
129 glVertex2f( 1, -1);
130 glVertex2f( 1, 1);
131 glVertex2f(-1, 1);
132 glEnd();
134 glBlendEquation( GL_MIN );
135 glBlendFunc( GL_ZERO, GL_ZERO );
136 glBegin(GL_QUADS);
137 glColor3f( 0.5, 0.5, 0.5 );
138 glVertex2f(-1, -1);
139 glVertex2f( 1, -1);
140 glVertex2f( 1, 1);
141 glVertex2f(-1, 1);
142 glEnd();
144 glPopMatrix();
146 glutSwapBuffers();
150 static void Reshape( int width, int height )
152 GLfloat ar = (float) width / (float) height;
153 Width = width;
154 Height = height;
155 glViewport( 0, 0, width, height );
156 glMatrixMode( GL_PROJECTION );
157 glLoadIdentity();
158 glFrustum( -ar, ar, -1.0, 1.0, Near, Far );
159 glMatrixMode( GL_MODELVIEW );
160 glLoadIdentity();
161 glTranslatef( 0.0, 0.0, -15.0 );
165 static void Key( unsigned char key, int x, int y )
167 (void) x;
168 (void) y;
169 switch (key) {
170 case 27:
171 exit(0);
172 break;
174 glutPostRedisplay();
178 static void Init( void )
180 const char * const ver_string = (const char * const)
181 glGetString( GL_VERSION );
183 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
184 printf("GL_VERSION = %s\n", ver_string);
186 if ( !glutExtensionSupported("GL_ARB_imaging") && !glutExtensionSupported("GL_EXT_blend_minmax")) {
187 printf("Sorry, this program requires either GL_ARB_imaging or GL_EXT_blend_minmax.\n");
188 exit(1);
191 printf("\nAll 4 squares should be the same color.\n");
192 glEnable( GL_BLEND );
196 int main( int argc, char *argv[] )
198 glutInit( &argc, argv );
199 glutInitWindowPosition( 0, 0 );
200 glutInitWindowSize( Width, Height );
201 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
202 glutCreateWindow( "GL_EXT_blend_minmax test" );
203 glutReshapeFunc( Reshape );
204 glutKeyboardFunc( Key );
205 glutDisplayFunc( Display );
206 Init();
207 glutMainLoop();
208 return 0;