title: How do I blit pixel data to the screen using OpenGL ES?
body: <p>I'm currently learning OpenGL ES for iPhone and I'm wondering how to take an array of RGB pixel data and blit it to the screen, so far all the tutorials I've found cover loading a pre-existing image into a texture and displaying it.</p>
  
  <p>Here's how I've accomplished it using Core Graphics by creating an imageref then using a UIImage and UIImageView:</p>
  
  <pre><code>int screenWidth = (int)[[UIScreen mainScreen] bounds].size.width;
  int screenHeight = (int)[[UIScreen mainScreen] bounds].size.height;
  
  //Create blank image
  CGImageRef blankImageRef = [self createBlankImageRef];
  CFDataRef m_DataRef; 
  m_DataRef = CGDataProviderCopyData(CGImageGetDataProvider(blankImageRef)); 
  UInt8* bufferData = CFDataGetBytePtr(m_DataRef); 
  
  
  //Manipulate the image here
  for(int x=0; x &lt; screenWidth-1; x++)
  {
      int y = x;//*2;
  
      [self setPixel:bufferData width:screenWidth x:x y:y r:255 g:0 b:0];
  }
  
  
  //Paint the image to the screen
  CGImageRef imageRef = blankImageRef; 
  CGContextRef ctx; 
  ctx = CGBitmapContextCreate(bufferData, 
                              CGImageGetWidth( imageRef ), 
                              CGImageGetHeight( imageRef ), 
                              8, 
                              CGImageGetBytesPerRow( imageRef ), 
                              CGImageGetColorSpace( imageRef ), 
                              kCGImageAlphaPremultipliedLast ); 
  screenImage = [UIImage imageWithCGImage:CGBitmapContextCreateImage (ctx)]; 
  CGContextRelease(ctx); 
  
  [imageView setImage:screenImage];
  
  free(bufferData);
  </code></pre>
  
  <p>...</p>
  
  <pre><code>- (CGImageRef) createBlankImageRef
  {
  CGFloat imageScale = (CGFloat)1.0;
  CGFloat width = [[UIScreen mainScreen] bounds].size.width;
  CGFloat height = [[UIScreen mainScreen] bounds].size.height;
  
  // Create a bitmap graphics context of the given size
  CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
  CGContextRef context = CGBitmapContextCreate(NULL, width * imageScale, height * imageScale, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast);
  
  // Draw ...
  CGContextSetRGBFillColor(context, (CGFloat)0.0, (CGFloat)0.0, (CGFloat)0.0, (CGFloat)1.0 );
  
  // Get your image
  CGImageRef cgImage = CGBitmapContextCreateImage(context);
  
  CGColorSpaceRelease(colorSpace);
  CGContextRelease(context);
  
  return cgImage;
  }
  
  -(void)setPixel:(UInt8*)buffer width:(int)width x:(int)x y:(int)y r:(int)r g:(int)g b:(int)b
  {
  buffer[x*4 + y*(width*4)] = r;
  buffer[x*4 + y*(width*4)+1] = g;
  buffer[x*4 + y*(width*4)+2] = b;
  buffer[x*4 + y*(width*4)+3] = 255;
  }
  </code></pre>
  
  <p>Any ideas how I could accomplish this using OpenGL ES (currently using 1.0) instead of Core Graphics? </p>