SFMLight is a simple to use library that can be used to add lighting to your 2D game.
These steps will show you how to build SFMLight on your machine.
This project uses:
First, get the SFMLight source code
git clone https://github.com/dfranx/SFMLight.git SFMLight
cd SFMLight
Then build it
cmake .
make
If you get error message which says that SFML was not found on your computer you need to specify SFML_ROOT variable in your cmake command:
cmake -DSFML_ROOT=path/to/your/sfml .
Include the library
#include <SFMLight.h>
Declare a LightScene
sfl::LightScene scene;
scene.SetDebugDraw(true); // just for debugging
Declare an object/obstacle and define it's boundaries
sfl::Object obj;
obj.Add(50, 50);
obj.Add(100, 50);
obj.Add(100, 100);
obj.Add(50, 100);
Add the object to the scene
scene.Add(obj);
Create a light and define some of its properties (radius and position)
sfl::Light light;
light.SetRadius(300);
light.SetPosition(sf::Vector2f(150, 150));
Update light's vertices
scene.Update(light);
Render everything
light.Render(window);
scene.Render(window);
Result:
This project is licensed under the MIT License - see the LICENSE.md file for details