title: Render contents of UIView as an OpenGL ES texture but only black turns out
body: <p>I'm learning OpenGL ES with the tutorial on raywenderlich.com <a href="http://www.raywenderlich.com/4404/opengl-es-2-0-for-iphone-tutorial-part-2-textures" rel="nofollow noreferrer">http://www.raywenderlich.com/4404/opengl-es-2-0-for-iphone-tutorial-part-2-textures</a></p>
  
  <p>When I get started to tweak the example project to grasp a UIView's content as the texture to get rendered, it's only black screen turns out just like:
  <img src="https://i.stack.imgur.com/m5gxK.png" alt="Black view is the OpenGL ES view"></p>
  
  <p>The black view is the OpenGL ES view.</p>
  
  <p>I used the code posted by Tommy in this post: <a href="https://stackoverflow.com/questions/4118778/render-contents-of-uiview-as-an-opengl-texture">Render contents of UIView as an OpenGL texture</a>, and  here is my version:</p>
  
  <pre><code>- (GLuint)createTexture:(UIView *)view
  {
      size_t width = CGRectGetWidth(view.layer.bounds) * [UIScreen mainScreen].scale;
      size_t height = CGRectGetHeight(view.layer.bounds) * [UIScreen mainScreen].scale;
  
      GLubyte * texturePixelBuffer = (GLubyte *) calloc(width * height * 4,
                                     sizeof(GLubyte));
  
      CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
      CGContextRef context = CGBitmapContextCreate(texturePixelBuffer,
                                                   width, height, 8, width*4, colorSpace, 
                                                   kCGImageAlphaPremultipliedLast | 
                                                   kCGBitmapByteOrder32Big);
      CGColorSpaceRelease(colorSpace);
  
      [view.layer renderInContext:context];
  
      CGContextRelease(context);
  
      GLuint texName;
      glGenTextures(1, &amp;texName);
      glBindTexture(GL_TEXTURE_2D, texName);
  
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  
      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, 
                   GL_UNSIGNED_BYTE, texturePixelBuffer);
  
      free(texturePixelBuffer);
      return texName;
  }
  </code></pre>