Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// SOURCE
// http://techblog.orangepixel.net/2015/07/shine-a-light-on-it/
// http://www.java-gaming.org/topics/2d-nuclear-throne-style-lighting-libgdx/38314/view.html
// VARS
FrameBuffer lightBuffer;
TextureRegion lightBufferRegion;
SpriteBatch light_batch;
// RENDER LOOP
lightBuffer.begin();
// 0 PITCH BLACK to 1 BRIGHT
float lightness = .3f;
Gdx.gl.glClearColor(lightness,lightness,lightness,1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
light_batch.enableBlending();
// RENDER LIGHTS
light_batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE);
// SPRITEBATCH
light_batch.begin();
light_batch.setColor(1,1,1,1);
float tx = (control.screen_w/2);
float ty = (control.screen_h/2);
// hard coded width of 600 for testing
light_batch.draw(Media.light_spot, tx-300,ty-300, 600, 600);
light_batch.end();
// SPRITEBATCH END
lightBuffer.end();
// Render the lightBuffer to the default "frame buffer"
// Set Blend Function of Spritebatch
light_batch.setBlendFunction(GL20.GL_DST_COLOR, GL20.GL_ZERO);
light_batch.begin();
light_batch.draw(lightBufferRegion, 0, 0,control.screen_w,control.screen_h);
light_batch.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.