2

I want to combine 2 textures in a GLSL shader to 1.

the problem is that I fail to set the sampler2D in the shader from my program. (the shader/program compiles correctly, the textures load correctly, the vertex shader is correct too) I tried it with the following code from a tutorial:

glUniform1i(program.getUniformLocation("Texture0"), 0);
glUniform1i(program.getUniformLocation("Texture1"), 1);

//texture 0, first texture
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, colorTexture.handle);

//texture 1, other texture
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, normalTexture.handle);

the fragment shader code looks like this

uniform sampler2D Texture0;
uniform sampler2D Texture1;

void main(void)
{
    vec4 color = texture2D(Texture0, vec2(gl_TexCoord[0]));
    vec4 normal = texture2D(Texture1, vec2(gl_TexCoord[0]));
    gl_FragColor = normal + color;
}

it gets drawn with

glUseProgram(program.handle);
glColor3f(1, 1, 1);
    glBegin(GL_QUADS);
    glTexCoord2f(0, 0);
    glVertex3f(0, 0, 0);
    glTexCoord2f(1, 0);
    glVertex3f(500, 0, 0);
    glTexCoord2f(1, 1);
    glVertex3f(500, 500, 0);
    glTexCoord2f(0, 1);
    glVertex3f(0, 500, 0);
    glEnd();
2
  • 1
    What does your vertex shader look like? And even more importantly: how does what the program actually does differ from what you expected it to do? Commented Jun 24, 2012 at 14:23
  • 2
    What you have up there looks correct to me. Have you tried glGetError? Commented Jun 24, 2012 at 15:34

1 Answer 1

2

try changing the second sampler to use gl_TexCoord[1]

uniform sampler2D Texture0;
uniform sampler2D Texture1;

void main(void)
{
    vec4 color = texture2D(Texture0, vec2(gl_TexCoord[0]));
    vec4 normal = texture2D(Texture1, vec2(gl_TexCoord[1]));
    gl_FragColor = normal + color;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.