In my game, I have a line class that is drawn on top of circles.The thing is, those circles have the same color as the line when highlighted, so it gets pretty difficult to distinguish them(impossible when the line is too small)
https://i.imgur.com/RZJviGv.png.I could just change the color of the line, but I think a blend mode(like
https://i.stack.imgur.com/LuWAA.png) would be the most future-proof way to visualize this line, as it overlaps other entities.
I've already read up on the docs
https://www.sfml-dev.org/documentation/2.4.2/structsf_1_1BlendMode.php but I'm still pretty much confused as to how I implement this specific blend mode.Actually, I think
I still don't understand sf::BlendMode at all.This was my attempt:
// Draw charges
for (auto s : chargeVector) {
mainWindow.draw(*s);
if (s->getIsCursorOn()) {
// Draw charge
mainWindow.draw(*s, &chargeHighlightShader);
// Draw velocity line
mainWindow.draw(
s->velocityLine(),
sf::BlendMode(sf::BlendMode::Zero,
sf::BlendMode::OneMinusDstColor,
sf::BlendMode::Add));
} else
mainWindow.draw(*s);
}
It's best if I give my current "understanding" of this code snippet, just so that you can clarify my misconceptions and better pinpoint the problem(s):
sf::BlendMode is just a part of the renderstate of the drawable object(in this case, a "Line") which is passed as an argument to it's draw() method.
The constructor I'm using takes three arguments:
- sourceFactor:In this case, it means how much a pixel of the line(src) affects the final output.This is set to zero, that is, the color and alpha of each pixel of the line is just being ignored.
- destinationFactor:In this case, it means how much a pixel of the current buffer(dst) affects the final output.This is set to vec4(1.0) - pixel.rgba, that is, it's colors are completely inverted, including the alpha.
- blendEquation:Determines how the src and dst values should be mixed.Set to add(pretty self-explanatory).
I guess the only problem I see is in the second argument, for which the alpha value is set to 1.0 - 1.0 = 0.0.But if that's the problem, how do I fix it?
Oh and this is what happens when I use my attempt:
https://i.imgur.com/RkSmcHS.png