Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML Light System - Let There Be Light  (Read 230449 times)

0 Members and 1 Guest are viewing this topic.

Theshooter7

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #330 on: May 06, 2014, 04:27:28 am »
I guess the shadow fin is for the shadow part only, i was unsure what to call the dark area, but basically i want everything brighter, not just the shadow. I see in your screenshots it's not entirely black.

Basically m_ambientColor doesn't work at all with bloom turned off for me.
Oh. Yeah I have bloom enabled and m_ambientColor doesn't work for me with it off either. :/

Voroz

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #331 on: May 06, 2014, 05:51:05 am »
I guess the shadow fin is for the shadow part only, i was unsure what to call the dark area, but basically i want everything brighter, not just the shadow. I see in your screenshots it's not entirely black.

Basically m_ambientColor doesn't work at all with bloom turned off for me.
Oh. Yeah I have bloom enabled and m_ambientColor doesn't work for me with it off either. :/
Well i fixed it :).
In the parts where it says:
glBegin(GL_QUADS);
                        glVertex2f(0.0f, 0.0f);
                        glVertex2f(width, 0.0f);
                        glVertex2f(width, height);
                        glVertex2f(0.0f, height);
                glEnd();
in the lightsystem.cpp file, comment all that out. Then it works fine. He is clearing 2 times. First normally and then with the clearing shown above.

Theshooter7

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #332 on: May 06, 2014, 06:57:23 am »
Well i fixed it :).
In the parts where it says:
glBegin(GL_QUADS);
                        glVertex2f(0.0f, 0.0f);
                        glVertex2f(width, 0.0f);
                        glVertex2f(width, height);
                        glVertex2f(0.0f, height);
                glEnd();
in the lightsystem.cpp file, comment all that out. Then it works fine. He is clearing 2 times. First normally and then with the clearing shown above.
Exact lines? There are several instances where this shows up. But good job!

[EDIT] Ok took another swing at the problem I'm having (didn't realize you could setActive() a render texture so that's a step forward), but I get odd results; the play area comes up pure white and the sky comes out gray. This is the code I've got:
Code: [Select]
sf::RenderTexture rt1, rt2;
        rt1.create(app->GetWindow()->getSize().x, app->GetWindow()->getSize().y);
        rt2.create(app->GetWindow()->getSize().x, app->GetWindow()->getSize().y);

                        /* ... */

                //app->GetWindow()->draw(app->GetBackdrop());
rt1.setActive();
rt1.clear();
rt1.draw(app->GetBackdrop());
world->GetBackgroundLightSystem()->RenderLights();
world->GetBackgroundLightSystem()->RenderLightTexture();
rt1.display();
sf::Sprite tempsprite1(rt1.getTexture());

//app->GetWindow()->draw(*world->GetLevel());
rt2.setActive();
rt2.clear();
rt2.draw(*world->GetLevel());
world->GetLightSystem()->RenderLights();
world->GetLightSystem()->RenderLightTexture();
rt2.display();
sf::Sprite tempsprite2(rt2.getTexture());

app->GetWindow()->setActive();

app->GetWindow()->draw(tempsprite1);
app->GetWindow()->draw(tempsprite2);

app->GetWindow()->display();

[EDIT 2] this code just gets me black render textures, as if nothing is being drawn to them for some reason.

Code: [Select]
//app->GetWindow()->draw(app->GetBackdrop());
rt1.setActive();
rt1.clear();
//rt1.draw(app->GetBackdrop());
world->GetBackgroundLightSystem()->RenderLights();
rt1.setActive();
world->GetBackgroundLightSystem()->RenderLightTexture();
rt1.resetGLStates();
rt1.display();
sf::Sprite tempsprite1(rt1.getTexture());

//app->GetWindow()->draw(*world->GetLevel());
rt2.setActive();
rt2.clear();
//rt2.draw(*world->GetLevel());
world->GetLightSystem()->RenderLights();
rt2.setActive();
world->GetLightSystem()->RenderLightTexture();
rt2.resetGLStates();
rt2.display();
sf::Sprite tempsprite2(rt2.getTexture());

app->GetWindow()->setActive();

