title: How to store INTEGER vec2 to texture using FBO and read it by glReadPixels
body: <p>I want to generate an integer texture with two channels, and I want the first channel to store the index of each vertex and the second channel to store the index of the model, so each pixel in this texture is like <code>(vertex_id, model_id)</code> and they are both integers.
  Texture binding:</p>
  <pre class="lang-cpp prettyprint-override"><code>glBindTexture(GL_TEXTURE_2D, id_tex);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RG32UI, width, height, 0, GL_RG_INTEGER, GL_UNSIGNED_INT, NULL);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, id_tex, 0);
  glBindTexture(GL_TEXTURE_2D, 0);
  </code></pre>
  <p>Read pixels:</p>
  <pre class="lang-cpp prettyprint-override"><code>double x, y;
  glfwGetCursorPos(window, &amp;x, &amp;y);
  unsigned rg[2];
  glReadBuffer(GL_COLOR_ATTACHMENT1);
  glReadPixels(x, height - y - 1, 1, 1, GL_RG_INTEGER, GL_UNSIGNED_INT, rg);
  glReadBuffer(GL_NONE);
  cout &lt;&lt; rg[0] &lt;&lt; ' ' &lt;&lt; rg[1] &lt;&lt; endl;
  </code></pre>
  <p>shader:</p>
  <pre class="lang-cpp prettyprint-override"><code>#version 450 core
  layout( location = 0 ) out vec4 scene_color;
  layout( location = 1 ) out vec2 vid_mid;
  
  flat in int index;
  in vec3 FragPos;
  in vec3 Position;
  in vec3 Normal;
  
  uniform int mid;
  
  void main(){
      scene_color = vec4(Normal, 1.0);
      vid_mid = vec2(index, mid);
  }
  </code></pre>
  <p>This is <a href="https://i.stack.imgur.com/9MRv1.png" rel="nofollow noreferrer">what I got</a>(since the vertex index is greater than the model index, so the red color is reasonable):</p>
  <p>But when I use <code>glReadPixels</code> to get the pixel color at <code>(x, y)</code>, <a href="https://i.stack.imgur.com/4SWJz.png" rel="nofollow noreferrer">I got</a>:</p>
  <p><strong>But what I actually want is the <code>(vertex_id, model_id)</code></strong></p>