Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Alpha blending issue




On Oct 20, 2007, at 1:58 PM, Red Marble Games wrote:

This is more a general OpenGL question, but it is for a Mac project, so I'm hopeful it is permissible here: I'm drawing a number of textures with alpha to context 1 using (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA), and in context 1 things look great. But then I'm using context 1 as a source texture for drawing to context 2, and am getting some artifacts where the original drawing in context 1 involved alpha values other than 1 or 0. I assume this is because, as the spec says, blending affects the alpha component of the destination pixels as well as the color components, so that when context 1 becomes a texture, it has non-1.0 alpha values in it. And indeed, if I turn off blending for the draw from context 1 -> context 2, everything is OK. But for a variety of reasons (I'm simplifying the situation to describe it here) I can't adopt that solution. So, my question is: once drawing into context 1 is complete, is there a way to force all of the alpha values in context 1 to be 1.0 before drawing it into context 2, so that it will draw correctly even with blending enabled?

What you are effectively winding up with in your context 1 destination buffer is what is known as "premultiplied alpha", where the color have already been multipled by alpha. If you multiply them by alpha again, things will look wrong.


Assuming that you want blending enabled in context 2 and you know you are texturing from a texture that came from context 1, you can try using a blend func of (GL_ONE, GL_ONE_MINUS_SRC_ALPHA).

This is what the WindowServer does when rendering window backing store textures which are also premultiplied.

-Ken

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Mac-opengl mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/mac-opengl/email@hidden

This email sent to email@hidden
References: 
 >Alpha blending issue (From: Red Marble Games <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.