app->GetWindow()->draw(app->GetBackdrop());
app->GetWindow()->draw(tempsprite1);
app->GetWindow()->draw(*world->GetLevel());
app->GetWindow()->draw(tempsprite2);

app->GetWindow()->display();
}
« Last Edit: May 06, 2014, 08:02:48 am by Theshooter7 »

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #333 on: May 07, 2014, 02:21:10 am »
Wonder if this was ever ported to C#?  If so it would be nice to use. :)
I have many ideas but need the help of others to find way to make use of them.

Estivo

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Re: SFML Light System - Let There Be Light
« Reply #334 on: May 08, 2014, 11:23:03 pm »
        void LightSystem::RenderLights()
        {
                // So will switch to main render textures from SFML projection
                m_currentRenderTexture = cur_lightStatic;

                Vec2f viewCenter(m_viewAABB.GetCenter());
                Vec2f viewSize(m_viewAABB.GetDims());

                glDisable(GL_TEXTURE_2D);

                if(m_useBloom)
                {
                        // Clear the bloom texture
                        SwitchBloom();
                        glLoadIdentity();

            m_bloomTexture.clear(m_ambientColor);

            glColor4f(0.5f, 0.5f, 0.5f, 0.5f);

                        glBlendFunc(GL_ONE, GL_ZERO);

                        // Clear with quad, since glClear is not working for some reason... if results in very ugly artifacts
            /*glBegin(GL_QUADS);
                                glVertex2f(0.0f, 0.0f);
                                glVertex2f(viewSize.x, 0.0f);
                                glVertex2f(viewSize.x, viewSize.y);
                                glVertex2f(0.0f, viewSize.y);
                        glEnd();

            glColor4f(1.0f, 1.0f, 1.0f, 1.0f);*/

                }

#589 line

Estivo

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Re: SFML Light System - Let There Be Light
« Reply #335 on: June 03, 2014, 09:52:50 am »
std::vector<ltbl::ConvexHull* > test;

for(int i = 0; i < walls.size(); i ++)
    {
        test.push_back(new ltbl::ConvexHull() );
        test->loadShape("data/testShape.txt");
        test->calculateNormals();
        test->generateAABB();
        test->setWorldCenter(Vec2f(walls.getPosition().x + 32,720 - walls.getPosition().y + 32));
        ls.addConvexHull(test);
    }

You made some local variables and each loop pass alloc memory for new ConvexShape and leave in memory old.

Epiplon

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Re: SFML Light System - Let There Be Light
« Reply #336 on: June 17, 2014, 05:56:13 am »
Wonder if this was ever ported to C#?  If so it would be nice to use. :)
I thought about that. Started to make the port, but ran in some doubts about the C++ behaviour of certain methods.
Anyone have an idea how to translate QuadTreeNode::Partition to C# language? I don't know how to proceed with resize and the Create method. There are better ways to implement this and I want to set the m_hasChildren property to the right value in the end.

Cyraxx

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #337 on: June 28, 2014, 03:41:09 pm »
Hi,
I'm trying to use LTBL for my platformer but I encountered a wierd problem. When I was testing LTBL it was fine, I managed to implement it with a view following my character around and it worked perfectly.
Altough when I tried to implement it to my main game where we have a really wide map, and an sf::View with zoom centered on the player I just can get the LightSystem's view to be the same size as the window and to follow the player's movement. I tried multiple ways to fix it but it is never at the correct position. (mostly the Y axis)
Could anyone help me out with this one?  :-\

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: SFML Light System - Let There Be Light
« Reply #338 on: June 30, 2014, 01:08:31 pm »
If you don't provide useful information, no one can help you. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jabberwocky

  • Full Member
  • ***
  • Posts: 157
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #339 on: November 19, 2014, 01:16:14 pm »
*** (edit)  See update next post ***

Hi,

I have the LTBL sample compiled and running.  But the only effect I can see is the ambient light.

SFML version:  2.1
LTBL version:  1.5.1
  • LTBL source code modified with the sf::Texture::bind and sf::Shader::bind changes as discussed in this thread.

Here's the program, which is copied directly from the Let there be Light manual.pdf
The only changes are:
  • changes to compile with sfml 2.x
  • changes to compile with ltbl 1.5 - apparently the ltbl manual is out of date.  I needed to change the Light* to a Light_Point*
  • the call to ls.SetView
  • setting ls.m_ambientColor

Code: [Select]
#include <LTBL/Light/LightSystem.h>
#include <LTBL/Light/Light_Point.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("D:/SFML/Let_There_Be_Light_v1.5.1/Let_There_Be_Light_v1.5/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, "D:/SFML/Let_There_Be_Light_v1.5.1/Let_There_Be_Light_v1.5/data/lightFin.png", "D:/SFML/Let_There_Be_Light_v1.5.1/Let_There_Be_Light_v1.5/data/shaders/lightAttenuationShader.frag");
   ls.m_ambientColor = sf::Color(55,55,110);
   ls.SetView(win.getView());

   // Create a light
   ltbl::Light* testLight = new ltbl::Light_Point();
   testLight->m_center = Vec2f(200.0f, 200.0f);
   testLight->m_radius = 500.0f;
   testLight->m_size = 30.0f;
   testLight->CalculateAABB();
   ls.AddLight(testLight);

   // Create a hull by loading it from a file
   ltbl::ConvexHull* testHull = new ltbl::ConvexHull();
   if (!testHull->LoadShape("D:/SFML/Let_There_Be_Light_v1.5.1/Let_There_Be_Light_v1.5/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);
      // Calculate the lights
      ls.RenderLights();
      // Draw the lights
      ls.RenderLightTexture();
      win.display();
   }
   win.close();
}

Screenshot attached.
It is blue/purple because of the ambient colour setting.  But no light or shadow other than that appears.

Thanks for any help!
« Last Edit: November 20, 2014, 12:05:13 am by Jabberwocky »

Jabberwocky

  • Full Member
  • ***
  • Posts: 157
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #340 on: November 20, 2014, 12:04:42 am »
Update:  the LTBL source from here works with SFML 2.1:  https://github.com/hovatterz/light

Unfortunately it is an older version that ltbl 1.5.1, so is missing some key functionality like LightSystem::SetView.  Between this functional version in github, and the 1.5.1 source, hopefully I should be able to create a working version 1.5.1.

I understand it happens with open source projects, but it's a real shame that ltbl isn't maintained.  I am sure it would be very popular functionality for sfml users as some sort of official add-on.
« Last Edit: November 20, 2014, 07:44:12 am by Jabberwocky »

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: SFML Light System - Let There Be Light
« Reply #341 on: November 20, 2014, 11:21:22 am »
Is there the source code of the original example exe from the 1.5.1 zip anywhere?
It works for me but the code from 2 posts above doesn't and I'm not sure if it's SFML or the above code causing that...
Back to C++ gamedev with SFML in May 2023

Jabberwocky

  • Full Member
  • ***
  • Posts: 157
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #342 on: November 20, 2014, 03:25:13 pm »
Is there the source code of the original example exe from the 1.5.1 zip anywhere?

If there is, I never found it.

It works for me but the code from 2 posts above doesn't and I'm not sure if it's SFML or the above code causing that...

Weird.  As I noted above, I had the exact opposite problem.
What doesn't work with the github code?
How did you get the 1.5.1 code working with SFML 2.x?  (or are you using SFML 1.x?)

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: SFML Light System - Let There Be Light
« Reply #343 on: November 20, 2014, 04:21:40 pm »
No, no, you misunderstood me.
The 1.5.1 exe ('it' from second sentence) from the first post is working (via wine even).
With your example code for 1.5.1 (which is what I meant by code from '2 posts above') I too get just purple screen.
I made late SFML 2.1 and LTBL 1.5.1 work together the same way you did.
I didn't try the LTBL version from your github link at all.
So I'd say we have the same problem - 1.5.1 doesn't work with 2.1. Does the exe from the first post work for you too?
« Last Edit: November 20, 2014, 04:28:39 pm by FRex »
Back to C++ gamedev with SFML in May 2023

Jabberwocky

  • Full Member
  • ***
  • Posts: 157
    • View Profile
Re: SFML Light System - Let There Be Light
« Reply #344 on: November 20, 2014, 04:28:30 pm »
So I'd say we have same problem - 1.5.1 doesn't work with 2.1.

Ahh right.  Yes, we both have the same problem.

Does the exe from the first post work for you too?
Yes it does.