iPhone+Quartz+OpenGL. What is the correct way for Quartz and OpenGL to play nice together regarding
- by dugla
So we know the CoreGraphics/Quartz imaging model is based on pre-multiplied alpha. We also know that OpenGL blending is based on un-premultiplied alpha.
What is the best practice to avoid head explosion when doing blending with textures that are derived from pre-multiplied alpha imagery (PNG files generated in Photoshop with pre-multiplied alpha).
Given the apples/oranges mish mash of Quartz and OpenGL, what is the correct glBlendFunc for doing the fundamental Porter/Duff "over" operation?
Typical example:
A simple paint program. Brush shapes are texture-map patterns created from pre-multiplied alpha rgba images. Paint color is specified via glColor4(...) with the alpha channel used to control paint transparency. GL_MODULATE is used so the brush texture multiplies the (translucent) paint color to blend the color into the canvas.
Problem: The texture is premult. The color is not. What is the correct way to handle this fundamental inconsistency?
Thanks,
Doug