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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Clink

Pages: [1]
1
Graphics / Re: Create a light effect with BlendMode?
« on: January 04, 2013, 05:02:03 pm »
Thanks for the reply! It really made things go forward. Though using sf::BlendAdd on the light and sf::BlendMultiply on the scene didn't work.

But I played around with it and came upp with this:

_light.setColor(sf::Color(0, 0, 0, 0));

        _light.setPosition(static_cast<float>(mousePos.x), static_cast<float>(mousePos.y));

//_target is a sf::RenderTexture
        _target.clear(sf::Color(255, 255, 255, 200));

        _target.draw(_light, sf::BlendMultiply);
        //_target.draw(_light, sf::BlendAdd);

        _target.display();


        _pWindow->clear(sf::Color(0, 150, 255, 255));

        _pWindow->draw(_background);

        _darkness.setTexture(_target.getTexture() );

        _pWindow->draw(_darkness, sf::BlendAdd);
        //_pWindow->draw(_darkness, sf::BlendMultiply);

        _pWindow->display();

This works exactley like I want it to. Just one little problem...

The dark isn't that dark. In fact, it's white. My guess was that it was because of
_target.clear(sf::Color(255, 255, 255, 200)); that fill the render texture with a black color.

So I thought switching it to _target.clear(sf::Color(0, 0, 0, 200)); would give me the opposite effect.

But that made the whole render texture invisible!

What am I missing?

*Edit

Nevermind, I solved it :)

The light was the bad guy. It was also supposed to be black :P

I'll leave the code here if anyone is intrested.

_light.setColor(sf::Color(255, 255, 255, 0));

        _light.setPosition(static_cast<float>(mousePos.x), static_cast<float>(mousePos.y));

        _target.clear(sf::Color(0, 0, 0, 200));

        _target.draw(_light, sf::BlendNone);

        _target.display();


        _pWindow->clear(sf::Color(0, 150, 255, 255));

        _pWindow->draw(_background);

        _darkness.setTexture(_target.getTexture() );

        _pWindow->draw(_darkness);

        _pWindow->display();

Thanks for the help!

2
Graphics / Create a light effect with BlendMode?
« on: January 04, 2013, 03:40:03 pm »
Hi!

I'm working on a little project and I'm kinda stuck. I'm trying to create a dark screen that you can lit up with a light that follows the mouse.

The effect I'm looking for is something similar to the thing they have in Donkey Kong Country:
http://4.bp.blogspot.com/_PM97N1Dtb10/SjN41jFUNzI/AAAAAAAABRU/UCfF2AfDf2c/s400/torchlight_trouble.jpg

I believe this would be possible by first drawing the background. And then drawing a a compleatly black sprite over the the entire screen, representing the darkness. On top of the darkness sprite I draw a smaller sprite that would be the light.

My thought was that I could use a BlendMode to take the alpha value of the light and "cut through" the darkness. Showing a clear piece of the background.

The code that I have so far is this:
_darkness.setColor(sf::Color(255, 255, 255, 200));
        _light.setColor(sf::Color(0, 0, 0, 0));

        _light.setPosition(static_cast<float>(mousePos.x), static_cast<float>(mousePos.y));

        _pWindow->clear(sf::Color(0, 150, 255, 255));

        _pWindow->draw(_background);

        _pWindow->draw(_darkness);

        _pWindow->draw(_light, sf::BlendMultiply);
       
        _pWindow->display();
 

Am I even on the right track? If so, how can I fix this? If not, what is the right track?

Help is appreciated :)

Pages: [1]