#include <SFML/Graphics.hpp>
int main() {
sf::RenderWindow window(sf::VideoMode(1280,720), "Moon", sf::Style::Default);
window.setFramerateLimit(60);
sf::RenderTexture drawBuffer;
sf::Sprite buffer;
sf::RenderTexture drawBuffer2;
sf::Sprite buffer2;
///Lights
sf::Texture lightSheet;
sf::Sprite light;
lightSheet.loadFromFile("lights.png");
light.setTexture(lightSheet);
light.setTextureRect({0,0,300,300});
drawBuffer.create(1280,720);
buffer.setTexture(drawBuffer.getTexture());
drawBuffer2.create(1280,720);
buffer2.setTexture(drawBuffer2.getTexture());
buffer2.setColor(sf::Color(80,50,50));
sf::Vector2u mouse;
while( window.isOpen() ) {
sf::Event event;
while( window.pollEvent( event ) ) {
if (event.type == sf::Event::Closed) { window.close(); }
if (event.type == sf::Event::MouseMoved) {
mouse = {event.mouseMove.x, event.mouseMove.y};
}
}
window.clear(sf::Color::Green);
///Draw game scene/map/entities/objects here
///....
///....
///Draw Lights here
///Clear renderTextures
drawBuffer.clear(sf::Color(0,0,0));
///For each Light, draw with additive blendmode
light.setPosition(mouse.x,mouse.y);
drawBuffer.draw(light, sf::BlendMode::BlendAdd);
///For each blocking light, simply draw the sprite
//drawBuffer.draw(light);
///Draw the first framebuffer
drawBuffer.display(); ///y u flip y axis
///Clear framebuffer
drawBuffer2.clear(sf::Color(50,50,50));
///Draw the light sprite to the second framebuffer
drawBuffer2.draw(buffer, sf::BlendMode::BlendAdd);
drawBuffer2.display(); ///flip flip
///Finally, draw the finished frame to the main window, using BlendMultiply so it overlays onto the main scene.
window.draw(buffer2, sf::BlendMode::BlendMultiply);
window.display();
}
return 0;
}