I'm trying to implement some basic light using blending. It's based of this
https://dl.dropboxusercontent.com/u/36451301/ld/ld27/index.htmlI'm trying to implement it by doing it in a few small steps:
You must do it this way:
- fill a render-texture (which covers the whole window) with the dark color
- draw your light(s) to the render-texture with sf::BlendAdd
- draw the render-texture on top of your scene with sf::BlendMultiply
but for some reason the only thing I get is an completely black screen, I'm not sure what exactly I'm doing wrong. If I use Multiply when drawing the lightmap-buffer it litterly only shows black.
Here is a minimal code example:
int main()
{
sf::Sprite s_lightmap;
sf::Sprite s_light;
sf::RenderTexture t_lightmap;
sf::Texture t_light;
t_lightmap.create(800,600);
t_light.loadFromFile("light.png");
sf::Color ambient(0,0,0,255);
sf::Color lightColor(255,0,0,178);
s_light.setTexture(t_light);
s_light.setColor(lightColor);
sf::RenderWindow window(sf::VideoMode(800,600,32),"Window");
sf::Event event;
while(window.isOpen())
{
while(window.pollEvent(event))
{
}
window.clear(sf::Color::Blue);
t_lightmap.clear(ambient);
t_lightmap.draw(s_light, sf::BlendMode::BlendAdd);
s_lightmap.setTexture(t_lightmap.getTexture());
window.draw(s_lightmap, sf::BlendMode::BlendMultiply);
window.display();
}
return 0;
}