how to render multiple textures with GLSL
Question
i am about to port all my rendering from "old" opengl to glsl.
now i have a mesh with different textures, so in "old" gl i just used bindTexture to change the texture. i guess, i still need to do this, but something is missing, since my everything seems to be rendered with the first texture only.
uniform sampler2D tex;
void main() {
gl_FragColor = tex2D(tex, gl_TexCoord[0].st);
}
"tex" is the name of the texture which i put to glsl like this:
int loc = glGetUniformLocationARB(id, "tex");
glUniform1iARB(loc, 0);
note: i am not talking about multitexturing! :-)
Solution
You have bound texture unit 0 to the sampler2D
, but you need to bind the texture to the texture unit as well. So that'd be simply a glBindTexture
call.
OTHER TIPS
i was confused with the way to tell GLSL which texture unit to use for which sampler as well. i searched hours for my problem and could not solve it because i think this topic is not very well explained in all the literature out there.
here is a valuable explaination: (see the part "Using Textures With GLSL") http://nehe.gamedev.net/data/articles/article.asp?article=21
maybe this helps somebody!