Hi guys,
I’m been struggling to use texture combiners for a while now. If anyone could help me, that’d be nice. I cannot use shaders because we have to cater for low end graphics cards. So my only option is texture combiners.
What I want to is this:
- Add the color (0.5,0.5,0.5,1.0) to texture0
- Perform a dot3 operation with texture1 and the result of Step1.
Texture0 is a nice picture of a girl.
Texture1 is a flat color with values (0.58, 0.58, 0.58 );
If all goes well, I should get the grayscale texture as my final result. That’s because the dot3 operation performs the following operation:
4 * ( ( ( r0 - 0.5 ) * (r1 - 0.5 ) ) +
( ( g0 - 0.5 ) * (g1 - 0.5 ) ) +
( ( b0 - 0.5 ) * (b1 - 0.5 ) ) );
So if I add r0,g0,b0 with 0.5 (thus canceling the -0.5 that occurs during the dot3 operation) and perform a dot3 operation with a texture having a color of (0.58 0.58, 0.58 ), i should end up with a result of
( ( r0 * 0.33 ) + ( g0 * 0.33 ) + ( b0 * 0.33 ) )
I tried it out and I get a greyscale image for sure. But it’s heavily contrasted. And I mean heavily! I did some debugging and it looks that the first operation is not being taken into account. i.e the GL_ADD operation
Can someone please tell me what I’m doing wrong.
thx.
Below is my code:
glActiveTextureARB( GL_TEXTURE0 );
glEnable(GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, m_textureID0 );
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
//Color Operation
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD );
//source 0
GLfloat rgba[4] = { 0.5f, 0.5f, 0.5f, 1.0f };
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, rgba );
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_CONSTANT );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR );
//Source 1
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE0 );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR );
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE );
//Color Operation
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_DOT3_RGB );
//Source 0
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR );
glActiveTextureARB( GL_TEXTURE1 );
glEnable(GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, m_textureID1 );
//Source 1
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE1 );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR );
glActiveTextureARB( GL_TEXTURE1 );
glDisable(GL_TEXTURE_2D );
glBegin( GL_QUADS );
glMultiTexCoord2fARB( GL_TEXTURE0, 0, 0 );
glVertex3d( -1, -1, -2.0 );
glMultiTexCoord2fARB( GL_TEXTURE0, 1, 0 );
glVertex3d( 1, -1, -2.0 );
glMultiTexCoord2fARB( GL_TEXTURE0, 1, 1 );
glVertex3d( 1, 1, -2.0 );
glMultiTexCoord2fARB( GL_TEXTURE0, 0, 1 );
glVertex3d( -1, 1, -2.0 );
glEnd();
glActiveTextureARB( GL_TEXTURE0 );
glDisable(GL_TEXTURE_2D );