Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Problem with multi-texturing

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2011
    Location
    USA
    Posts
    17

    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:
    Code :
    #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:
    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

  2. #2
    Member Regular Contributor malexander's Avatar
    Join Date
    Aug 2009
    Location
    Ontario
    Posts
    328
    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.

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2011
    Location
    USA
    Posts
    17
    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:

    Code :
    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.

  4. #4
    Junior Member Newbie
    Join Date
    Apr 2011
    Location
    USA
    Posts
    17
    I found the problem. I was using glSetUniformf instead of glSetUniformi.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •