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

Author Topic: Only render Parts of a sf::sprite | Light sources?  (Read 2384 times)

0 Members and 1 Guest are viewing this topic.

Allptraum

  • Newbie
  • *
  • Posts: 7
    • View Profile
Only render Parts of a sf::sprite | Light sources?
« on: August 09, 2016, 06:35:31 pm »
Hey. I want to implement light sources in my game. I want to lay a complete blank sprite (exactly the window size)
over the game.
Is it possible to create masks for the light (like a white circle wich fades out) as a texture and to say, that the black sprite wont render over the lightmasks? (i dont mean with the intersect function. the pixels of the black sprite wich doesnt cover the mask should render).

I'm open for other ideas to implement light sources.

DarkRoku12

  • Full Member
  • ***
  • Posts: 203
  • Lua coder.
    • View Profile
    • Email
Re: Only render Parts of a sf::sprite | Light sources?
« Reply #1 on: August 09, 2016, 08:05:49 pm »
If you want to render a part of a texture dynamically you need to use shaders.

Check the sf::Shader class and the sf::Shader tutorial.

You also will need a shader tutorial.

Or try to implement LTBL/LTBL2.
I would like a spanish/latin community...
Problems building for Android? Look here

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Only render Parts of a sf::sprite | Light sources?
« Reply #2 on: August 12, 2016, 04:03:59 am »
You may also find using sf::BlendMode useful. It can be used to blend/overlay during drawing or used to cut/crop using a render texture.

If you draw a black rectangle containing a white circle using BlendMultiply, it will leave the circle part as it was and change the rest to black.

Maybe using a the Radial Gradient Shader will help if you're looking for smoother light/spotlight masks.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*