Dear,
First of all, thank you so much for sharing your code and hard work!
I would like to ask a question though, which has been asked before.
I do everything stated in the documentation, but no light seems to appear when I run my application.
I have an easy test project setup so I'll post the code I'm using at the moment.
This is the initialization of everything.
Game::Game() :
window(), ls(), unshadowShader(), lightOverShapeShader(), view()
{
sf::ContextSettings settings = sf::ContextSettings();
settings.antialiasingLevel = 8;
window.create(sf::VideoMode(windowWidth, windowHeight), "Test game", sf::Style::Default, settings);
sf::Vector2u windowSize(window.getSize());
view.setSize(sf::Vector2f(static_cast<float>(windowSize.x), static_cast<float>(windowSize.y)));
view.setCenter(view.getSize() / 2.0f);
unshadowShader.loadFromFile("resources/unshadowShader.vert", "resources/unshadowShader.frag");
lightOverShapeShader.loadFromFile("resources/lightOverShapeShader.vert", "resources/lightOverShapeShader.frag");
sf::Texture penumbraTexture;
penumbraTexture.loadFromFile("resources/penumbraTexture.png");
penumbraTexture.setSmooth(true);
//ltbl::LightSystem ls;
ls.create(sf::FloatRect(-1000.0f, -1000.0f, 1000.0f, 1000.0f), window.getSize(), penumbraTexture, unshadowShader, lightOverShapeShader);
std::shared_ptr<ltbl::LightPointEmission> pointLight = std::make_shared<ltbl::LightPointEmission>();
pointLight->_emissionSprite.setOrigin(0, 0);
sf::Texture pointTexture;
pointTexture.loadFromFile("resources/pointLightTexture.png");
pointTexture.setSmooth(true);
pointLight->_emissionSprite.setTexture(pointTexture, true);
pointLight->_emissionSprite.setColor(sf::Color::Cyan);
pointLight->_emissionSprite.setPosition(50, 50);
pointLight->_localCastCenter = sf::Vector2f(70.f, 70.f); // This is where the shadows emanate from relative to the sprite
std::shared_ptr<ltbl::LightDirectionEmission> directionLight = std::make_shared<ltbl::LightDirectionEmission>();
sf::Texture directionTexture;
directionTexture.loadFromFile("resources/directionLightTexture.png");
directionTexture.setSmooth(true);
directionLight->_emissionSprite.setTexture(directionTexture);
directionLight->_castDirection = sf::Vector2f(200.f, 200.f);
std::shared_ptr<ltbl::LightShape> lightShape = std::make_shared<ltbl::LightShape>();
lightShape->_shape.setPointCount(3);
const int arraySize = 4;
sf::Vector2f fixedPoints[arraySize] = { sf::Vector2f(0.f, 0.f), sf::Vector2f(0.f, 0.f), sf::Vector2f(0.f, 0.f), sf::Vector2f(0.f, 0.f) };
fixedPoints[0] = sf::Vector2f(20.f, 20.f);
fixedPoints[1] = sf::Vector2f(20.f, 30.f);
fixedPoints[2] = sf::Vector2f(25.f, 40.f);
fixedPoints[3] = sf::Vector2f(50.f, 30.f);
for (int j = 0; j < arraySize - 1; j++)
lightShape->_shape.setPoint(j, fixedPoints[j]);
lightShape->_shape.setPosition(100.f, 100.f);
ls.addShape(lightShape);
ls.addLight(directionLight);
ls.addLight(pointLight);
}
The lights should be rendered here:
void Game::render()
{
window.clear();
window.setView(view);
ls.render(view, unshadowShader, lightOverShapeShader);
//window.draw();
window.display();
}
I am looking forward to your answer!
Thanks in advance.