I'm trying to spawn a light for testing purposes, but i'm just seeing a hard rectangle shape instead of a smooth light. The rectangle is the same color as the light is supposed to be, but i only see the rectangle if i clear with white instead of standard black clear color.
This is the code i'm using:
#include <memory>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <ltbl/lighting/lightSystem.h>
using namespace std;
int main(){
sf::ContextSettings Settings;
Settings.depthBits = 24; // Request a 24 bits depth buffer
Settings.stencilBits = 8; // Request a 8 bits stencil buffer
Settings.antialiasingLevel = 0; // Request 2 levels of antialiasing
// Set Screen Size
sf::Vector2<double> screenSize;
screenSize.x = 1000;
screenSize.y = 800;
//Create the Window
sf::RenderWindow App(sf::VideoMode(screenSize.x, screenSize.y, 32), "Test LTBL2", sf::Style::Close, Settings);
//Frame Limit
App.setFramerateLimit(0);
//Vertical sync
App.setVerticalSyncEnabled(true);
// lights setup
sf::Texture pointLightTexture;
if (!pointLightTexture.loadFromFile("resources/directionLightTexture.png"));
pointLightTexture.setSmooth(true);
sf::Texture penumbraTexture;
if (!penumbraTexture.loadFromFile("resources/penumbraTexture.png"));
penumbraTexture.setSmooth(true);
ltbl::LightSystem ls;
sf::Shader unshadowShader;
sf::Shader lightOverShapeShader;
if (!unshadowShader.loadFromFile("resources/unshadowShader.vert", "resources/unshadowShader.frag"));
if (!lightOverShapeShader.loadFromFile("resources/lightOverShapeShader.vert", "resources/lightOverShapeShader.frag"));
ls.create(ltbl::rectFromBounds(sf::Vector2f(-1000.0f, -1000.0f), sf::Vector2f(1000.0f, 1000.0f)), App.getSize(), penumbraTexture, unshadowShader, lightOverShapeShader);
std::shared_ptr<ltbl::LightPointEmission> light = std::make_shared<ltbl::LightPointEmission>();
light->_emissionSprite.setOrigin(sf::Vector2f(pointLightTexture.getSize().x * 0.5f, pointLightTexture.getSize().y * 0.5f));
light->_emissionSprite.setTexture(pointLightTexture);
light->_emissionSprite.setScale(sf::Vector2f(1.0f, 1.0f));
light->_emissionSprite.setColor(sf::Color(255, 230, 200));
light->_emissionSprite.setPosition(sf::Vector2f(500, 400));
ls.addLight(light);
while (App.isOpen()){
sf::Event Event;
while (App.pollEvent(Event)){
// Window closed
if (Event.type == sf::Event::Closed){
App.close();
}
// Key Pressed
if (Event.type == sf::Event::KeyPressed){
//Quit
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)){
App.close();
}
}
if (Event.type == sf::Event::KeyReleased){
}
}
App.clear(sf::Color(255,255,255));
ls.render(App.getDefaultView(), unshadowShader, lightOverShapeShader);
sf::Sprite sprite;
sprite.setTexture(ls.getLightingTexture());
sf::RenderStates lightRenderStates;
lightRenderStates.blendMode = sf::BlendMultiply;
App.draw(sprite, lightRenderStates);
App.display();
}
return 0;
}