Пример #1
0
static void
MakeBitmapTextures(void)
{
   const char *px =
      "        X     X "
      "   X     X   X  "
      "   X      X X   "
      " XXXXX     X    "
      "   X      X X   "
      "   X     X   X  "
      "        X     X "
      "        X     X ";
   const char *nx =
      "        X     X "
      "         X   X  "
      "          X X   "
      " XXXXX     X    "
      "          X X   "
      "         X   X  "
      "        X     X "
      "        X     X ";
   glGenTextures(2, Textures);
   MakeTexImage(px, Textures[0]);
   MakeTexImage(nx, Textures[1]);
}
Пример #2
0
// Do numColors * numColors tests in one batch.
// Setup a texture in which the colors vary by column.
// Draw a quadstrip in which we draw horizontal bands of colors.
// Drawing the textured quadstrips will fill the window with
// numColors * numColors test squares.
// Verify that they're all correct.
// Return:  true = pass, false = fail
bool
TexEnvTest::MatrixTest(GLenum envMode, GLenum texFormat,
	const char *envName, const char *formatName,
	int numColors, const GLfloat colors[][4],
	const GLfloat envColor[4], Window &w) {

	if (envMode == GL_DECAL && (texFormat != GL_RGB &&
		texFormat != GL_RGBA)) {
		// undefined mode
		return true;
	}

	glClear(GL_COLOR_BUFFER_BIT);

	// The texture colors are the columns
	MakeTexImage(texFormat, numColors, colors);

	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, envMode);
	glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, envColor);

	// The fragment colors are the rows
	GLfloat W = numColors * 3;
	GLfloat S = (float) (numColors*3) / (float) 256;
	glBegin(GL_QUAD_STRIP);
	glTexCoord2f(0, 0);  glVertex2f(0, 0);
	glTexCoord2f(S, 0);  glVertex2f(W, 0);
	for (int i = 0; i < numColors; i++) {
		glColor4fv(colors[i]);
		GLfloat y = i * 3 + 3;
		GLfloat t = y / (numColors * 3);
		glTexCoord2f(0, t);  glVertex2f(0, y);
		glTexCoord2f(S, t);  glVertex2f(W, y);
	}
	glEnd();

	const GLsizei width = 256;
	const GLsizei height = 256;
	GLfloat *image = new GLfloat[width*height*4];
	glReadPixels(0, 0, width, height, GL_RGBA, GL_FLOAT, image);

	w.swap(); // lets us watch the progress

	// Check results
	for (int row = 0; row < numColors; row++) {
		for (int col = 0; col < numColors; col++) {

			// compute expected
			GLfloat expected[4];
			ComputeExpectedColor(envMode, texFormat,
				colors[col], colors[row],
				envColor, expected);

			// fetch actual pixel
			int x = col * 3 + 1;
			int y = row * 3 + 1;
			const GLfloat *actual = image + y*width*4 + x*4;

			// compare
			if (!TestColor(expected, actual)) {
				// Report the error
				env->log << name
					 << ":  FAIL:  GL_TEXTURE_ENV_MODE="
					 << envName
					 << "  Texture Format="
					 << formatName
					 << "  Fragment Color=("
					 << colors[row][0] << ", "
					 << colors[row][1] << ", "
					 << colors[row][2] << ", "
					 << colors[row][3] << ") "
					 << " Texture Color=("
					 << colors[col][0] << ", "
					 << colors[col][1] << ", "
					 << colors[col][2] << ", "
					 << colors[col][3] << ") "
					 << " Tex Env Color=("
					 << envColor[0] << ", "
					 << envColor[1] << ", "
					 << envColor[2] << ", "
					 << envColor[3] << ") "
#if BLEND_WITH_BACKGROUND
					 << " Blend over=("
					 << BgColor[0] << ", "
					 << BgColor[1] << ", "
					 << BgColor[2] << ", "
					 << BgColor[3] << ") "
#endif
					 << " Expected=("
					 << expected[0] << ", "
					 << expected[1] << ", "
					 << expected[2] << ", "
					 << expected[3] << ") "
					 << " Measured=("
					 << actual[0] << ", "
					 << actual[1] << ", "
					 << actual[2] << ", "
					 << actual[3] << ")\n";
				delete[] image;
				return false;
			}
		}
	}
	delete[] image;
	return true;
}