Rendering a texture grayscale using multi-texturing

Hello, I’m trying to render a texture as grayscale but the second texture unit operation is not being performed. Perhaps there are other issues. I’ve based this code off of:

Here is my version for the IPhone:

	//Set up OpenGL states
	glDisable(GL_DITHER);
        glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glEnable(GL_BLEND);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_TEXTURE_2D);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE);

	glActiveTexture(GL_TEXTURE0);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, tx1);
	glTexCoordPointer(2, GL_FLOAT, 0, textureCoords);

	// Now that the texture colors have been moved up into the pseudo signed range (+0.5)
	// We can dot them with the luminances
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
	glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD);

	GLfloat offset[4] = { 0.5f, 0.5f, 0.5f, 1.0f };
	glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, offset);
	glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_CONSTANT);
	glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);

	glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE0);
	glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);


	// Now dot those values with the luminances (adjusted for the dot3 equation)
	glActiveTexture(GL_TEXTURE1);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, grayMultiplier);
	glTexCoordPointer(2, GL_FLOAT, 0, textureCoords);

	glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE ); 
	glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_DOT3_RGB );

	// Combination equation, previous value dot3 with the luminance texture
	glTexEnvi( GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS );
	glTexEnvi( GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PREVIOUS );
	glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR );
	glTexEnvi( GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE1 );
	glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR );

	glVertexPointer(3, GL_FLOAT, 0, vertices);
	glDrawArrays(GL_TRIANGLES, 0, vertexCount);

	// Disable this texture unit
	glDisable(GL_TEXTURE_2D);

	glDisable(GL_BLEND);
	glDisable(GL_DEPTH_TEST);
	glDisable(GL_TEXTURE_2D);
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);

Any ideas? Thanks in advance!

Shane

Hello,

I found the problem. On lines like this:

   glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE0);

I was using the wrong constant, GL_TEXTURE0, instead of GL_TEXTURE. That mistake disabled the rendering pipeline.

Shane

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.