Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Lights with blending, doing something wrong.  (Read 1761 times)

0 Members and 1 Guest are viewing this topic.

Moonkis

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Lights with blending, doing something wrong.
« on: January 23, 2014, 12:38:54 pm »
I'm trying to implement some basic light using blending. It's based of this https://dl.dropboxusercontent.com/u/36451301/ld/ld27/index.html


I'm trying to implement it by doing it in a few small steps:
Quote
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;
}
 

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Lights with blending, doing something wrong.
« Reply #1 on: January 23, 2014, 12:43:53 pm »
Try calling display on render texture before drawing it to window.
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Lights with blending, doing something wrong.
« Reply #2 on: January 23, 2014, 01:03:33 pm »
Your light is pure red. The lit environment is pure blue. Even in real life the result would be black ;)
Laurent Gomila - SFML developer

 

anything