title: OpenGL ES 2.0 - Blending issue with text (iOS)
body: <p>I have grey shadows around texts when I blend them with OpenGL. </p>
  
  <p><a href="https://i.stack.imgur.com/uTpm9b.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uTpm9b.png" alt="enter image description here"></a></p>
  
  <p>Currently, this is my blending function :</p>
  
  <pre><code>glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  </code></pre>
  
  <p>If I change it to :</p>
  
  <pre><code>glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
  </code></pre>
  
  <p>It works, and I obtain the same result with Gimp :</p>
  
  <p><a href="https://i.stack.imgur.com/H2mdLb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H2mdLb.png" alt="enter image description here"></a></p>
  
  <p>But, however with GL_ONE, the text can't be faded into the background anymore. It's like it's either transparency 0 or 1.</p>
  
  <p>Also with GL_ONE, a crossfade between 2 pictures will somehow make the result image super bright :</p>
  
  <p><a href="https://i.stack.imgur.com/oCcXC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oCcXC.png" alt="enter image description here"></a></p>
  
  <p>Whereas with GL_SRC_ALPHA it looks normal :</p>
  
  <p><a href="https://i.stack.imgur.com/cU955m.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cU955m.png" alt="enter image description here"></a></p>
  
  <p>So both solutions have pros and cons. I don't want the grey shadows, but I want to keep the crossfade effect.. Any suggestions would be very appreciated.</p>
  
  <p>This is my fragment shader :</p>
  
  <pre><code>gl_FragColor = (v_Color * texture2D(u_Texture, v_TexCoordinate));
  </code></pre>
  
  <p>And here's how the textures (text and images) are loaded (premultiplied last):</p>
  
  <pre><code>+ (GLuint)getGLTextureFromCGIImage:(CGImageRef)cgiImage {
      size_t width = CGImageGetWidth(cgiImage);
      size_t height = CGImageGetHeight(cgiImage);
  
      GLubyte *spriteData = (GLubyte *) calloc(width * height * 4, sizeof(GLubyte));
      NSUInteger bytesPerPixel = 4;
      NSUInteger bytesPerRow = bytesPerPixel * width;
      NSUInteger bitsPerComponent = 8;
  
      CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
  
      CGContextRef spriteContext = CGBitmapContextCreate(spriteData,
                                                         width,
                                                         height,
                                                         bitsPerComponent,
                                                         bytesPerRow,
                                                         colorSpace,
                                                         kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
  
      CGColorSpaceRelease(colorSpace);
  
      CGContextDrawImage(spriteContext, CGRectMake(0, 0, width, height), cgiImage);
      CGContextRelease(spriteContext);
  
      return [GLMediaUtils getGLTextureFromPixelsInFormat:GL_RGBA
                                                    width:(int)width
                                                   height:(int)height
                                                   pixels:spriteData];
  }
  
  + (GLuint)getGLTextureFromPixelsInFormat:(GLenum)format
                                     width:(int)width
                                    height:(int)height
                                    pixels:(void *)pixels {
  
      glActiveTexture(GL_TEXTURE0);
  
      GLuint texture;
      glGenTextures(1, &amp;texture);
  
  
      glBindTexture(GL_TEXTURE_2D, texture);
  
  
      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);
  
  
      GLenum type = GL_UNSIGNED_BYTE;
      if(format == GL_RGB) // RGB565
          type = GL_UNSIGNED_SHORT_5_6_5;
  
      glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, type, pixels);
  
      free(pixels);
      glFlush();
  
      return texture;
  } 
  </code></pre>