Fog Of War, Custom Rendering HELP


I need to make Fog of War for my game.

My strategy now:

  1. Draw a fullscreen black rectangle.
  2. Player has a transparent circle around him.
  3. I want to somehow write a blend function that when this transparent circle meets the black rectangle, the portion of the rectangle where they intersect should go transparent.
  4. That way the black rectangle will become transparent in the intersections with the circle around the player.

How is this done in OpenGL and Defold?

Any other strategies for FoW?

Thank you!

Everytime I do FoW it’s always part of a tile-based program. The original sprite for the object will be a black square and in the update function for an object (let’s say a wall) I’d put:

if (can_see_player)
if (distance_to_player <= 25)

this way, everything starts out black but as soon as the player gets close enough and the object isn’t behind anything then it will change to its normal sprite.

Hope this helps :slight_smile:

Thank you man. @Listrix
I did something similar, I used an entirely black tilemap on top of my game and cleared these black tiles when the player was near them.
However I think there are better ways to do it with some OpenGL magic.
My thought was to have a fullscreen black plane and somehow use masking to “make holes” in that plane when needed.
I will continue experimenting with this when I have some time over :smiley:

I don’t have much OpenGL experience, but this is kinda similar, using masks to make holes in planes Making a “flashlight”

The way that you described your version of it is actually very similar, it’s kinda what I did when making survival games for a lighting engine. You’d have a black screen over the top of everything and then the torches would give off light by lowering the alpha value of the black screen around it. I’d encourage you to experiment with this more and see what you come up with :slight_smile:

1 Like