Created
April 10, 2017 14:32
-
-
Save badlogic/a07a45c977c1d0b737f70c197aef5535 to your computer and use it in GitHub Desktop.
This file contains 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
package com.annimationtest.game; | |
import com.badlogic.gdx.ApplicationAdapter; | |
import com.badlogic.gdx.Gdx; | |
import com.badlogic.gdx.Input; | |
import com.badlogic.gdx.graphics.GL20; | |
import com.badlogic.gdx.graphics.OrthographicCamera; | |
import com.badlogic.gdx.graphics.Pixmap; | |
import com.badlogic.gdx.graphics.g2d.SpriteBatch; | |
import com.badlogic.gdx.graphics.g2d.TextureAtlas; | |
import com.badlogic.gdx.graphics.g2d.TextureRegion; | |
import com.badlogic.gdx.graphics.glutils.FrameBuffer; | |
import com.esotericsoftware.spine.*; | |
public class SpineFBOTest extends ApplicationAdapter { | |
OrthographicCamera camera; | |
SpriteBatch batch; | |
SkeletonRenderer renderer; | |
TextureAtlas atlas; | |
Skeleton skeleton; | |
FrameBuffer fbo; | |
TextureRegion fboRegion; | |
boolean useFbo = false; | |
@Override | |
public void create() { | |
camera = new OrthographicCamera(); | |
batch = new SpriteBatch(); | |
renderer = new SkeletonRenderer(); | |
renderer.setPremultipliedAlpha(true); | |
atlas = new TextureAtlas(Gdx.files.internal("annimation/Farmer1/Farmer1.atlas")); | |
SkeletonJson json = new SkeletonJson(atlas); | |
json.setScale(0.66f); | |
SkeletonData skeletonData = json.readSkeletonData(Gdx.files.internal("annimation/Farmer1/Farmer10.json")); | |
skeleton = new Skeleton(skeletonData); | |
skeleton.setPosition(250, 20); | |
fbo = new FrameBuffer(Pixmap.Format.RGBA8888, 512, 512, false); | |
fboRegion = new TextureRegion(fbo.getColorBufferTexture()); | |
fboRegion.flip(false, true); | |
} | |
@Override | |
public void render() { | |
Gdx.gl.glClearColor(1, 1, 1, 1); | |
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); | |
skeleton.updateWorldTransform(); | |
if (!useFbo) { | |
batch.begin(); | |
renderer.draw(batch, skeleton); | |
batch.end(); | |
} else { | |
// Render skeleton to FBO | |
fbo.begin(); | |
Gdx.gl.glClearColor(0, 0, 0, 0); | |
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); | |
camera.setToOrtho(false, fbo.getWidth(), fbo.getHeight()); | |
camera.update(); | |
batch.getProjectionMatrix().set(camera.combined); | |
batch.begin(); | |
renderer.draw(batch, skeleton); | |
batch.end(); | |
fbo.end(); | |
// Render FBO color buffer texture to screen | |
camera.setToOrtho(false); | |
camera.update(); | |
batch.getProjectionMatrix().set(camera.combined); | |
batch.begin(); | |
batch.draw(fboRegion, 0, 0); | |
batch.end(); | |
} | |
if (Gdx.input.isKeyJustPressed(Input.Keys.SPACE)) { | |
useFbo = !useFbo; | |
Gdx.app.log("SpineFBOTest", "Using FBO: " + useFbo); | |
} | |
} | |
@Override | |
public void resize(int width, int height) { | |
camera.setToOrtho(false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment