Skip to content

CoreySelover/Candle-SFML3

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

134 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Candle-SFML3

This is a port of Candle to SFML3. No additional work/modification/upgrades have been added other than getting the project to compile and run. It has been successfully integrated into an existing SFML3 project, but not all features have been tested.

The only major change to note, though it should not affect existing projects, is that with the deprecation and removal of sf::Quads as a Primitive Type for Vertex Arrays, LightingArea and DirectedLight have had their Vertex Arrays adjusted to use sf::PrimitiveType::Triangles instead. They should function the same, as far as the user is concerned.

The original ReadMe is below.

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 3

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • C++ 94.8%
  • Makefile 3.3%
  • CMake 1.9%