title: OpenGL - GLSL assigning to varying variable breaks the vertex positioning
body: <p>I did a project in OpenGL version 3.2 once where I used a "sampler2DArray" to store multiple images with the same dimensions and rendered them using textured points.</p>
  
  <p>Now I am trying to port that project to my gnu/linux computer. This computer only supports up to OpenGL version to 2.1 and GLSL version up to 1.20 (which doesn't have sampler2DArray). As far as I know there is no way to update OpenGL to support the newer features.</p>
  
  <p>What I am currently trying to do is to use a sampler3D to store my images and use the depth value to select the image I want.</p>
  
  <p>To send the texture depth from the vertex shader to the fragment shader I have declared a "varying" float variable holding the depth value (0.0 to 1.0). </p>
  
  <p>I am rendering 4 images at the locations: (-0.5, +0.5), (+0.5, +0.5), (-0.5, -0.5) and (+0.5, -0.5).</p>
  
  <p>The image switching method appears to be working (changing the "index" variable changes the image). But for some wierd reason all images gets rendered at (0.0, 0.0) and not at their assigned positions. This problem goes away when I don't assign to the varying variable containing the depth value for the texture and set the depth value to 0.0 in the fragment shader.</p>
  
  <p>Here is the vertex shader:</p>
  
  <pre><code>#version 120
  
  attribute vec2 position
  attribute float index
  varying float v_index
  
  void main()
  {
      gl_Position = vec4(position, 0.0, 1.0);
      v_index = index; // Removing this assignment makes the images appear at their assigned locations.
  }
  </code></pre>
  
  <p>Here is the fragment shader:</p>
  
  <pre><code>#version 120
  
  uniform sampler3D texture;
  varying float v_index;
  
  void main()
  {
      gl_FragColor = texture3D(texture, vec3(gl_PointCoord, v_index));
  }
  </code></pre>
  
  <p>The structure I use represent vertices:</p>
  
  <pre><code>struct vertex {
      GLfloat x;
      GLfloat y;
      GLfloat texture_index;
  };
  </code></pre>
  
  <p>The calls to the <code>glVertexAttribPointer</code> function (the problem may be here too):</p>
  
  <pre><code>glBindAttribLocation(shader_program, 0, "position");
  glEnableVertexAttribArray(0);
  glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(struct vertex), (void *)0);
  glBindAttribLocation(shader_program, 1, "index");
  glEnableVertexAttribArray(1);
  glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, sizeof(struct vertex), (void *)(2 * sizeof(GLfloat));
  </code></pre>
  
  <p>I have also found a very similar question. The answer marked "accepted" claims that the cause of the problem is that the shaders have more than 16 varying vectors (which isn't the case for me).</p>
  
  <p>Here is the link: <a href="https://stackoverflow.com/questions/13189412/strange-error-in-glsl-while-assigning-attribute-to-a-varying-in-vertex-shader">Strange error in GLSL while assigning attribute to a varying in vertex shader</a></p>