Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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)? opengl.org/sdk/docs/man/xhtml/glLogicOp.xml –  Adam May 5 '12 at 13:12
1  
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

1 Answer 1

up vote 9 down vote accepted

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

glEnable(GL_BLEND);
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);

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
2  
Sounds like you know your alpha blending! –  bobobobo May 5 '12 at 16:29

Your Answer

 
discard

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.