GLSL / Multi-texture problem

Started by
2 comments, last by deavik 18 years ago
I'm having difficulties with multi-texturing in GLSL. I have binded my textures in the usual way (glActiveTexture, glBindTexture, glEnable(GL_TEXTURE_2D) ) and multi-texturing works for the fixed function pipeline. When I switch to using a shader object, multi-texturing doesn't work! This leads me to believe that either: 1. My GLSL code is incorrect 2. There is something that I haven't done (an OpenGL function I haven't called maybe?) before the geometry is rendered Attached below is a simple fragment shader that should use the first set of texture coordinates to sample the 2D texture binded to GL_TEXTURE1:
uniform sampler2D sampler0, sampler1;
void main ( void )
{
	gl_FragColor = texture2D ( sampler1, gl_TexCoord[0] );
}
What actually happens is no matter which sampler I use for the first argument of 'texture2D', it always samples the 2D texture bound to GL_TEXTURE0. I am definitely binding my textures correctly, as fixed-function works fine. Any help would be much appreciated! Thanks, birdjames.
Advertisement
in GLSL, you must tell openGL wich texture is associated with wich sampler.opengl don't know that sampler0 is bound to texture 0, and sampler1 to texture 1. You must explicitely tell him.

you have to set your's samplers values their texture unit numbers with the GLUniform functions, like you would do with other uniforms.
Thanks for your quick reply - problem fixed.
birdjames.
Glad you got that sorted out! However, it's possible I'm wrojng but I think texture2D(...) expects a vec2 as the second argument. You should really be using gl_TexCoord[0].st

This topic is closed to new replies.

Advertisement