View Full Version : invert pixels in the framebuffer

04-17-2010, 09:25 AM
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.

04-17-2010, 06:02 PM
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.

04-18-2010, 05:12 AM
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.

04-18-2010, 08:37 AM
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.

04-18-2010, 10:43 AM
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