I’m using this typical code for rubber band selection:
glEnable(GL_COLOR_LOGIC_OP);
glLogicOp(GL_XOR);
// draw rect
glDisable(GL_COLOR_LOGIC_OP);
glLogicOp(GL_COPY);
And it works ok for everything except a middle gray background (128,128,128), as the inverse of gray is also gray,
so the selection lines turn invisible.
I was just wondering if there’s some kind of hack to fix this case, aside from not using a gray background.
The easiest solution is to use #808080 as the band colour rather than #fffffff. That way, the difference between the modified value and the original will always be +/- 128 rather than varying between +/-1 and +/-255.
A shader can’t read from the framebuffer which is being modified, so to use a shader you’d need to either render into a texture (glFramebufferTexture() etc) or copy the framebuffer contents to a texture (glCopyTex[Sub]Image2D()).
I can take your idea further, and dynamically change the band color depending on the background color set by the user.
So, if the background color is gray, I can set the band color to (128,128,128), otherwise I can leave the band color to all white (255,255,255).
However, even though a gray band color works well on a gray background, it doesn’t seem to work well when there are other colors there too, like red. The selection line disappears right through a red box. Oh well.
That’s fine provided that you only need the band to be visible against the background. If it needs to be visible against any colour, then (128,128,128) is the best you can get in terms of the difference vector.
[QUOTE=sevenfold;1282591]
However, even though a gray band color works well on a gray background, it doesn’t seem to work well when there are other colors there too, like red. The selection line disappears right through a red box. Oh well.[/QUOTE]
Check that the values are reproduced exactly; (127,127,127) is no better than white. OpenGL mostly tries to treat colour components as real numbers in the range 0…1, but for logic ops the bit pattern matters. If you’re using a 5:5:5 or 5:6:5 framebuffer, it’s possible that the values might not get converted correctly.