Funnily, I've just implemented an algorithm to do this in Java2d
Though I'm rewriting it atm to change the way the level is represented, so it'll be simpler to procedurally generate level data.
I doubt it'll be of much use if you're using ogl, but if you like I can post the code once I've refactored & neatened everything up a bit.
A quick overview of the algo:
- map defined as a maze of interconnected convex polygons
- lights are arcs (mathematical 'sector'), with an origin, radius, start & end angles.
- lights are rendered as gradient fill circles (pre-rendered to an image if you want extra speed), and are drawn through a polygon clip.
- the polygon clip is constructed by:
- cast 1 ray out from light origin along start angle, looking for edge intersection with the polygon currently containing the light.
- If the intersected edge is a wall (rather than a doorway into another polygon), add the intersection point as a vertex to your clip polygon.
- walk around polygon's vertices, adding each as a vertex to your clip polygon.
- once you reach a vertex that that lies beyond the light's end angle, cast a 2nd ray to find the intersection point
- for each edge you walk around that is a doorway into another convex polygon (and is inside the radius of the light), process it recursively using the same algorithm.
Computationally it's very cheap; my initial implementation could render 1000+ clipped light sources @ 60fps.
There are of course limitations; no spot effect (focal point), no smooth transitions at the start/end of the light arc (sector), no surface specific lighting.