views:

39

answers:

4

Hello,

I have a font texture which I use in order to draw text on top of my OpenGL scene. The problem is that the scene's colors vary so much that any solid color I use is hard to read. Is it possible to draw my font texture with inverted colors?

A call to glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); would just draw it with a solid color, A call to glBlendFunc(GL_ONE_MINUS_DEST_COLOR, GL_ZERO); would draw it inverted, but would disregard the alpha values of the texture so you'd just see an inverted rectangle instead of the letters.

What I need is something equivalent to glBlendFunc(GL_SRC_ALPHA * GL_ONE_MINUS_DEST_COLOR, GL_ONE_MINUS_SRC_ALPHA);

Can this be achieved somehow without using shaders ?

Thanks.

A: 

Copy the subsection of the screen you want to overwrite, you can use the CPU to invert this copied portion. Draw your newly made inverted texture to the screen using the text as a mask.

Note that this is slow, there's no doubt that shaders would be much faster.

Hannesh
A: 

Does glLogicOp( GL_OR_REVERSE ) does what you want?

eile
A: 

glLogicOp(GL_INVERT) almost does what I want, but it disregards alpha values. (It just draws an inverted polygon)

I've seen some calls to glBlendEquationEXT(GL_LOGIC_OP); but I'm working with OpenGL-ES where this call in not available.

Any ideas?

A: 

Problem solved.

Following dave's comment to my original post: Instead of using a GL_ALPHA texture I generate a GL_RGBA texture where each pixel is equal: (alpha, alpha, alpha, 0xff) (this is a greyscale image instead of a luminance image). Then I use this texture with:

glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_SRC_COLOR);

The result is: (1 - dest_color) x "src_alpha" + dest_color x (1 - "src_alpha") which is exactly what I needed.

Thank you! Ron