How can I create a Fog of War in SDL?

I’m looking to create a 2D game that uses a Fog of War like mechanic.

How can I implement this using SDL?

I have a bitmap as a background and just want to show a section of it around the player as they move, with the rest completely blacked out.

Is this possible?

Thanks in advance!

I guess it mostly depends on how exactly you want it to look like.

One way would be to draw your map and then draw the darkened areas with rects over it, this could work for a tile based map.

For more complex shapes you could use texture blending with a black and white texture representing the explored areas, and texture blending set to SDL_BLENDMODE_MOD.

Sorry if this sounds confusing, but I’d recommend checking out and experimenting with SDL_SetTextureBlendMode and SDL_SetRenderTarget.