invert pixels in the framebuffer

I was wondering was the best way to invert the color pixels in the frame buffer is. I’ve done it with glReadPixels() and glDrawPixels() but the performance hit of those calls is pretty big.

Basically, what I’m trying to do is have an inverted color cross-hair, so it’s always visible no matter what’s behind it. For instance, I’d have an arbitrary alpha mask bitmap or texture, have it render without depth test after the scene is drawn, and all the frame buffer pixels under the masked pixels of the texture would be inverted.

I’ve been trying to do this with a texture, but I’m getting some strange results, also all the blending options I still find confusing.

Render your scene not including your crosshair to an FBO and use that texture to render to the back of your window. Now render the geometry of the crosshair using the background texture as a color lookup and invert it in the shader. (1 - textureColor). You can use a second texture for an alpha mask.

strattonbrazil provides a good suggestion.

But “an inverted color cross-hair, so it’s always visible no matter what’s behind it” is not true for 50% gray.

That’s a good point. One thing I do a lot on my Java guis when drawing text is to draw the text in black and draw it again in white one or two pixels off. Or vice versa, and this usually provides good enough contrast for whatever I’m looking at.

I had never considered that the inversion of 50% gray is itself, good catch!

I managed to do the inversion by just drawing my cross as a shape and then using glLogicOp(). It worked well, but obviously suffered the 50% gray problem :s