1
Graphics / Re: Create a light effect with BlendMode?
« on: January 04, 2013, 05:02:03 pm »
Thanks for the reply! It really made things go forward. Though using sf::BlendAdd on the light and sf::BlendMultiply on the scene didn't work.
But I played around with it and came upp with this:
This works exactley like I want it to. Just one little problem...
The dark isn't that dark. In fact, it's white. My guess was that it was because of
_target.clear(sf::Color(255, 255, 255, 200)); that fill the render texture with a black color.
So I thought switching it to _target.clear(sf::Color(0, 0, 0, 200)); would give me the opposite effect.
But that made the whole render texture invisible!
What am I missing?
*Edit
Nevermind, I solved it
The light was the bad guy. It was also supposed to be black
I'll leave the code here if anyone is intrested.
Thanks for the help!
But I played around with it and came upp with this:
_light.setColor(sf::Color(0, 0, 0, 0));
_light.setPosition(static_cast<float>(mousePos.x), static_cast<float>(mousePos.y));
//_target is a sf::RenderTexture
_target.clear(sf::Color(255, 255, 255, 200));
_target.draw(_light, sf::BlendMultiply);
//_target.draw(_light, sf::BlendAdd);
_target.display();
_pWindow->clear(sf::Color(0, 150, 255, 255));
_pWindow->draw(_background);
_darkness.setTexture(_target.getTexture() );
_pWindow->draw(_darkness, sf::BlendAdd);
//_pWindow->draw(_darkness, sf::BlendMultiply);
_pWindow->display();
_light.setPosition(static_cast<float>(mousePos.x), static_cast<float>(mousePos.y));
//_target is a sf::RenderTexture
_target.clear(sf::Color(255, 255, 255, 200));
_target.draw(_light, sf::BlendMultiply);
//_target.draw(_light, sf::BlendAdd);
_target.display();
_pWindow->clear(sf::Color(0, 150, 255, 255));
_pWindow->draw(_background);
_darkness.setTexture(_target.getTexture() );
_pWindow->draw(_darkness, sf::BlendAdd);
//_pWindow->draw(_darkness, sf::BlendMultiply);
_pWindow->display();
This works exactley like I want it to. Just one little problem...
The dark isn't that dark. In fact, it's white. My guess was that it was because of
_target.clear(sf::Color(255, 255, 255, 200)); that fill the render texture with a black color.
So I thought switching it to _target.clear(sf::Color(0, 0, 0, 200)); would give me the opposite effect.
But that made the whole render texture invisible!
What am I missing?
*Edit
Nevermind, I solved it
The light was the bad guy. It was also supposed to be black
I'll leave the code here if anyone is intrested.
_light.setColor(sf::Color(255, 255, 255, 0));
_light.setPosition(static_cast<float>(mousePos.x), static_cast<float>(mousePos.y));
_target.clear(sf::Color(0, 0, 0, 200));
_target.draw(_light, sf::BlendNone);
_target.display();
_pWindow->clear(sf::Color(0, 150, 255, 255));
_pWindow->draw(_background);
_darkness.setTexture(_target.getTexture() );
_pWindow->draw(_darkness);
_pWindow->display();
_light.setPosition(static_cast<float>(mousePos.x), static_cast<float>(mousePos.y));
_target.clear(sf::Color(0, 0, 0, 200));
_target.draw(_light, sf::BlendNone);
_target.display();
_pWindow->clear(sf::Color(0, 150, 255, 255));
_pWindow->draw(_background);
_darkness.setTexture(_target.getTexture() );
_pWindow->draw(_darkness);
_pWindow->display();
Thanks for the help!