Candle is a SFML based C++ library that provides light, shadow casting and field of view functionalities with easy integration.
Before anything, here you have a little example of how it looks.
The code comes with a demo program showing the functionalities provided by the library. In it you can place lights and edges that will cast shadows, and modify the behaviour of the fog.
You can check the full manual of the demo here.
You can build the static library and the demo program with CMake.
mkdir build && cd build
cmake .. -DBUILD_DEMO=ON
cmake --build .
This will generate libCandle-s.a
or (Candle-s.lib
on Windows) in build/lib
folder, and the demo
program (or demo.exe
) in build/bin
.
Alternatively, if you work in Linux, you can use make
, and also build the docs with it.
make
make docs # optional
This library is meant to be used in SFML applications, so it's assumed that you are familiar with the process of compiling them. If you are not, you can learn in the official website .
Thanks to the people that have contributed to this project: (emoji key)
Modar Nasser π π π |
nightroy99 π π |
Lukas DΓΌrrenberger π |
Tim Stoddard π» π β οΈ |
Dead-Deus π π |
GuillaumeG. π β οΈ π» π€ |
This project follows the all-contributors specification.
I will assume that you have SFML installed in your system. If we have a project with the following structure:
|- project
|- libCandle-s.a
|- main.cpp
|- include
|- Candle
|- Candle.hpp
|- ... # Candle headers
the main.cpp
file could look like this:
#include <SFML/Graphics.hpp>
#include "Candle/RadialLight.hpp"
int main(){
// create window
sf::RenderWindow w(sf::VideoMode(400, 400), "app");
// create a light source
candle::RadialLight light;
light.setRange(150);
// create an edge pool
candle::EdgeVector edges;
edges.emplace_back(sf::Vector2f(200.f, 100.f),
sf::Vector2f(200.f, 300.f));
// main loop
while(w.isOpen()){
sf::Event e;
while(w.pollEvent(e)){
if(e.type == sf::Event::Closed){
w.close();
}else if(e.type == sf::Event::MouseMoved){
sf::Vector2f mp(sf::Mouse::getPosition(w));
light.setPosition(mp);
light.castLight(edges.begin(), edges.end());
}
}
w.clear();
w.draw(light);
w.display();
}
return 0;
}
We can compile it with the following command:
g++ -o app main.cpp -Iinclude -L. -lCandle-s -lsfml-graphics -lsfml-window -lsfml-system
And we run it
./app
The result will be a simple light casting a shadow over an invisible wall in the center of the window.
Candle uses the MIT license, a copy of which you can find here, in the repo.
It uses the external library SFML, that is licensed under the zlib/png license.