demos: add missing binaries to .gitignore
[mesa-demos.git] / src / tests / bumpmap.c
blobc77394a94c3f953b9394e4fce51afe9d177a2488
1 /*
2 * Copyright (c) 2009 VMware, Inc.
3 * All Rights Reserved.
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
14 * Software.
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.
25 /**
26 * Simple test for testing ATI_envmap_bumpmap support.
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <math.h>
33 #include <GL/glew.h>
34 #include "glut_wrap.h"
36 #include "readtex.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 );
53 glPushMatrix();
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 );
63 /* bump map */
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);
73 glCallList(1);
75 glPopMatrix();
77 glutSwapBuffers();
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 );
86 glLoadIdentity();
87 glFrustum( -ar, ar, -1.0, 1.0, Near, Far );
88 glMatrixMode( GL_MODELVIEW );
89 glLoadIdentity();
90 glTranslatef( 0.0, 0.0, -6.0 );
94 static void Key( unsigned char key, int x, int y )
96 (void) x;
97 (void) y;
98 switch (key) {
99 case 27:
100 exit(0);
101 break;
103 glutPostRedisplay();
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;
114 GLenum imgFormat;
115 GLint i,j;
116 GLint param, paramArray[16];
117 GLfloat paramMat[4];
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");
124 exit(1);
127 glGetTexBumpParameterivATI(GL_BUMP_ROT_MATRIX_SIZE_ATI, &param);
128 printf("BUMP_ROT_MATRIX_SIZE_ATI = %d\n", param);
129 glGetTexBumpParameterivATI(GL_BUMP_NUM_TEX_UNITS_ATI, &param);
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);
137 printf("\n");
139 image = LoadRGBImage(TexFile, &imgWidth, &imgHeight, &imgFormat);
140 if (!image) {
141 printf("Couldn't read %s\n", TexFile);
142 exit(0);
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 );
169 glBegin(GL_QUADS);
170 glColor3f( 0.9, 0.0, 0.0 );
171 glMultiTexCoord2f( GL_TEXTURE0, 0.0, 0.0 );
172 glMultiTexCoord2f( GL_TEXTURE1, 0.0, 0.0 );
173 glVertex2f(-1, -1);
174 glMultiTexCoord2f( GL_TEXTURE0, 1.0, 0.0 );
175 glMultiTexCoord2f( GL_TEXTURE1, 1.0, 0.0 );
176 glVertex2f( 1, -1);
177 glMultiTexCoord2f( GL_TEXTURE0, 1.0, 1.0 );
178 glMultiTexCoord2f( GL_TEXTURE1, 1.0, 1.0 );
179 glVertex2f( 1, 1);
180 glMultiTexCoord2f( GL_TEXTURE0, 0.0, 1.0 );
181 glMultiTexCoord2f( GL_TEXTURE1, 0.0, 1.0 );
182 glVertex2f(-1, 1);
183 glEnd();
184 glEndList();
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" );
195 glewInit();
196 glutReshapeFunc( Reshape );
197 glutKeyboardFunc( Key );
198 glutDisplayFunc( Display );
199 Init();
200 glutMainLoop();
201 return 0;