title: Render Large Texture To Smaller Renderbuffer
body: <p>I have a render buffer that is 852x640 and a texture that is 1280x720. When I render the texture, it is getting cropped, not just stretched. I know the aspect ratio needs correcting, but how can I get it so that the full texture displays in the render buffer?</p>
  
  <pre><code>//-------------------------------------
      glGenFramebuffers(1, &amp;frameBufferHandle);
      glBindFramebuffer(GL_FRAMEBUFFER, frameBufferHandle);
  
      glGenRenderbuffers(1, &amp;renderBufferHandle);
      glBindRenderbuffer(GL_RENDERBUFFER, renderBufferHandle);
  
      [oglContext renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer *)self.layer];
  
      glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &amp;renderBufferWidth);
      glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &amp;renderBufferHeight);
  
      glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderBufferHandle);
  //-------------------------------------
  
  
  static const GLfloat squareVertices[] = {
      -1.0f, 1.0f,
      1.0f, 1.0f,
      -1.0f,  -1.0f,
      1.0f,  -1.0f
  };
  
  static const GLfloat horizontalFlipTextureCoordinates[] = {
      0.0f, 1.0f,
      1.0f, 1.0f,
      0.0f,  0.0f,
      1.0f,  0.0f,
  };
  
  size_t frameWidth = CVPixelBufferGetWidth(pixelBuffer);
  size_t frameHeight = CVPixelBufferGetHeight(pixelBuffer);
  
  CVReturn err = CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault, 
                                                              videoTextureCache,
                                                              pixelBuffer,
                                                              NULL,
                                                              GL_TEXTURE_2D,
                                                              GL_RGBA,
                                                              frameWidth,
                                                              frameHeight,
                                                              GL_BGRA,
                                                              GL_UNSIGNED_BYTE,
                                                              0,
                                                              &amp;texture);
  
  
  if (!texture || err) {
      NSLog(@"CVOpenGLESTextureCacheCreateTextureFromImage failed (error: %d)", err);  
      return;
  }
  
  glBindTexture(CVOpenGLESTextureGetTarget(texture), CVOpenGLESTextureGetName(texture));
  
  glViewport(0, 0, renderBufferWidth, renderBufferHeight); // setting this to 1280x720 fixes the aspect ratio but still crops
  
  glBindFramebuffer(GL_FRAMEBUFFER, frameBufferHandle);
  
  glUseProgram(shaderPrograms[PASSTHROUGH]);
  
  // Update attribute values.
  glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices);
  glEnableVertexAttribArray(ATTRIB_VERTEX);
  glVertexAttribPointer(ATTRIB_TEXTUREPOSITON, 2, GL_FLOAT, 0, 0, horizontalFlipTextureCoordinates);
  glEnableVertexAttribArray(ATTRIB_TEXTUREPOSITON);
  
  glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  
  // Present
  glBindRenderbuffer(GL_RENDERBUFFER, renderBufferHandle);
  [oglContext presentRenderbuffer:GL_RENDERBUFFER];
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>I'm still running into issues. I've included more source. Basically, I need the entire raw input texture to display in wide screen while also writing the raw texture to disk. </p>
  
  <p>When rendering to a smaller texture, things are automatically scaled, is this not the case with a renderbuffer? </p>
  
  <p>I guess I could make another passthrough to a smaller texture, but that would slow things down.</p>