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.
37 static PFNGLGETTEXBUMPPARAMETERFVATIPROC glGetTexBumpParameterfvATI_func
= NULL
;
38 static PFNGLGETTEXBUMPPARAMETERIVATIPROC glGetTexBumpParameterivATI_func
= NULL
;
39 static PFNGLTEXBUMPPARAMETERFVATIPROC glTexBumpParameterfvATI_func
= NULL
;
41 static const char *TexFile
= "../images/arch.rgb";
43 static const GLfloat Near
= 5.0, Far
= 25.0;
45 static void Display( void )
47 /* together with the construction of dudv map, do fixed translation
48 in y direction (up), some cosine deformation in x and more
49 deformation in y dir */
50 GLfloat bumpMatrix
[4] = {0.1, 0.0, 0.2, 0.1};
53 glClearColor(0.2, 0.2, 0.8, 0);
54 glClear( GL_COLOR_BUFFER_BIT
);
58 /* this is the base map */
59 glActiveTexture( GL_TEXTURE0
);
60 glEnable( GL_TEXTURE_2D
);
61 glBindTexture( GL_TEXTURE_2D
, 1 );
62 glTexEnvf( GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_COMBINE
);
63 glTexEnvf( GL_TEXTURE_ENV
, GL_COMBINE_RGB
, GL_REPLACE
);
64 glTexEnvf( GL_TEXTURE_ENV
, GL_SOURCE0_RGB
, GL_TEXTURE
);
67 glActiveTexture( GL_TEXTURE1
);
68 glEnable( GL_TEXTURE_2D
);
69 glBindTexture( GL_TEXTURE_2D
, 2 );
70 glTexEnvf( GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_COMBINE
);
71 glTexEnvf( GL_TEXTURE_ENV
, GL_COMBINE_RGB
, GL_BUMP_ENVMAP_ATI
);
72 glTexEnvf( GL_TEXTURE_ENV
, GL_BUMP_TARGET_ATI
, GL_TEXTURE0
);
74 glTexBumpParameterfvATI_func(GL_BUMP_ROT_MATRIX_ATI
, bumpMatrix
);
84 static void Reshape( int width
, int height
)
86 GLfloat ar
= (float) width
/ (float) height
;
87 glViewport( 0, 0, width
, height
);
88 glMatrixMode( GL_PROJECTION
);
90 glFrustum( -ar
, ar
, -1.0, 1.0, Near
, Far
);
91 glMatrixMode( GL_MODELVIEW
);
93 glTranslatef( 0.0, 0.0, -6.0 );
97 static void Key( unsigned char key
, int x
, int y
)
110 static void Init( void )
112 const char * const ver_string
= (const char * const)
113 glGetString( GL_VERSION
);
114 GLfloat temp
[16][16][2];
115 GLubyte
*image
= NULL
;
116 GLint imgWidth
, imgHeight
;
119 GLint param
, paramArray
[16];
122 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
123 printf("GL_VERSION = %s\n", ver_string
);
125 if ( !glutExtensionSupported("GL_ATI_envmap_bumpmap")) {
126 printf("\nSorry, this program requires GL_ATI_envmap_bumpmap\n");
130 glGetTexBumpParameterfvATI_func
= glutGetProcAddress("glGetTexBumpParameterfvATI");
131 glGetTexBumpParameterivATI_func
= glutGetProcAddress("glGetTexBumpParameterivATI");
132 glTexBumpParameterfvATI_func
= glutGetProcAddress("glTexBumpParameterfvATI");
134 glGetTexBumpParameterivATI_func(GL_BUMP_ROT_MATRIX_SIZE_ATI
, ¶m
);
135 printf("BUMP_ROT_MATRIX_SIZE_ATI = %d\n", param
);
136 glGetTexBumpParameterivATI_func(GL_BUMP_NUM_TEX_UNITS_ATI
, ¶m
);
137 printf("BUMP_NUM_TEX_UNITS_ATI = %d\n", param
);
138 glGetTexBumpParameterfvATI_func(GL_BUMP_ROT_MATRIX_ATI
, paramMat
);
139 printf("initial rot matrix %f %f %f %f\n", paramMat
[0], paramMat
[1], paramMat
[2], paramMat
[3]);
140 glGetTexBumpParameterivATI_func(GL_BUMP_TEX_UNITS_ATI
, paramArray
);
141 printf("units supporting bump mapping: ");
142 for (i
= 0; i
< param
; i
++)
143 printf("%d ", paramArray
[i
] - GL_TEXTURE0
);
146 image
= LoadRGBImage(TexFile
, &imgWidth
, &imgHeight
, &imgFormat
);
148 printf("Couldn't read %s\n", TexFile
);
152 glBindTexture( GL_TEXTURE_2D
, 1 );
153 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
154 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
155 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
156 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
157 glTexImage2D( GL_TEXTURE_2D
, 0, imgFormat
, imgWidth
, imgHeight
, 0,
158 imgFormat
, GL_UNSIGNED_BYTE
, image
);
160 for (j
= 0; j
< 16; j
++) {
161 for (i
= 0; i
< 16; i
++) {
162 temp
[j
][i
][0] = cos((float)(i
) * 3.1415 / 16.0);
163 temp
[j
][i
][1] = -0.5;
166 glBindTexture( GL_TEXTURE_2D
, 2 );
167 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
168 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
169 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
170 glTexParameteri( GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
171 glTexImage2D( GL_TEXTURE_2D
, 0, GL_DU8DV8_ATI
, 16, 16, 0,
172 GL_DUDV_ATI
, GL_FLOAT
, temp
);
175 glNewList( 1, GL_COMPILE
);
177 glColor3f( 0.9, 0.0, 0.0 );
178 glMultiTexCoord2f( GL_TEXTURE0
, 0.0, 0.0 );
179 glMultiTexCoord2f( GL_TEXTURE1
, 0.0, 0.0 );
181 glMultiTexCoord2f( GL_TEXTURE0
, 1.0, 0.0 );
182 glMultiTexCoord2f( GL_TEXTURE1
, 1.0, 0.0 );
184 glMultiTexCoord2f( GL_TEXTURE0
, 1.0, 1.0 );
185 glMultiTexCoord2f( GL_TEXTURE1
, 1.0, 1.0 );
187 glMultiTexCoord2f( GL_TEXTURE0
, 0.0, 1.0 );
188 glMultiTexCoord2f( GL_TEXTURE1
, 0.0, 1.0 );
195 int main( int argc
, char *argv
[] )
197 glutInit( &argc
, argv
);
198 glutInitWindowPosition( 0, 0 );
199 glutInitWindowSize( 400, 400 );
200 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
);
201 glutCreateWindow( "GL_ATI_envmap_bumpmap test" );
202 glutReshapeFunc( Reshape
);
203 glutKeyboardFunc( Key
);
204 glutDisplayFunc( Display
);