Simplistic 2d lighting in lwjgl

Greeting everyone.

I currently am preparing a port of my 2d plain java game to lwjgl. The game is tilebased and currently uses per-pixel rendering in pure java.
I have made a test version with lwjgl and everything seems to run pretty smooth.
Though I have encountered one problem(as I’m not that familiar with lwjgl and opengl) of porting the game. In the pure java version the game achieves lighting by adjusting the rgb value of each individual pixel as they are rendered.
The lighting is tile-based and each tile-light value is stored in array(which is only updated whenever a new lightsource is placed), from which the rgb values are adjusted.
Picture showing the lighting:

Here the light around the bonfire is slightly tinted. The rest is just the rgb values lowered(if it is an entity, the light value is based).
What would be a good way to implement such a ‘simple’ form of light in lwjgl?

The simplest way would be to just use shaders and apply lighting to every fragment you render. The correct way is to render lighting mask to a texture, and then blend the lighting texture to the scene, but that is a little bit more complex to do with LWJGL.

Simple way:

Store a 1x1 white square texture.
Render it at varying alphas and tint colors stretched over the tiles to be lit.

…and make sure to either:

  • Position it with an int, not a float. (Although this can cause trouble if your other graphics are positioned with floats. Might look funny sometimes)
  • Render all the lights as one FBO.

Reason being is when dealing with scaled artwork, sometimes you get a strange overlap problem with doing sub pixel movement, and you’ll end up with bright “gridlines” around your light sources sometimes as the two tiles slightly overlap and double the alpha levels in that one spot…

True. But I assume he’ll have already figured out tiles, as that’s what his game is.
Could also just have a 32x32 light mask or whatever size it needs to be.

Thanks. That would be perfect for the tiles!

But entities like trees should also have lighting applied(value based on what tile they are placed on).

Thank you. I’m gonna go with shaders for now :slight_smile: