tags:

views:

767

answers:

2

hello,

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! :-)

+3  A: 

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.

Thomas
thanks, yepp, as i said i am still doing the glBindTexture call, but even though i bind a different texture at a specific time, i still see the object with the previous texture.
clamp
glBindTexture is the call that changes what is bound. If that does not work for you, it either means your call to glBindTexture is wrong, or you are modifying a different texture unit (e.g. because you called glActiveTexture and forgot to reset the active texture unit to 0).
Bahbar
bahbar: thanks, that was it! i accidentally had another texture unit active!
clamp
+2  A: 

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!

didito