I include all source to my project who are needed
#include <LTBL/Light/LightSystem.h>
#include <LTBL/Light/Light_Point.h>
#include <LTBL/Utils.h>
#include <assert.h>
#include <SFML/Graphics.hpp>
int main(int argc, char* args[])
{
sf::VideoMode vidMode;
vidMode.width = 800;
vidMode.height = 600;
vidMode.bitsPerPixel = 32;
assert(vidMode.isValid());
sf::RenderWindow win;
win.create(vidMode, "Let there be Light - Demo");
// ---------------------- Background Image ---------------------
sf::Texture backgroundImage;
assert(backgroundImage.loadFromFile("data/background.png"));
// Tiling background
backgroundImage.setRepeated(true);
sf::Sprite backgroundSprite(backgroundImage);
backgroundSprite.setTextureRect(sf::IntRect(0, 0, vidMode.width, vidMode.height));
// --------------------- Light System Setup ---------------------
ltbl::LightSystem ls(AABB(Vec2f(0.0f, 0.0f), Vec2f(static_cast<float>(vidMode.width), static_cast<float>(vidMode.height))), &win, "data/lightFin.png", "data/shaders/lightAttenuationShader.frag");
// Create a light
/*ltbl::Light* testLight = new ltbl::Light();
testLight->m_center = Vec2f(200.0f, 200.0f);
testLight->m_radius = 500.0f;
testLight->m_size = 30.0f;
//testLight->m_spreadAngle = 2.0f * static_cast<float>(M_PI);
//testLight->m_softSpreadAngle = 0.0f;
testLight->CalculateAABB();*/
ltbl::Light_Point * testLight = new ltbl::Light_Point();
ls.AddLight(testLight);
// Create a hull by loading it from a file
ltbl::ConvexHull* testHull = new ltbl::ConvexHull();
if(!testHull->LoadShape("data/testShape.txt"))
abort();
// Pre-calculate certain aspects
testHull->CalculateNormals();
testHull->CalculateAABB();
testHull->SetWorldCenter(Vec2f(300.0f, 300.0f));
ls.AddConvexHull(testHull);
// ------------------------- Game Loop --------------------------
sf::Event eventStructure;
bool quit = false;
while(!quit)
{
while(win.pollEvent(eventStructure))
if(eventStructure.type == sf::Event::Closed)
{
quit = true;
break;
}
sf::Vector2i mousePos = sf::Mouse::getPosition(win);
// Update light
testLight->SetCenter(Vec2f(static_cast<float>(mousePos.x), static_cast<float>(vidMode.height - mousePos.y)));
win.clear();
// Draw the background
win.draw(backgroundSprite);
ls.RenderLights();
ls.RenderLightTexture();
win.display();
}
win.close();
}