2 * (C) Copyright IBM Corporation 2005
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
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.
28 * Simple test of GL_ARB_texture_env_crossbar functionality. Several squares
29 * are drawn with different texture combine modes, but all should be rendered
30 * with the same final color.
32 * \author Ian Romanick <idr@us.ibm.com>
41 static const GLint tests
[][8] = {
42 { 1, GL_REPLACE
, GL_PRIMARY_COLOR
, GL_PRIMARY_COLOR
,
43 2, GL_REPLACE
, GL_TEXTURE
, GL_PRIMARY_COLOR
},
44 { 3, GL_REPLACE
, GL_PRIMARY_COLOR
, GL_PRIMARY_COLOR
,
45 2, GL_SUBTRACT
, GL_TEXTURE0
, GL_TEXTURE1
},
46 { 2, GL_REPLACE
, GL_PRIMARY_COLOR
, GL_PRIMARY_COLOR
,
47 2, GL_REPLACE
, GL_TEXTURE0
, GL_TEXTURE0
},
48 { 2, GL_REPLACE
, GL_PRIMARY_COLOR
, GL_PRIMARY_COLOR
,
49 1, GL_SUBTRACT
, GL_TEXTURE0
, GL_TEXTURE1
},
50 { 3, GL_ADD
, GL_TEXTURE1
, GL_TEXTURE1
,
51 2, GL_MODULATE
, GL_TEXTURE1
, GL_PREVIOUS
},
52 { 3, GL_ADD
, GL_TEXTURE1
, GL_TEXTURE1
,
53 4, GL_MODULATE
, GL_TEXTURE0
, GL_PREVIOUS
},
56 #define NUM_TESTS (sizeof(tests) / sizeof(tests[0]))
58 static int Width
= 100 * (NUM_TESTS
+ 1);
59 static int Height
= 200;
60 static const GLfloat Near
= 5.0, Far
= 25.0;
63 static void Display( void )
68 glClearColor(0.2, 0.2, 0.8, 0);
69 glClear( GL_COLOR_BUFFER_BIT
);
73 /* This is the "reference" square.
76 glActiveTexture( GL_TEXTURE0
);
77 glDisable( GL_TEXTURE_2D
);
78 glActiveTexture( GL_TEXTURE1
);
79 glDisable( GL_TEXTURE_2D
);
81 glTranslatef(-(NUM_TESTS
* 1.5), 0, 0);
83 glColor3f( 0.5, 0.5, 0.5 );
90 for ( i
= 0 ; i
< NUM_TESTS
; i
++ ) {
91 glActiveTexture( GL_TEXTURE0
);
92 glEnable( GL_TEXTURE_2D
);
93 glBindTexture( GL_TEXTURE_2D
, tests
[i
][0] );
94 glTexEnvi( GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_COMBINE
);
95 glTexEnvi( GL_TEXTURE_ENV
, GL_COMBINE_RGB
, tests
[i
][1] );
96 glTexEnvi( GL_TEXTURE_ENV
, GL_SOURCE0_RGB
, tests
[i
][2] );
97 glTexEnvi( GL_TEXTURE_ENV
, GL_SOURCE1_RGB
, tests
[i
][3] );
99 glActiveTexture( GL_TEXTURE1
);
100 glEnable( GL_TEXTURE_2D
);
101 glBindTexture( GL_TEXTURE_2D
, tests
[i
][4] );
102 glTexEnvi( GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_COMBINE
);
103 glTexEnvi( GL_TEXTURE_ENV
, GL_COMBINE_RGB
, tests
[i
][5] );
104 glTexEnvi( GL_TEXTURE_ENV
, GL_SOURCE0_RGB
, tests
[i
][6] );
105 glTexEnvi( GL_TEXTURE_ENV
, GL_SOURCE1_RGB
, tests
[i
][7] );
116 static void Reshape( int width
, int height
)
118 GLfloat ar
= (float) width
/ (float) height
;
121 glViewport( 0, 0, width
, height
);
122 glMatrixMode( GL_PROJECTION
);
124 glFrustum( -ar
, ar
, -1.0, 1.0, Near
, Far
);
125 glMatrixMode( GL_MODELVIEW
);
127 glTranslatef( 0.0, 0.0, -15.0 );
131 static void Key( unsigned char key
, int x
, int y
)
144 static void Init( void )
146 const char * const ver_string
= (const char * const)
147 glGetString( GL_VERSION
);
148 float ver
= strtod( ver_string
, NULL
);
153 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
154 printf("GL_VERSION = %s\n", ver_string
);
156 if ( (!glutExtensionSupported("GL_ARB_multitexture")
158 || (!glutExtensionSupported("GL_ARB_texture_env_combine")
159 && !glutExtensionSupported("GL_EXT_texture_env_combine")
161 || (!glutExtensionSupported("GL_ARB_texture_env_crossbar")
162 && !glutExtensionSupported("GL_NV_texture_env_combine4")
164 printf("\nSorry, this program requires GL_ARB_multitexture and either\n"
165 "GL_ARB_texture_env_combine or GL_EXT_texture_env_combine (or OpenGL 1.3).\n"
166 "Either GL_ARB_texture_env_crossbar or GL_NV_texture_env_combine4 (or\n"
167 "OpenGL 1.4) are also required.\n");
171 glGetIntegerv( GL_MAX_TEXTURE_UNITS
, & tex_units
);
172 if ( tex_units
< 2 ) {
173 printf("\nSorry, this program requires at least 2 texture units.\n");
177 printf("\nAll %lu squares should be the same color.\n", (unsigned long) NUM_TESTS
+ 1);
179 (void) memset( temp
, 0x00, sizeof( temp
) );
180 glBindTexture( GL_TEXTURE_2D
, 1 );
181 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
182 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
183 glTexImage2D( GL_TEXTURE_2D
, 0, GL_RGBA
, 8, 8, 0,
184 GL_RGBA
, GL_UNSIGNED_BYTE
, temp
);
186 (void) memset( temp
, 0x7f, sizeof( temp
) );
187 glBindTexture( GL_TEXTURE_2D
, 2 );
188 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
189 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
190 glTexImage2D( GL_TEXTURE_2D
, 0, GL_RGBA
, 8, 8, 0,
191 GL_RGBA
, GL_UNSIGNED_BYTE
, temp
);
193 (void) memset( temp
, 0xff, sizeof( temp
) );
194 glBindTexture( GL_TEXTURE_2D
, 3 );
195 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
196 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
197 glTexImage2D( GL_TEXTURE_2D
, 0, GL_RGBA
, 8, 8, 0,
198 GL_RGBA
, GL_UNSIGNED_BYTE
, temp
);
200 (void) memset( temp
, 0x3f, sizeof( temp
) );
201 glBindTexture( GL_TEXTURE_2D
, 4 );
202 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
203 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
204 glTexImage2D( GL_TEXTURE_2D
, 0, GL_RGBA
, 8, 8, 0,
205 GL_RGBA
, GL_UNSIGNED_BYTE
, temp
);
208 glNewList( 1, GL_COMPILE
);
209 glTranslatef(3.0, 0, 0);
211 glColor3f( 0.9, 0.0, 0.0 );
212 glMultiTexCoord2f( GL_TEXTURE0
, 0.5, 0.5 );
213 glMultiTexCoord2f( GL_TEXTURE1
, 0.5, 0.5 );
223 int main( int argc
, char *argv
[] )
225 glutInit( &argc
, argv
);
226 glutInitWindowPosition( 0, 0 );
227 glutInitWindowSize( Width
, Height
);
228 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
);
229 glutCreateWindow( "GL_ARB_texture_env_crossbar test" );
231 glutReshapeFunc( Reshape
);
232 glutKeyboardFunc( Key
);
233 glutDisplayFunc( Display
);