Dynamic tile map lighting.

Posted the code and more details on the technique here:
http://slick.cokeandcode.com/wiki/doku.php?id=alpha_maps

:open_mouth:

:open_mouth:

:open_mouth:

I love you!

My slick2d lights in action.

This simple code snippet draw nice lights pretty efficiently and these blend together smoothly. Light is just class that have float x, y and size. Alphamap is just like usual one http://dl.dropbox.com/u/10960490/alphamini.png


void lights(Graphics g) {
	GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);

	g.clearAlphaMap();

        for (Lights l :  lightList){
            g.scale(l.size, l.size);		
            alphamap.drawCentered(l.x, l.y);
        }

	g.resetTransform();
	GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_DST_ALPHA);
	g.fillRect(0, 0, ScreenWidth, ScreenHeight);
	g.setDrawMode(Graphics.MODE_NORMAL);
}

For full dynamic 2d lights solution I have made this http://code.google.com/p/box2dlights/

http://desmond.imageshack.us/Himg21/scaled.php?server=21&filename=newbitmapimageeu.png&res=landing

How do I fix that?
(Not the yellow box, it’s supposed to be there)

There might be a way using Slick’s blending modes, but the simplest would be to bake your sprites/overlays/etc onto the same texture (via offscreen images), and only apply the lighting as if it were a “post processing” effect.

There are some more flexible lighting solutions discussed here, although all of them require some OpenGL tinkering:

Should the player background be filled with alpha, so the player blends right in?

Yes.

Edit: Also…I need a better way of handling these lights. I need to draw them kind of in-between blending, instead of before blending. If I do it before blending, it really makes the engine unflexible and messy. If I need to use OpenGL I’m completely fine with it, I just need someone to explain it in relatively simple terms.