3

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

1
  • So if my previous answer was wrong, could you maybe show us some more of your C code?
    – Thomas
    Nov 23, 2009 at 8:24

2 Answers 2

6

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.

3
  • 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
    Nov 22, 2009 at 22:08
  • 1
    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
    Nov 23, 2009 at 12:36
  • bahbar: thanks, that was it! i accidentally had another texture unit active!
    – clamp
    Nov 24, 2009 at 10:05
5

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!

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.