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

Author Topic: 2D lighting with SFML  (Read 2589 times)

0 Members and 1 Guest are viewing this topic.

demetri247

  • Newbie
  • *
  • Posts: 3
    • View Profile
2D lighting with SFML
« on: December 16, 2020, 06:29:12 pm »
I'm in the process of implementing a lighting engine, and I've been struggling with the polygon drawing. Currently, I'm using TriangleFan to connect the points that my raycasting algorithm has come in contact with, but I wish to achieve the opposite effect where everything except where the triangle fan is drawn is black and the play would have a limited view of their surroundings.

Is there a shape that could easily accomplish this?

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: 2D lighting with SFML
« Reply #1 on: December 16, 2020, 09:21:49 pm »
You could render that triangle fan (as white) to a render texture (the same size as the window) and then draw that render texture to the window with a multiplicative blend mode, leaving everything as-is where it is white and turning to black anything that is black.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

demetri247

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: 2D lighting with SFML
« Reply #2 on: December 16, 2020, 10:36:31 pm »
So something like this?
(click to show/hide)
The screen is just rendered as black, without the blending the Triangle fan is white and the rest is black but I can't see the textures underneath.

demetri247

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: 2D lighting with SFML
« Reply #3 on: December 16, 2020, 11:45:12 pm »
nvm i was being silly and cleared the window  :P, works like a dream. Thank you!

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: 2D lighting with SFML
« Reply #4 on: December 17, 2020, 12:04:24 am »
Yes, you need to clear, draw and display both the render texture and the window.

You are welcome! Pleased to help :)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything