I’m trying to use either a solid color (white) or a texture as a mask for inverting pixels. What I’ve found is this post on Game Development Stack Exchange, and, while the blend mode works great for drawing polygons (the circle shown on the screenshot), it does not appear to work correctly for drawing textured rectangles such as text:
The funky rectangles on the above screenshot should be glyphs, but my glyph textures use unpremultiplied alpha (I use texture swizzling to convert a single-channel
GL_RED texture to
(1, 1, 1, alpha)), so modifying their color doesn’t quite work. I’d need to stuff a multiplication by the source alpha there somehow, but there is no way of doing that. If I make my font renderer use premultiplied alpha, then my alpha blending mode needs to change, and that seems to break image and transparent rectangle rendering, which uses unpremultiplied alpha.
My question here is, how do I make the blend mode work with textures? Is it even possible with fixed-function blend modes, or do I have to resort to shaders? If I have to use shaders and framebuffers, how can I achieve the correct result?