2 * Copyright (c) 2009 VMware, Inc.
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.
26 * Simple test for testing ATI_envmap_bumpmap support.
34 #include "glut_wrap.h"
38 static const char *TexFile
= DEMOS_DATA_DIR
"arch.rgb";
40 static const GLfloat Near
= 5.0, Far
= 25.0;
42 static void Display( void )
44 /* together with the construction of dudv map, do fixed translation
45 in y direction (up), some cosine deformation in x and more
46 deformation in y dir */
47 GLfloat bumpMatrix
[4] = {0.1, 0.0, 0.2, 0.1};
50 glClearColor(0.2, 0.2, 0.8, 0);
51 glClear( GL_COLOR_BUFFER_BIT
);
55 /* this is the base map */
56 glActiveTexture( GL_TEXTURE0
);
57 glEnable( GL_TEXTURE_2D
);
58 glBindTexture( GL_TEXTURE_2D
, 1 );
59 glTexEnvf( GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_COMBINE
);
60 glTexEnvf( GL_TEXTURE_ENV
, GL_COMBINE_RGB
, GL_REPLACE
);
61 glTexEnvf( GL_TEXTURE_ENV
, GL_SOURCE0_RGB
, GL_TEXTURE
);
64 glActiveTexture( GL_TEXTURE1
);
65 glEnable( GL_TEXTURE_2D
);
66 glBindTexture( GL_TEXTURE_2D
, 2 );
67 glTexEnvf( GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_COMBINE
);
68 glTexEnvf( GL_TEXTURE_ENV
, GL_COMBINE_RGB
, GL_BUMP_ENVMAP_ATI
);
69 glTexEnvf( GL_TEXTURE_ENV
, GL_BUMP_TARGET_ATI
, GL_TEXTURE0
);
71 glTexBumpParameterfvATI(GL_BUMP_ROT_MATRIX_ATI
, bumpMatrix
);
81 static void Reshape( int width
, int height
)
83 GLfloat ar
= (float) width
/ (float) height
;
84 glViewport( 0, 0, width
, height
);
85 glMatrixMode( GL_PROJECTION
);
87 glFrustum( -ar
, ar
, -1.0, 1.0, Near
, Far
);
88 glMatrixMode( GL_MODELVIEW
);
90 glTranslatef( 0.0, 0.0, -6.0 );
94 static void Key( unsigned char key
, int x
, int y
)
107 static void Init( void )
109 const char * const ver_string
= (const char *)
110 glGetString( GL_VERSION
);
111 GLfloat temp
[16][16][2];
112 GLubyte
*image
= NULL
;
113 GLint imgWidth
, imgHeight
;
116 GLint param
, paramArray
[16];
119 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
120 printf("GL_VERSION = %s\n", ver_string
);
122 if ( !glutExtensionSupported("GL_ATI_envmap_bumpmap")) {
123 printf("\nSorry, this program requires GL_ATI_envmap_bumpmap\n");
127 glGetTexBumpParameterivATI(GL_BUMP_ROT_MATRIX_SIZE_ATI
, ¶m
);
128 printf("BUMP_ROT_MATRIX_SIZE_ATI = %d\n", param
);
129 glGetTexBumpParameterivATI(GL_BUMP_NUM_TEX_UNITS_ATI
, ¶m
);
130 printf("BUMP_NUM_TEX_UNITS_ATI = %d\n", param
);
131 glGetTexBumpParameterfvATI(GL_BUMP_ROT_MATRIX_ATI
, paramMat
);
132 printf("initial rot matrix %f %f %f %f\n", paramMat
[0], paramMat
[1], paramMat
[2], paramMat
[3]);
133 glGetTexBumpParameterivATI(GL_BUMP_TEX_UNITS_ATI
, paramArray
);
134 printf("units supporting bump mapping: ");
135 for (i
= 0; i
< param
; i
++)
136 printf("%d ", paramArray
[i
] - GL_TEXTURE0
);
139 image
= LoadRGBImage(TexFile
, &imgWidth
, &imgHeight
, &imgFormat
);
141 printf("Couldn't read %s\n", TexFile
);
145 glBindTexture( GL_TEXTURE_2D
, 1 );
146 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
147 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
148 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
149 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
150 glTexImage2D( GL_TEXTURE_2D
, 0, imgFormat
, imgWidth
, imgHeight
, 0,
151 imgFormat
, GL_UNSIGNED_BYTE
, image
);
153 for (j
= 0; j
< 16; j
++) {
154 for (i
= 0; i
< 16; i
++) {
155 temp
[j
][i
][0] = cos((float)(i
) * 3.1415 / 16.0);
156 temp
[j
][i
][1] = -0.5;
159 glBindTexture( GL_TEXTURE_2D
, 2 );
160 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
161 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
162 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
163 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
164 glTexImage2D( GL_TEXTURE_2D
, 0, GL_DU8DV8_ATI
, 16, 16, 0,
165 GL_DUDV_ATI
, GL_FLOAT
, temp
);
168 glNewList( 1, GL_COMPILE
);
170 glColor3f( 0.9, 0.0, 0.0 );
171 glMultiTexCoord2f( GL_TEXTURE0
, 0.0, 0.0 );
172 glMultiTexCoord2f( GL_TEXTURE1
, 0.0, 0.0 );
174 glMultiTexCoord2f( GL_TEXTURE0
, 1.0, 0.0 );
175 glMultiTexCoord2f( GL_TEXTURE1
, 1.0, 0.0 );
177 glMultiTexCoord2f( GL_TEXTURE0
, 1.0, 1.0 );
178 glMultiTexCoord2f( GL_TEXTURE1
, 1.0, 1.0 );
180 glMultiTexCoord2f( GL_TEXTURE0
, 0.0, 1.0 );
181 glMultiTexCoord2f( GL_TEXTURE1
, 0.0, 1.0 );
188 int main( int argc
, char *argv
[] )
190 glutInit( &argc
, argv
);
191 glutInitWindowPosition( 0, 0 );
192 glutInitWindowSize( 400, 400 );
193 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
);
194 glutCreateWindow( "GL_ATI_envmap_bumpmap test" );
196 glutReshapeFunc( Reshape
);
197 glutKeyboardFunc( Key
);
198 glutDisplayFunc( Display
);