MiguelMJ / Candle

2D lighting for SFML

Home Page:http://www.miguelmj.dev/Candle/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

logo

Candle

2D lighting for SFML

Candle is a SFML based C++ library that provides light, shadow casting and field of view functionalities with easy integration.

Official documentation.

Contents

Demo

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.

Build

CMake

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.

Make

Alternatively, if you work in Linux, you can use make, and also build the docs with it.

make
make docs # optional	

Requisites

  • SFML v2.5.1
    • Graphics module and System module.

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 .

  • If you want to build the docs, Doxygen 1.9.1 is required.

Contributors

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.

Contributing

  • Read the contributing guidelines if you want to contribute to the code.
  • Open a new issue (issues) to make a request or report a bug.
  • Alternatively, comment it on the SFML forum
  • If you use it in a project, you don't have to give any credit. But if you did so, that would be fantastic!
  • And of course, ⭐ star this repository and give it some visibility (stargazers).

Example program

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.

License

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.

About

2D lighting for SFML

http://www.miguelmj.dev/Candle/

License:MIT License


Languages

Language:C++ 94.6%Language:Makefile 3.4%Language:CMake 2.0%