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>
40
static const GLint tests[][8] = {
41
{ 1, GL_REPLACE, GL_PRIMARY_COLOR, GL_PRIMARY_COLOR,
42
2, GL_REPLACE, GL_TEXTURE, GL_PRIMARY_COLOR },
43
{ 3, GL_REPLACE, GL_PRIMARY_COLOR, GL_PRIMARY_COLOR,
44
2, GL_SUBTRACT, GL_TEXTURE0, GL_TEXTURE1 },
45
{ 2, GL_REPLACE, GL_PRIMARY_COLOR, GL_PRIMARY_COLOR,
46
2, GL_REPLACE, GL_TEXTURE0, GL_TEXTURE0 },
47
{ 2, GL_REPLACE, GL_PRIMARY_COLOR, GL_PRIMARY_COLOR,
48
1, GL_SUBTRACT, GL_TEXTURE0, GL_TEXTURE1 },
49
{ 3, GL_ADD, GL_TEXTURE1, GL_TEXTURE1,
50
2, GL_MODULATE, GL_TEXTURE1, GL_PREVIOUS },
51
{ 3, GL_ADD, GL_TEXTURE1, GL_TEXTURE1,
52
4, GL_MODULATE, GL_TEXTURE0, GL_PREVIOUS },
55
#define NUM_TESTS (sizeof(tests) / sizeof(tests[0]))
57
static int Width = 100 * (NUM_TESTS + 1);
58
static int Height = 200;
59
static const GLfloat Near = 5.0, Far = 25.0;
62
static void Display( void )
67
glClearColor(0.2, 0.2, 0.8, 0);
68
glClear( GL_COLOR_BUFFER_BIT );
72
/* This is the "reference" square.
75
glActiveTexture( GL_TEXTURE0 );
76
glDisable( GL_TEXTURE_2D );
77
glActiveTexture( GL_TEXTURE1 );
78
glDisable( GL_TEXTURE_2D );
80
glTranslatef(-(NUM_TESTS * 1.5), 0, 0);
82
glColor3f( 0.5, 0.5, 0.5 );
89
for ( i = 0 ; i < NUM_TESTS ; i++ ) {
90
glActiveTexture( GL_TEXTURE0 );
91
glEnable( GL_TEXTURE_2D );
92
glBindTexture( GL_TEXTURE_2D, tests[i][0] );
93
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
94
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB, tests[i][1] );
95
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB, tests[i][2] );
96
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB, tests[i][3] );
98
glActiveTexture( GL_TEXTURE1 );
99
glEnable( GL_TEXTURE_2D );
100
glBindTexture( GL_TEXTURE_2D, tests[i][4] );
101
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
102
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB, tests[i][5] );
103
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB, tests[i][6] );
104
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB, tests[i][7] );
115
static void Reshape( int width, int height )
117
GLfloat ar = (float) width / (float) height;
120
glViewport( 0, 0, width, height );
121
glMatrixMode( GL_PROJECTION );
123
glFrustum( -ar, ar, -1.0, 1.0, Near, Far );
124
glMatrixMode( GL_MODELVIEW );
126
glTranslatef( 0.0, 0.0, -15.0 );
130
static void Key( unsigned char key, int x, int y )
143
static void Init( void )
145
const char * const ver_string = (const char * const)
146
glGetString( GL_VERSION );
147
float ver = strtof( ver_string, NULL );
152
printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
153
printf("GL_VERSION = %s\n", ver_string);
155
if ( (!glutExtensionSupported("GL_ARB_multitexture")
157
|| (!glutExtensionSupported("GL_ARB_texture_env_combine")
158
&& !glutExtensionSupported("GL_EXT_texture_env_combine")
160
|| (!glutExtensionSupported("GL_ARB_texture_env_crossbar")
161
&& !glutExtensionSupported("GL_NV_texture_env_combine4")
163
printf("\nSorry, this program requires GL_ARB_multitexture and either\n"
164
"GL_ARB_texture_env_combine or GL_EXT_texture_env_combine (or OpenGL 1.3).\n"
165
"Either GL_ARB_texture_env_crossbar or GL_NV_texture_env_combine4 (or\n"
166
"OpenGL 1.4) are also required.\n");
170
glGetIntegerv( GL_MAX_TEXTURE_UNITS, & tex_units );
171
if ( tex_units < 2 ) {
172
printf("\nSorry, this program requires at least 2 texture units.\n");
176
printf("\nAll %u squares should be the same color.\n", NUM_TESTS + 1);
178
(void) memset( temp, 0x00, sizeof( temp ) );
179
glBindTexture( GL_TEXTURE_2D, 1 );
180
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
181
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
182
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0,
183
GL_RGBA, GL_UNSIGNED_BYTE, temp );
185
(void) memset( temp, 0x7f, sizeof( temp ) );
186
glBindTexture( GL_TEXTURE_2D, 2 );
187
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
188
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
189
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0,
190
GL_RGBA, GL_UNSIGNED_BYTE, temp );
192
(void) memset( temp, 0xff, sizeof( temp ) );
193
glBindTexture( GL_TEXTURE_2D, 3 );
194
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
195
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
196
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0,
197
GL_RGBA, GL_UNSIGNED_BYTE, temp );
199
(void) memset( temp, 0x3f, sizeof( temp ) );
200
glBindTexture( GL_TEXTURE_2D, 4 );
201
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
202
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
203
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0,
204
GL_RGBA, GL_UNSIGNED_BYTE, temp );
207
glNewList( 1, GL_COMPILE );
208
glTranslatef(3.0, 0, 0);
210
glColor3f( 0.9, 0.0, 0.0 );
211
glMultiTexCoord2f( GL_TEXTURE0, 0.5, 0.5 );
212
glMultiTexCoord2f( GL_TEXTURE1, 0.5, 0.5 );
222
int main( int argc, char *argv[] )
224
glutInit( &argc, argv );
225
glutInitWindowPosition( 0, 0 );
226
glutInitWindowSize( Width, Height );
227
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
228
glutCreateWindow( "GL_ARB_texture_env_crossbar test" );
229
glutReshapeFunc( Reshape );
230
glutKeyboardFunc( Key );
231
glutDisplayFunc( Display );