title: Problem with reading multiple texture units from a Shader in OpenGL
body: <p>I am trying to read two different textures in my shader, one for regular texturing, and one bumpmap. However both Sampler2D's are reading from the same texture unit. I am setting the uniforms to 0 and 1 however, and I have bound the textures to their respective units as follows:</p>
  
  <pre><code>glActiveTexture(GL_TEXTURE0);
  glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, texMgr-&gt;GetTexture("stone")-&gt;texture);
  
  glActiveTexture(GL_TEXTURE1);
  glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, texMgr-&gt;GetTexture("bump")-&gt;texture);
  </code></pre>
  
  <p>In my render loop I set the uniforms as follows:</p>
  
  <pre><code>shaderMgr-&gt;activeProgram()-&gt;setUniform1f("tex", 0);
  shaderMgr-&gt;activeProgram()-&gt;setUniform1f("norm", 1);
  </code></pre>
  
  <p>And finally my shader code:</p>
  
  <pre><code>varying vec4 colorVarying;
  varying vec4 normalVarying;
  varying vec3 lightDirVarying;
  varying vec2 textureCoordinateVarying;
  
  uniform sampler2D tex;
  uniform sampler2D norm;
  
  void main() {    
      vec4 texColor = texture2D(tex, textureCoordinateVarying);
      vec4 normColor = texture2D(norm, textureCoordinateVarying);
      vec3 newNormal = vec3(2.0 * normColor.x - 1.0, 2.0 * normColor.y - 1.0, 2.0 * normColor.z - 1.0);
      vec3 normal = normalize(normalVarying.xyz + newNormal);
      float diff = max(0.0, dot(normal, normalize(lightDirVarying)));
  
      gl_FragColor = texColor * (diff + 0.3);
  }
  </code></pre>
  
  <p>I only call glActiveTexture in my renderloop every time I draw an Object, and I only call glActiveTexture(GL_TEXTURE1) once (in my initialization).</p>
  
  <pre><code>glActiveTexture(GL_TEXTURE0);
  glBindTexture( GL_TEXTURE_2D, object-&gt;tex-&gt;texture);
  </code></pre>
  
  <p>Everything is working fine for the first texture, but the second texture (Bump) isn't showing up. I've tried:</p>
  
  <ul>
  <li>Adding ARB to everything, I'm not sure if this matters. (I'm on OSX 10.6 if that is of any use)</li>
  <li>Adding glEnable(GL_TEXTURE_2D) every time I switch texture units.</li>
  <li>Not switching between programs, and just run with one shaders, and set the uniforms in my initialization </li>
  <li>Resetting the texture params every time I switch texture units.</li>
  <li>Not switching between TextureUnits, and only initialize them at the start</li>
  <li>Started a new project, only copied the relevant code and ran it, kept it as small as possible</li>
  </ul>
  
  <p>All these things didn't help, the norm sampler is solely reading the GL_TEXTURE0 unit.</p>
  
  <p>I have been searching for hours now, and I still haven't found the answer. I have no idea what I am doing wrong and why my norm sampler isn't reading from the proper GL_TEXTURE1 unit.</p>