0
\$\begingroup\$

I'm working on a 2D tile-map RPG with C++17 and SDL2 + SDL_Image.

There are daily cycles, weekly cycles and seasons. Even a kind of weather engine provides atmosphere. The moods and times of day are conveyed very well via a semi-transparent additional layer that I render over the other layers. To do this, i modulate the colors of this layer depending on the time of day, season or weather. So far so good...

Such a village looks really bad at night without lighting! Unfortunately, the pure SDL2 library does not support light without the use of OGL (which I have no idea about). Apart from the fact that I could of course create tiles for an illuminated version of the map (which I don't want to), i was thinking about a possible solution in which i somehow render the last layer "with holes" that are more transparent than the rest and Maybe the color tends more towards yellow.

But I have no idea how to implement something like that without forcing the device to its knees. And at 3 fps the game is definitely a lot of fun.

I need theortical help please!

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

I think what you want is to create a black texture with the same size as your screen, set it as the render target, render blurry white circles to it at the locations of the light sources, with the blend mode set to 'add'.

Then render this texture on top of your scene, with the blend mode set to 'modulate' (which is how SDL calls multiplication that ignores alpha).

This will give you the effect of the screen being black by default, with things only being visible through blurry 'holes' near the light sources.

You can vary the default lighting by replacing black with a lighter color, and vary light source colors.

\$\endgroup\$
2
  • \$\begingroup\$ Yes, exactly! This is the idea i was looking for. Thank you. \$\endgroup\$ Commented Nov 25, 2023 at 16:54
  • 1
    \$\begingroup\$ When i add a kind of randomized zoom/size-change to the circles it looks like natural fire. \$\endgroup\$ Commented Nov 25, 2023 at 21:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .