I wanted to make a little 2D game for the iPhone. I wanted the game play to be happening at night and for the player to be able to see anything at all I needed to some light into the game world. I wanted multiple light sources and if possible colored light. Also, I wanted to be able to easily switch to dawn or even full day light. I wanted to be able to ‘shape’ the light, like the light cones from a cars headlights and not just light spots. So I came up with the idea of rendering light sprites to a texture that is bound to a off screen frame buffer and then blend this texture onto the 2D rendered world. This method keeps the number of textures to a minimum with a large amount of light ‘sources’ - though they are still fakes.

Here is the two light textures used in this example. The one the left is used for the car and the one on the right is used for the three light spots. I have putted both textures on a blue background because they contain transparent areas. I used OpenGL to scale and change the color of when rederingen the three light spots.

Here is the rendered 2D world:

Here is the final rendered light texture:

Here is the final result:

So lets dive into the code. Below is a series of code fragments that shows how to implement the method I have just described.

Here is what you need to do to make the texture that we will render to:

Unlike many other type in the runtime (string, int, DateTime, TimeSpan, Guid etc) CultureInfo is a class and not a struct. And CultureInfo does not have any overloads for ==/!=, so the usage of == and != will do a reference comparison and NOT a value comparison.

The morale of this is; always use the CultureInfo.Equals method when comparing CultureInfo instances. And yes, if you really mean to do a reference comparison, then you of cause use the ==/!= operators.