Texture in OpenGL ES 2 looks pixelated
(Aug 26, 2011 10:59 AM)vunterslaush Wrote: Screenshot
BTW, after second thoughts, I enlarged a bit the GL texture so it will be more similar to the image view version, and it does look pretty identical. except for that black outline sorta thing. How can I fix that?
Aha, you've hit another classic problem. Short version: Your texture appears to be using premultiplied alpha; use glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA) and the black halo should disappear.
Longer version: A bitmap image with premultiplied alpha has its R, G, and B components scaled by the A component, and has to be composited differently in order to be drawn without semi-transparent portions looking darker than they should. For example, 50% transparent red would be 0x7F00007F premultiplied, rather than 0xFF00007F unpremultiplied. This has some advantages, though; when pixels are interpolated due to image scaling, transparent color values mingle with opaque ones in a way that can cause black or white halos (depending on a few things) around edges in a nonpremultiplied image. Premultiplied images (when composited correctly) categorically avoid this problem, because the math works out correctly when transparent pixels blend with opaque ones.
There's more information about this scattered around the forum. Here's another thread about it: http://www.idevgames.com/forums/thread-966.html
As for why your pixels are premultiplied, I presume you're loading the texture with UIImage or some other Apple API? Apple's image loading functions will typically premultiply your data for you, though in some cases you can disable it. If you want to load the image without premultiplying, you can (maybe? haven't done it in a while) change the options you use to load the image, or use libpng directly.
(Aug 26, 2011 10:59 AM)vunterslaush Wrote: BTW, ThemsAllTook, thanks a lot for everything!!! You are helping me big time, I owe you!
It's my pleasure! I always enjoy helping someone who puts the proper effort into understanding things and formulating their questions as well as you have.
|Messages In This Thread|
RE: Texture in OpenGL ES 2 looks pixelated - ThemsAllTook - Aug 26, 2011 11:51 AM
Possibly Related Threads...
|OpenGL ES Texture Compression||ajrs84||9||2,505||
May 7, 2013 03:36 PM
Last Post: ajrs84
|OpenGL ES Texture Masking||airfire||5||12,818||
Nov 14, 2012 09:36 AM
Last Post: toanNguyen
|OpenGL ES Texture Masking||dalasjoe sin||0||3,494||
Apr 13, 2012 12:17 AM
Last Post: dalasjoe sin
|Lighting and changing texture colors in OpenGL||agreendev||2||6,912||
Aug 13, 2010 03:47 PM
Last Post: agreendev
|OpenGL ES Texture Problems||jhbau1000||1||4,831||
Jul 12, 2010 05:57 AM
Last Post: Kezhaya