title: openGL ES textures from PNGs with transparency are being rendered with weird artifacts and driving me nuts!
body: <p>I am beginning to work on my first OpenGL iPhone app, but I've hit an early snag.</p>
  
  <p>I have a VERY SIMPLE little texture that I want to use as a sprite in a 2D game, but it renders with weird 'randomly' colored pixels up top.</p>
  
  <p><a href="http://i40.tinypic.com/2s7c9ro.png" rel="noreferrer">http://i40.tinypic.com/2s7c9ro.png</a> &lt;-- Screenshot here</p>
  
  <p>I sort of get the feeling that this is Photoshop's fault, so if anybody something about that please let me know.</p>
  
  <p>If it's not photoshop then it's gotta be my code... So here is the code in question...</p>
  
  <pre><code>- (void)loadTexture {
  
  CGImageRef textureImage = [UIImage imageNamed:@"zombie0.png"].CGImage;
  
  if (textureImage == nil) {
      NSLog(@"Failed to load texture image");
      return;
  }
  
  NSInteger texWidth = CGImageGetWidth(textureImage);
  NSInteger texHeight = CGImageGetHeight(textureImage);
  
  GLubyte *textureData = (GLubyte *)malloc(texWidth * texHeight * 4);
  
  CGContextRef textureContext = CGBitmapContextCreate(textureData, texWidth, texHeight, 8, texWidth * 4, CGImageGetColorSpace(textureImage), kCGImageAlphaPremultipliedLast);
  
  CGContextDrawImage(textureContext, CGRectMake(0.0, 0.0, (float)texWidth, (float)texHeight), textureImage);
  
  CGContextRelease(textureContext);
  
  glGenTextures(1, &amp;textures[0]);
  
  glBindTexture(GL_TEXTURE_2D, textures[0]);
  
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData);
  
  free(textureData);
  
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  
  glEnable(GL_TEXTURE_2D);
  
  glEnable(GL_BLEND);
  glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
  </code></pre>
  
  <p>}</p>
  
  <p>This blend function yielded the best results.</p>
  
  <p>Please, let me know what you think is wrong.</p>
  
  <p>Thank you very much, this problem has been driving me nuts.</p>