Hi there!
I'm trying to create a simple shader that uses multiple textures (using one texture worked flawlessly). Here's the code (I use the same set of coords for both textures, is that ok?):
uniform sampler2D tex1;
uniform sampler2D tex2;
void main()
{
vec4 col1 = texture2D( tex1, gl_TexCoord[0].st );
vec4 col2 = texture2D( tex2, gl_TexCoord[0].st );
//gl_FragColor = col1;
gl_FragColor = col2;
}
The strange thing is that the shader always displays the same texture, no matter which of the two lines I comment out!
Here's the code of my application, where the textures are set and the quad is drawn:
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
bind(texColor);
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
bind(texColor);
glActiveTextureARB(GL_TEXTURE0_ARB);
glBegin(GL_QUADS);
glMultiTexCoord2fARB( GL_TEXTURE0_ARB, 0.0f, 0.0f );
glMultiTexCoord2fARB( GL_TEXTURE1_ARB, 0.0f, 0.0f );
glVertex3f( -20.0f, -20.0f, 0.0f );
glMultiTexCoord2fARB( GL_TEXTURE0_ARB, 0.0f, 1.0f );
glMultiTexCoord2fARB( GL_TEXTURE1_ARB, 0.0f, 1.0f );
glVertex3f( -20.0f, 20.0f, 0.0f );
glMultiTexCoord2fARB( GL_TEXTURE0_ARB, 1.0f, 1.0f );
glMultiTexCoord2fARB( GL_TEXTURE1_ARB, 1.0f, 1.0f );
glVertex3f( 20.0f, 20.0f, 0.0f );
glMultiTexCoord2fARB( GL_TEXTURE0_ARB, 1.0f, 0.0f );
glMultiTexCoord2fARB( GL_TEXTURE1_ARB, 1.0f, 0.0f );
glVertex3f( 20.0f, -20.0f, 0.0f );
glEnd();
IMHO the whole code is very simple and nothing can go wrong. But obviously it does. I always see the texture in unit 0, no matter what I do (of course, when I switch the two bind-lines I see the other texture).
How can that be?