title: OpenGL ES on iOS - glReadPixels() returns the image with a black bar on the side
body: <p>i like to render a simple texture with my fragment shader to 4 vertices and read the image resolution with glReadPixels. I set the (readPixel) size like the (source)picture size but i didn't get a complete image back. There is always a black bar on the right side. And the image seems to be compressed.</p>
  
  <p>The returned part of the image is correct. It shows the resolution of my sobel shader. So i didn't think that there are some errors on the ReadPixel part or the SetImage part. But i don't know... </p>
  
  <p>Here is my method to set the image source:</p>
  
  <pre><code>-(void)setImageSource : (unsigned char*) image
  {
  static const GLfloat textureVertices[] = 
  {
      0.0f, 1.0f,
      0.0f, 0.0f,
      1.0f, 1.0f,
      1.0f, 0.0f,
  };
  
  static const GLfloat squareVertices[] = 
  {
      -1.0f, -1.0f,
      1.0f, -1.0f,
      -1.0f, 1.0f,
      1.0f, 1.0f
  };
  
  glGenTextures(1, &amp;pictureTexture);
  glActiveTexture(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, pictureTexture);
  
  glUniform1i(uniforms[UNIFORM_VIDEOFRAME], 0);
  
  glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices);
  glEnableVertexAttribArray(ATTRIB_VERTEX);
  glVertexAttribPointer(ATTRIB_TEXTUREPOSITON, 2, GL_FLOAT, 0, 0, textureVertices);
  glEnableVertexAttribArray(ATTRIB_TEXTUREPOSITON);
  
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imageHeight, imageWidth, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
  }
  </code></pre>
  
  <p>Here the part to render the texture:</p>
  
  <pre><code>-(void)render
  {
      glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
      glViewport(0, 0, imageHeight, imageWidth);
  
      [self presentFramebuffer];
  }
  </code></pre>
  
  <p>And here is the part to read the resolution back:</p>
  
  <pre><code>-(void)readPixels : (unsigned char*) dest
  {            
      glReadPixels(0, 0, imageHeight, imageWidth, GL_RGBA, GL_UNSIGNED_BYTE, dest);
  
      glDeleteTextures(1, &amp;pictureTexture);
  }
  </code></pre>
  
  <p>I don't have any idea where i make the error. I've searched on this forum and on the khronos group forum but i didn't get a solution for this (and i didn't find a case with the same error description).</p>
  
  <p>Maybe another important or confusing information - I've also tried to put the code to a c++ class. But when i go outside the Objective C class with the EAGLContext i got the correct picture size back but the resolution is wrong the resolution image contains just snow but without the black bar on the side.</p>
  
  <p>Did someone knew a solution for this error?</p>
  
  <p>Regards,
  krikit</p>