Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenGL ES (IPhone) alpha blending looks weird
    primarykey
    data
    text
    <p>I'm writing a game for IPhone in Opengl ES, and I'm experiencing a problem with alpha blending:</p> <p>I'm using <code>glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA)</code> to achieve alpha blending and trying to compose a scene with several "layers" so I can move them separately instead of having a static image. I created a preview in photoshop and then tried to achieve the same result in the iphone, but a black halo is shown when I blend a texture with semi-transparent regions.</p> <p>I attached an image. In the left is the screenshot from the iphone, and in the right is what it looks like when I make the composition in photoshop. The image is composed by a gradient and a sand image with feathered edges.</p> <p>Is this the expected behaviour? Is there any way I can avoid the dark borders?</p> <p>Thanks.</p> <p><strong>EDIT</strong>: I'm uploading the portion of the png containing the sand. The complete png is 512x512 and has other images too.</p> <p>I'm loading the image using the following code:</p> <pre><code>NSString *path = [NSString stringWithUTF8String:filePath]; NSData *texData = [[NSData alloc] initWithContentsOfFile:path]; UIImage *image = [[UIImage alloc] initWithData:texData]; if (image == nil) NSLog(@"ERROR LOADING TEXTURE IMAGE"); GLuint width = CGImageGetWidth(image.CGImage); GLuint height = CGImageGetHeight(image.CGImage); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); void *imageData = malloc( height * width * 4 ); CGContextRef context = CGBitmapContextCreate( imageData, width, height, 8, 4 * width, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big ); CGColorSpaceRelease( colorSpace ); CGContextClearRect( context, CGRectMake( 0, 0, width, height ) ); CGContextTranslateCTM( context, 0, height - height ); CGContextDrawImage( context, CGRectMake( 0, 0, width, height ), image.CGImage ); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData); CGContextRelease(context); free(imageData); [image release]; [texData release]; </code></pre> <hr> <p><img src="https://i.stack.imgur.com/bPGwB.png" alt="alt text"> <img src="https://i.stack.imgur.com/Ig0GR.png" alt="alt text"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload