OpenGL ES 2.0, 2D Alpha Transparency Artifacts - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: OpenGL ES 2.0, 2D Alpha Transparency Artifacts (/thread-206.html)
OpenGL ES 2.0, 2D Alpha Transparency Artifacts - Macmenace - Mar 28, 2010 07:39 PM
At the moment I'm rendering 2D sprites with an orthographic projection on top of my 3D scene.
The problem is if I draw two sprites on top of each other the alpha channel color does not blend with the sprite drawn beneath it.
Here is a screenshot as an example:
The same problem is happening with my 3D particle system which uses point sprites.
This is the current blending function I'm using, which works with my purely 2D Open GL ES 1.0 projects:
Also, I'm loading my PNG's like Apple does in a few samples:
Any help would be greatly appreciated.
OpenGL ES 2.0, 2D Alpha Transparency Artifacts - AnotherJake - Mar 28, 2010 09:44 PM
A couple ideas:
Try glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA );
That screenshot suggests to me that you might have depth testing on. If that is the case, you will need to sort and draw your translucent sprites from back to front, after you've drawn your opaque objects. Otherwise, depending on what you're doing (e.g. for your 2D sprites over your 3D scene), you could probably just glDisable(GL_DEPTH_TEST) and not worry about sorting.
OpenGL ES 2.0, 2D Alpha Transparency Artifacts - Macmenace - Mar 28, 2010 11:05 PM
AnotherJake Wrote:A couple ideas:
Thank you so much! It wasn't the blending function but you were spot on with the depth testing. All of my 2D sprites are sorted but they all lie at the same "z-distance" from my camera so depth testing would cause some of them not to draw.
All, I had to do was glDisable(GL_DEPTH_TEST) before entering my orthographic rendering.
OpenGL ES 2.0, 2D Alpha Transparency Artifacts - AnotherJake - Mar 28, 2010 11:18 PM
Aha! Right on. Always glad to help.