Help with 2d lighting

Started by lukstra, June 01, 2014, 04:55:29

Previous topic - Next topic

lukstra

I am new to both lwjgl and opengl.

I've been trying to experiment with 2d lighting. I've seen some examples online (the best of which is at https://github.com/jacobbrunson/BasicLighting/), but none have used textures. Could someone please use basic terminology to explain how to add textures to such a lighting system?

quew8

In that system, the lighting has absolutely nothing to do with the way the blocks themselves are rendered. Let me give you a run down of the render process.

--For Each Light
----For Each Block
------For Each Line
--------Draw into stencil buffer areas of shadow cast by that light on this line.
----Draw wash over screen of light intensity, except where there is a shadow in the stencil buffer, use additive blending.
----Clear stencil buffer for next light
--For Each Block
----Draw Block.

That is literally it. The complex bits here are getting the stencil buffer op right and computing the shadow areas. To add textures, you just need to change the way you draw the blocks.