Merge remote branch 'origin/master' into lp-binning
[mesa.git] / progs / tests / blendsquare.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 blendsquare.c
27 *
28 * Simple test of GL_NV_blend_square 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 glTranslatef(-4.5, 0, 0);
53 glBlendFunc( GL_ONE, GL_ZERO );
54 glBegin(GL_QUADS);
55 glColor3f( 0.5 * 0.5, 0.5 * 0.5, 0.5 * 0.5 );
56 glVertex2f(-1, -1);
57 glVertex2f( 1, -1);
58 glVertex2f( 1, 1);
59 glVertex2f(-1, 1);
60 glEnd();
61
62
63 glTranslatef(3.0, 0, 0);
64 glBlendFunc( GL_ONE, GL_ZERO );
65 glBegin(GL_QUADS);
66 glColor3f( 0.5, 0.5, 0.5 );
67 glVertex2f(-1, -1);
68 glVertex2f( 1, -1);
69 glVertex2f( 1, 1);
70 glVertex2f(-1, 1);
71 glEnd();
72
73 glBlendFunc( GL_DST_COLOR, GL_ZERO );
74 glBegin(GL_QUADS);
75 glVertex2f(-1, -1);
76 glVertex2f( 1, -1);
77 glVertex2f( 1, 1);
78 glVertex2f(-1, 1);
79 glEnd();
80
81
82 glTranslatef(3.0, 0, 0);
83 glBlendFunc( GL_SRC_COLOR, GL_ZERO );
84 glBegin(GL_QUADS);
85 glVertex2f(-1, -1);
86 glVertex2f( 1, -1);
87 glVertex2f( 1, 1);
88 glVertex2f(-1, 1);
89 glEnd();
90
91
92 glTranslatef(3.0, 0, 0);
93 glBlendFunc( GL_ONE, GL_ZERO );
94 glBegin(GL_QUADS);
95 glVertex2f(-1, -1);
96 glVertex2f( 1, -1);
97 glVertex2f( 1, 1);
98 glVertex2f(-1, 1);
99 glEnd();
100
101 glBlendFunc( GL_ZERO, GL_DST_COLOR );
102 glBegin(GL_QUADS);
103 glVertex2f(-1, -1);
104 glVertex2f( 1, -1);
105 glVertex2f( 1, 1);
106 glVertex2f(-1, 1);
107 glEnd();
108
109 glPopMatrix();
110
111 glutSwapBuffers();
112 }
113
114
115 static void Reshape( int width, int height )
116 {
117 GLfloat ar = (float) width / (float) height;
118 Width = width;
119 Height = height;
120 glViewport( 0, 0, width, height );
121 glMatrixMode( GL_PROJECTION );
122 glLoadIdentity();
123 glFrustum( -ar, ar, -1.0, 1.0, Near, Far );
124 glMatrixMode( GL_MODELVIEW );
125 glLoadIdentity();
126 glTranslatef( 0.0, 0.0, -15.0 );
127 }
128
129
130 static void Key( unsigned char key, int x, int y )
131 {
132 (void) x;
133 (void) y;
134 switch (key) {
135 case 27:
136 exit(0);
137 break;
138 }
139 glutPostRedisplay();
140 }
141
142
143 static void Init( void )
144 {
145 const char * const ver_string = (const char * const)
146 glGetString( GL_VERSION );
147 const double version = strtod( ver_string, NULL );
148
149 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
150 printf("GL_VERSION = %s\n", ver_string);
151
152 if ( (version < 1.4) && !glutExtensionSupported("GL_NV_blend_square")) {
153 printf("Sorry, this program requires either OpenGL 1.4 or GL_NV_blend_square\n");
154 exit(1);
155 }
156
157 printf("\nAll 4 squares should be the same color. The two on the left are drawn\n"
158 "without NV_blend_square functionality, and the two on the right are drawn\n"
159 "with NV_blend_square functionality. If the two on the left are dark, but\n"
160 "the two on the right are not, then NV_blend_square is broken.\n");
161 glEnable( GL_BLEND );
162 glBlendEquation( GL_FUNC_ADD );
163 }
164
165
166 int main( int argc, char *argv[] )
167 {
168 glutInit( &argc, argv );
169 glutInitWindowPosition( 0, 0 );
170 glutInitWindowSize( Width, Height );
171 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
172 glutCreateWindow( "GL_NV_blend_square test" );
173 glewInit();
174 glutReshapeFunc( Reshape );
175 glutKeyboardFunc( Key );
176 glutDisplayFunc( Display );
177 Init();
178 glutMainLoop();
179 return 0;
180 }