예제 #1
0
static void Display( void )
{
   /* together with the construction of dudv map, do fixed translation
      in y direction (up), some cosine deformation in x and more
      deformation in y dir */
   GLfloat bumpMatrix[4] = {0.1, 0.0, 0.2, 0.1};


   glClearColor(0.2, 0.2, 0.8, 0);
   glClear( GL_COLOR_BUFFER_BIT );

   glPushMatrix();

   /* this is the base map */
   glActiveTexture( GL_TEXTURE0 );
   glEnable( GL_TEXTURE_2D );
   glBindTexture( GL_TEXTURE_2D, 1 );
   glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
   glTexEnvf( GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE );
   glTexEnvf( GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE );

   /* bump map */
   glActiveTexture( GL_TEXTURE1 );
   glEnable( GL_TEXTURE_2D );
   glBindTexture( GL_TEXTURE_2D, 2 );
   glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
   glTexEnvf( GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_BUMP_ENVMAP_ATI );
   glTexEnvf( GL_TEXTURE_ENV, GL_BUMP_TARGET_ATI, GL_TEXTURE0);

   glTexBumpParameterfvATI(GL_BUMP_ROT_MATRIX_ATI, bumpMatrix);

   glCallList(1);

   glPopMatrix();

   glutSwapBuffers();
}
예제 #2
0
파일: bump.c 프로젝트: chemecse/piglit
enum piglit_result
piglit_display(void)
{
	GLboolean pass = GL_TRUE;
	GLuint tex, bump;
	int x, y;
	float bump_matrix[4] = {1.0, 0.0, 0.0, 1.0};
	float red[4]   = {1.0, 0.0, 0.0, 1.0};
	float green[4] = {0.0, 1.0, 0.0, 1.0};
	float blue[4]  = {0.0, 0.0, 1.0, 1.0};
	float white[4] = {1.0, 1.0, 1.0, 1.0};
	float bumpdata[TEXSIZE][TEXSIZE][2];

	/* First: the base texture. */
	tex = piglit_rgbw_texture(GL_RGBA, TEXSIZE, TEXSIZE,
				  GL_FALSE, GL_FALSE, GL_UNSIGNED_NORMALIZED);
	glActiveTexture(tex_unit);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, tex);

	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
	glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
	glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);

	/* Second: the bumpmap. */
	glGenTextures(1, &bump);
	glActiveTexture(bump_unit);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, bump);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
	glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_BUMP_ENVMAP_ATI);
	glTexEnvf(GL_TEXTURE_ENV, GL_BUMP_TARGET_ATI, tex_unit);

	/* The bump map we use is going to end up rotating texels CCW. */
	for (y = 0; y < TEXSIZE; y++) {
		for (x = 0; x < TEXSIZE; x++) {
			if (y < TEXSIZE / 2) {
				if (x < TEXSIZE / 2) {
					bumpdata[y][x][0] = 0.0;
					bumpdata[y][x][1] = 0.5;
				} else {
					bumpdata[y][x][0] = -0.5;
					bumpdata[y][x][1] = 0.0;
				}
			} else {
				if (x < TEXSIZE / 2) {
					bumpdata[y][x][0] = 0.5;
					bumpdata[y][x][1] = 0.0;
				} else {
					bumpdata[y][x][0] = 0.0;
					bumpdata[y][x][1] = -0.5;
				}
			}
		}
	}

	glTexImage2D(GL_TEXTURE_2D, 0, GL_DU8DV8_ATI, TEXSIZE, TEXSIZE, 0,
		     GL_DUDV_ATI, GL_FLOAT, bumpdata);

	glTexBumpParameterfvATI(GL_BUMP_ROT_MATRIX_ATI, bump_matrix);

	draw_rect_multitex(-1, -1, 2, 2,
			   0, 0, 1, 1);

	pass = pass && piglit_probe_rect_rgba(0,
					      0,
					      piglit_width / 2,
					      piglit_height / 2,
					      blue);
	pass = pass && piglit_probe_rect_rgba(piglit_width / 2,
					      0,
					      piglit_width / 2,
					      piglit_height / 2,
					      red);
	pass = pass && piglit_probe_rect_rgba(0,
					      piglit_height / 2,
					      piglit_width / 2,
					      piglit_height / 2,
					      white);
	pass = pass && piglit_probe_rect_rgba(piglit_width / 2,
					      piglit_height / 2,
					      piglit_width / 2,
					      piglit_height / 2,
					      green);

	piglit_present_results();

	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
}