Created
July 14, 2017 22:58
-
-
Save tyler6699/58a00ba6e679990984f8b090558ac3b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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