Fog of War in 2D RTS Game

Hello guys :slight_smile:

I’m making a 2d openGL RTS game with lwjgl. Everything is good so far, but I want to implement the fog of war.

I thought of alphamapping the units of the localplayer by blending them. I already made this alpha map effect with slick2D, but I am quite new to openGL and can’t figure out to make this.
But there are two problems. I don’t want to use textures for the “revealing map action” of a unit, instead I want to draw circles with individual radii. The second problem is, that the map is would only be revealed temporarly. If they move further, the map would be black with this solution. Instead it should be 50% transparent or something like that. YOu all know how fog of war works :smiley:

Please help me :slight_smile:

thanks

Okay I think I solved the problem that the map is kept revealed bye just saving pixels to an array and so on. That shouldn’t be the problem. The only one left is the rendering :smiley: the biggest :stuck_out_tongue:

The Question again: Which blendFunc in combination with what other commands do I have put together in which order?

I really appreciate any code snippets :smiley:

No idea? :frowning:

Here is what I found now. Works fine

	
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);

GL11.glEnable(GL11.GL_STENCIL_TEST);
	        GL11.glStencilFunc(GL11.GL_ALWAYS, 0x1, 0xffffffff);
	        GL11.glStencilOp(GL11.GL_REPLACE, GL11.GL_REPLACE, GL11.GL_REPLACE);
	        GL11.glColorMask(false, false, false, false);

		//draw white circle here
	        
	        GL11.glColorMask(true, true, true, true);
	        GL11.glDepthMask(true);
	        GL11.glStencilFunc(GL11.GL_NOTEQUAL, 1, 1);
	        GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_KEEP);
	        
                //draw black fog here
			
		GL11.glEnable(GL11.GL_STENCIL_TEST);