Problem with multi-texturing

Hello,

I am attempting to get a simple program to work which passes two textures to a shader, and will allow me to switch between the two. Unfortunately, the shader only draws the texture that is bound to GL_TEXTURE0, regardless of the uniform assignment in the shader. The code is as follows:

The Fragment shader:


#version 400

in vec2 TexCoord;
uniform sampler2D Tex1;
uniform sampler2D Tex2;

layout (location = 0) out vec4 FragColor;

void main()
{
    vec4 col2 = texture( Tex2, TexCoord );
    vec4 col1 = texture( Tex1, TexCoord );
    FragColor = (col1 + col2)*0.5;
}

And the C++ code:


displayShader.Use();

    glActiveTexture(GL_TEXTURE0);
    glEnable(GL_TEXTURE_2D);
    displayShader.SetUniform("Tex2",0);
    glBindTexture(GL_TEXTURE_2D, swfInter.GetRenderTexture());
    

    glActiveTexture(GL_TEXTURE1);
    glEnable(GL_TEXTURE_2D);
    displayShader.SetUniform("Tex1",1);
    glBindTexture(GL_TEXTURE_2D, TheScenes[0].Maps[0].TextureHandle);

    m_MLAACorrector.DrawQuad(-1, displayShader, 100, 100, true );

    glActiveTexture(GL_TEXTURE1);  
    glBindTexture(GL_TEXTURE_2D, 0);  
  
    glActiveTexture(GL_TEXTURE0);  
    glBindTexture(GL_TEXTURE_2D, 0);  


And the DrawQuad function makes no texture calls. This code successfully draws a quad with texture swfInter.GetRenderTexture() (this textures has large sections of Alpha), yet does not display TheScenes[0].Maps[0].TextureHandle. Additionally, if I swap the glBindTexture calls, then the converse is true. Please let me know if you have any ideas.

Thanks

Are you sure the shader is compiling? There is no #version at the top,and you are using some later-version GLSL features.

Also, the glEnable(GL_TEXTURE_2D)'s are not required when drawing with a shader. They are only used by the fixed-function pipeline. If taking them out causes the texture to disappear, then the shader is not properly compiled.

Thanks for the reply, I will remove the enable tags for GL_TEXTURE_2D.

There is a #version tag at the top, denoting version 4. Additionally, I am checking for compile and linking errors, there appear to be none. Furthermore if I change the fragment line in the shader to:


FragColor = (col1 + col2)*0.1 + vec4(1,0,0, 0.5);

Then the shader correctly applies a red “tint” then the texture sitting in GL_TEXTURE0, without displaying the shader in GL_TEXTURE1.

I found the problem. I was using glSetUniformf instead of glSetUniformi.

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