Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing a game and map editor using Java and jMonkeyEngine. In the map editor, I've got a brush done by wireframed sphere. My problem is: I want to make it visible everywhere, so I want to invert color of the pixel "behind" this brush. I wanted to do it with fragment shader (GLSL), but I don't know how to get color of this pixel.

share|improve this question
Does jMonkeyEngine support post-process effects? You'll probably have to go this way. – sam hocevar May 5 '12 at 10:41
Yeah, jMonkeyEngine supports post-process effects, but I'm not too familiar with them at this moment. Thanks for suggestion. – m4tx May 5 '12 at 11:10
Mmmh, nevermind, there are simpler ways. I'll try to answer properly. – sam hocevar May 5 '12 at 12:17
Can you use glLogicOp(GL_XOR)? – Adam May 5 '12 at 13:12
Note that inversion doesn't guarantee you visibility in a whole bunch of corner cases, like unsaturated grays, and provides poor visibility for many other cases. – Lars Viklund May 5 '12 at 16:13
up vote 11 down vote accepted

The quick and easy way to do this is to use the standard blending equation with the following parameters:


If src is the source colour (the one from your new object) and dst is the destination colour (the one which is in the framebuffer) it will compute the new colour as follows:

new = src * (1 - dst) + dst * 0
    = src * (1 - dst)

So you just need to set src = 1, ie. white, and you will get inverse video. The GLSL fragment shader will be:

void main(void) {
    gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
share|improve this answer
Sounds like you know your alpha blending! – bobobobo May 5 '12 at 16:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.