Uniforms are just (per-program) OpenGL state. The way you set the uniform values is completely independent of linking the shaders to a program object - the GL knows nothing about that at shader link time, the program just has a bunch of active uniforms and you can set them to anything you like at any time.
Uniforms always have a type. And you have to use the correct glUniform*()
function matching the type of your uniform variable, otherwise the GL error GL_INVALID_OPERATION
is generated (and the operation has no further effect). FOr sampler uniforms, you need to set the index of the texture unit as integer, hence glUniform1i()
is the correct function, while glUniform1f()
- which is for floats - will not work. As you did not set the uniform, the previous value of that uniform will be used - and it will be 0 if you never set it.
So what happened is that you sampled from the texure bound to texture unit GL_TEXTURE0
, and not the one you wanted. You might use that texture unit when you create your textures, which would explain will there is still the "last" textture bound.