title: GLSL Shader multi-texture lookup with different texCoord (iPad)
body: <p>I'm in GLSL texture hell: I load 4 different textures of the same size in uniform sampler2D variables in my fragment shader and try to access them with different texture coordinates:</p>
  
  <pre><code>uniform sampler2D image0, image1, image2, image3;
  varying highp vec2 texCoord;
  
  void main()
  {   
  highp vec2 tc = vec2(texCoord.x, mod(1.0-texCoord.y, 0.2) + 0.2);
  
  lowp vec4 color0 = texture2D(image0, tc);
  lowp vec4 color1 = texture2D(image1, tc);
  lowp vec4 color2 = texture2D(image2, tc);
  lowp vec4 color3 = texture2D(image3, tc);
  
  if (texCoord.y &lt; 0.2) { gl_FragColor = color0; }
  else if (texCoord.y &lt; 0.4) { gl_FragColor = color1; }
  else if (texCoord.y &lt; 0.6) { gl_FragColor = color2; }
  else if (texCoord.y &lt; 0.8) { gl_FragColor = color3; }
  else { gl_FragColor = vec4(0.0); }
  }
  </code></pre>
  
  <p>The texCoord comes from the vertex shader of course:</p>
  
  <pre><code>uniform lowp float ratio;
  attribute highp vec4 vertex;
  varying highp vec2 texCoord;
  
  void main()
  {
  gl_Position = vertex;
  texCoord.x = ((vertex.x * 0.5) + 0.5) * ratio;
  texCoord.y = (vertex.y * 0.5) + 0.5;
  }
  </code></pre>
  
  <p>I get 5 separate slices, from image0, image2 (!! not image1), image3, image3 (again!), and black (this would hold a merge of the various texture, not important in this context, my problem being getting the right textures first). I checked the image loading code multiple times, I do load 4 different images:</p>
  
  <pre><code>- (void)linkTexture:(GLenum)tex image:(Image *)image varName:(const char *)varName
  {
  GLint texLocation;
  
  texLocation = glGetUniformLocation(program, varName);
  glUniform1i(texLocation, tex-GL_TEXTURE0);
  glActiveTexture(tex);
  glBindTexture(GL_TEXTURE_2D, image-&gt;texID);
  }
  </code></pre>
  
  <p>and further down:</p>
  
  <pre><code>    loadTexture("new_york_0.jpg", &amp;image0, &amp;renderer);
      [self linkTexture:GL_TEXTURE0 image:&amp;image0 varName:"image0"];
  
      loadTexture("new_york_1.jpg", &amp;image1, &amp;renderer);
      [self linkTexture:GL_TEXTURE1 image:&amp;image1 varName:"image1"];
  
      loadTexture("new_york_2.jpg", &amp;image2, &amp;renderer);
      [self linkTexture:GL_TEXTURE2 image:&amp;image2 varName:"image2"];
  
      loadTexture("new_york_3.jpg", &amp;image3, &amp;renderer);
      [self linkTexture:GL_TEXTURE3 image:&amp;image3 varName:"image3"];
  </code></pre>
  
  <p>There must be something very wrong in the way I expect the GPU to lookup textures but I have no clue what it is.</p>
  
  <p>Can someone shine a light?</p>