From 4ecca69cff436adeca036ed9fbea4673c470ad88 Mon Sep 17 00:00:00 2001 From: Nathan Sweet Date: Mon, 15 Mar 2021 12:37:16 +0100 Subject: [PATCH] [libgdx] Added FboTest. Use ScreenUtils#clear. --- .../spine/AttachmentTimelineTests.java | 1 + .../esotericsoftware/spine/BonePlotting.java | 5 +- .../esotericsoftware/spine/Box2DExample.java | 14 +-- .../spine/EventTimelineTests.java | 9 +- .../com/esotericsoftware/spine/FboTest.java | 106 ++++++++++++++++++ .../spine/FrameByFrameTest.java | 4 +- .../com/esotericsoftware/spine/IKTest.java | 38 +++---- .../com/esotericsoftware/spine/MixTest.java | 7 +- .../esotericsoftware/spine/NormalMapTest.java | 7 +- .../esotericsoftware/spine/SimpleTest1.java | 4 +- .../esotericsoftware/spine/SimpleTest2.java | 12 +- .../esotericsoftware/spine/SimpleTest3.java | 4 +- .../esotericsoftware/spine/SimpleTest4.java | 4 +- .../spine/SkeletonAssetManagerTest.java | 4 +- .../spine/SkeletonAttachmentTest.java | 5 +- .../spine/SkinBonesMixAndMatchTest.java | 4 +- .../esotericsoftware/spine/TestHarness.java | 42 +++---- .../spine/VertexEffectTest.java | 7 +- 18 files changed, 194 insertions(+), 83 deletions(-) create mode 100644 spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/FboTest.java diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/AttachmentTimelineTests.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/AttachmentTimelineTests.java index 85df8184b..443679286 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/AttachmentTimelineTests.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/AttachmentTimelineTests.java @@ -30,6 +30,7 @@ package com.esotericsoftware.spine; import com.badlogic.gdx.utils.Array; + import com.esotericsoftware.spine.Animation.AttachmentTimeline; import com.esotericsoftware.spine.Animation.Timeline; import com.esotericsoftware.spine.attachments.Attachment; diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/BonePlotting.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/BonePlotting.java index f1d293966..a0461c486 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/BonePlotting.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/BonePlotting.java @@ -30,15 +30,16 @@ package com.esotericsoftware.spine; import com.badlogic.gdx.files.FileHandle; -import com.esotericsoftware.spine.Animation.MixDirection; + import com.esotericsoftware.spine.Animation.MixBlend; +import com.esotericsoftware.spine.Animation.MixDirection; import com.esotericsoftware.spine.attachments.AttachmentLoader; import com.esotericsoftware.spine.attachments.BoundingBoxAttachment; import com.esotericsoftware.spine.attachments.ClippingAttachment; -import com.esotericsoftware.spine.attachments.RegionAttachment; import com.esotericsoftware.spine.attachments.MeshAttachment; import com.esotericsoftware.spine.attachments.PathAttachment; import com.esotericsoftware.spine.attachments.PointAttachment; +import com.esotericsoftware.spine.attachments.RegionAttachment; public class BonePlotting { static public void main (String[] args) throws Exception { diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/Box2DExample.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/Box2DExample.java index a4ac6ca9c..d1aa96fe9 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/Box2DExample.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/Box2DExample.java @@ -29,16 +29,10 @@ package com.esotericsoftware.spine; -import com.esotericsoftware.spine.Animation.MixDirection; -import com.esotericsoftware.spine.Animation.MixBlend; -import com.esotericsoftware.spine.attachments.AtlasAttachmentLoader; -import com.esotericsoftware.spine.attachments.RegionAttachment; - import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.backends.lwjgl.LwjglApplication; import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; -import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureAtlas; @@ -55,6 +49,12 @@ import com.badlogic.gdx.physics.box2d.FixtureDef; import com.badlogic.gdx.physics.box2d.PolygonShape; import com.badlogic.gdx.physics.box2d.World; import com.badlogic.gdx.utils.Array; +import com.badlogic.gdx.utils.ScreenUtils; + +import com.esotericsoftware.spine.Animation.MixBlend; +import com.esotericsoftware.spine.Animation.MixDirection; +import com.esotericsoftware.spine.attachments.AtlasAttachmentLoader; +import com.esotericsoftware.spine.attachments.RegionAttachment; public class Box2DExample extends ApplicationAdapter { SpriteBatch batch; @@ -140,7 +140,7 @@ public class Box2DExample extends ApplicationAdapter { camera.update(); - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + ScreenUtils.clear(0, 0, 0, 0); batch.setProjectionMatrix(camera.projection); batch.setTransformMatrix(camera.view); batch.begin(); diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/EventTimelineTests.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/EventTimelineTests.java index 684a3ee12..4083984e6 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/EventTimelineTests.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/EventTimelineTests.java @@ -29,13 +29,14 @@ package com.esotericsoftware.spine; -import com.esotericsoftware.spine.Animation.EventTimeline; -import com.esotericsoftware.spine.Animation.MixDirection; -import com.esotericsoftware.spine.Animation.MixBlend; +import java.util.Arrays; + import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.StringBuilder; -import java.util.Arrays; +import com.esotericsoftware.spine.Animation.EventTimeline; +import com.esotericsoftware.spine.Animation.MixBlend; +import com.esotericsoftware.spine.Animation.MixDirection; /** Unit tests for {@link EventTimeline}. */ public class EventTimelineTests { diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/FboTest.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/FboTest.java new file mode 100644 index 000000000..5a8a5c84e --- /dev/null +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/FboTest.java @@ -0,0 +1,106 @@ + +package com.esotericsoftware.spine; + +import com.badlogic.gdx.ApplicationAdapter; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Input; +import com.badlogic.gdx.backends.lwjgl.LwjglApplication; +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.graphics.Pixmap; +import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.graphics.glutils.FrameBuffer; +import com.badlogic.gdx.utils.ScreenUtils; + +import com.esotericsoftware.spine.utils.TwoColorPolygonBatch; + +public class FboTest extends ApplicationAdapter { + OrthographicCamera camera; + TwoColorPolygonBatch batch; + SkeletonRenderer renderer; + BitmapFont font; + + TextureAtlas atlas; + Skeleton skeleton; + + FrameBuffer fbo; + TextureRegion fboRegion; + boolean drawFbo = true; + + public void create () { + camera = new OrthographicCamera(); + batch = new TwoColorPolygonBatch(); + renderer = new SkeletonRenderer(); + renderer.setPremultipliedAlpha(true); + font = new BitmapFont(); + + // Load the atlas and skeleton. + atlas = new TextureAtlas(Gdx.files.internal("spineboy/spineboy-pma.atlas")); + SkeletonJson json = new SkeletonJson(atlas); + json.setScale(0.66f); + SkeletonData skeletonData = json.readSkeletonData(Gdx.files.internal("spineboy/spineboy-ess.json")); + + // Create a skeleton instance, set the position of its root bone, and update its world transform. + skeleton = new Skeleton(skeletonData); + skeleton.setPosition(250, 20); + skeleton.updateWorldTransform(); + + // Create an FBO and a texture region with Y flipped. + fbo = new FrameBuffer(Pixmap.Format.RGBA8888, 512, 512, false); + fboRegion = new TextureRegion(fbo.getColorBufferTexture()); + fboRegion.flip(false, true); + + // Configure the camera and batch for rendering to the FBO's size. + camera.setToOrtho(false, fbo.getWidth(), fbo.getHeight()); + camera.update(); + batch.getProjectionMatrix().set(camera.combined); + + // Render the skeleton to the FBO. + fbo.begin(); + ScreenUtils.clear(0, 0, 0, 0); + batch.begin(); + renderer.draw(batch, skeleton); + batch.end(); + fbo.end(); + + // Configure the camera and batch for rendering to the screen's size. + camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + camera.update(); + batch.getProjectionMatrix().set(camera.combined); + } + + public void render () { + ScreenUtils.clear(1, 1, 1, 1); + + batch.begin(); + + if (drawFbo) { + // Render the FBO color buffer texture to screen. + batch.draw(fboRegion, 0, 0); + } else { + // Render the skeleton directly to the screen. + renderer.draw(batch, skeleton); + } + + font.setColor(Color.BLACK); + font.draw(batch, drawFbo ? "Drawing FBO." : "Not drawing FBO.", 10, 10 + font.getCapHeight()); + batch.end(); + + if (Gdx.input.justTouched() || Gdx.input.isKeyJustPressed(Input.Keys.SPACE)) { + drawFbo = !drawFbo; + Gdx.app.log("SpineFBOTest", "Using FBO: " + drawFbo); + } + } + + public void resize (int width, int height) { + camera.setToOrtho(false, width, height); + camera.update(); + batch.getProjectionMatrix().set(camera.combined); + } + + static public void main (String[] args) throws Exception { + new LwjglApplication(new FboTest()); + } +} diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/FrameByFrameTest.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/FrameByFrameTest.java index fe1727ba6..a4a38a711 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/FrameByFrameTest.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/FrameByFrameTest.java @@ -32,13 +32,13 @@ package com.esotericsoftware.spine; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.backends.lwjgl.LwjglApplication; -import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.Animation; import com.badlogic.gdx.graphics.g2d.Animation.PlayMode; import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasSprite; +import com.badlogic.gdx.utils.ScreenUtils; public class FrameByFrameTest extends ApplicationAdapter { OrthographicCamera camera; @@ -80,7 +80,7 @@ public class FrameByFrameTest extends ApplicationAdapter { y -= origin[1]; frame.setPosition(x, y); - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + ScreenUtils.clear(0, 0, 0, 0); camera.update(); batch.getProjectionMatrix().set(camera.combined); diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/IKTest.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/IKTest.java index 8c3c3da60..9cce44ab1 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/IKTest.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/IKTest.java @@ -32,18 +32,16 @@ package com.esotericsoftware.spine; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.backends.lwjgl.LwjglApplication; -import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector3; +import com.badlogic.gdx.utils.ScreenUtils; + import com.esotericsoftware.spine.utils.TwoColorPolygonBatch; -/** Demonstrates how to let the target bone of an IK constraint - * follow the mouse or touch position, which in turn repositions - * part of the skeleton, in this case Spineboy's back arm including - * his gun. - */ +/** Demonstrates how to let the target bone of an IK constraint follow the mouse or touch position, which in turn repositions part + * of the skeleton, in this case Spineboy's back arm including his gun. */ public class IKTest extends ApplicationAdapter { OrthographicCamera camera; TwoColorPolygonBatch batch; @@ -52,7 +50,7 @@ public class IKTest extends ApplicationAdapter { TextureAtlas atlas; Skeleton skeleton; AnimationState state; - + Vector3 cameraCoords = new Vector3(); Vector2 boneCoords = new Vector2(); @@ -66,21 +64,21 @@ public class IKTest extends ApplicationAdapter { // Load the texture atlas and skeleton data atlas = new TextureAtlas(Gdx.files.internal("spineboy/spineboy-pma.atlas")); SkeletonBinary json = new SkeletonBinary(atlas); - json.setScale(0.6f); + json.setScale(0.6f); SkeletonData skeletonData = json.readSkeletonData(Gdx.files.internal("spineboy/spineboy-pro.skel")); // Create a skeleton from the skeleton data skeleton = new Skeleton(skeletonData); skeleton.setPosition(250, 20); - + // Create an animation satte AnimationStateData stateData = new AnimationStateData(skeletonData); state = new AnimationState(stateData); - + // Queue the "walk" animation on the first track. state.setAnimation(0, "walk", true); - - // Queue the "aim" animation on a higher track. + + // Queue the "aim" animation on a higher track. // It consists of a single frame that positions // the back arm and gun such that they point at // the "crosshair" bone. By setting this @@ -97,10 +95,10 @@ public class IKTest extends ApplicationAdapter { // then calculate the world transforms of every bone. // This is needed so we can call Bone#worldToLocal() // later. - state.update(Gdx.graphics.getDeltaTime()); + state.update(Gdx.graphics.getDeltaTime()); state.apply(skeleton); skeleton.updateWorldTransform(); - + // Position the "crosshair" bone at the mouse // location. We do this before calling // skeleton.updateWorldTransform() below, so @@ -110,18 +108,18 @@ public class IKTest extends ApplicationAdapter { // When setting the crosshair bone position // to the mouse position, we need to translate // from "mouse space" to "camera space" - // and then to "local bone space". Note that the local + // and then to "local bone space". Note that the local // bone space is calculated using the bone's parent // worldToLocal() function! cameraCoords.set(Gdx.input.getX(), Gdx.input.getY(), 0); - camera.unproject(cameraCoords); // mouse space to camera space - + camera.unproject(cameraCoords); // mouse space to camera space + Bone crosshair = skeleton.findBone("crosshair"); // Should be cached. boneCoords.set(cameraCoords.x, cameraCoords.y); crosshair.getParent().worldToLocal(boneCoords); // camera space to local bone space crosshair.setPosition(boneCoords.x, boneCoords.y); // override the crosshair position crosshair.setAppliedValid(false); - + // Calculate final world transform with the // crosshair bone set to the mouse cursor // position. @@ -129,9 +127,9 @@ public class IKTest extends ApplicationAdapter { // Clear the screen, update the camera and // render the skeleton. - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + ScreenUtils.clear(0, 0, 0, 0); camera.update(); - + batch.getProjectionMatrix().set(camera.combined); batch.begin(); renderer.draw(batch, skeleton); diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/MixTest.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/MixTest.java index 819f82225..d1e55161b 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/MixTest.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/MixTest.java @@ -32,12 +32,13 @@ package com.esotericsoftware.spine; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.backends.lwjgl.LwjglApplication; -import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.utils.Array; -import com.esotericsoftware.spine.Animation.MixDirection; +import com.badlogic.gdx.utils.ScreenUtils; + import com.esotericsoftware.spine.Animation.MixBlend; +import com.esotericsoftware.spine.Animation.MixDirection; public class MixTest extends ApplicationAdapter { SpriteBatch batch; @@ -95,7 +96,7 @@ public class MixTest extends ApplicationAdapter { if (time > beforeJump + blendIn && time < blendOutStart) speed = 360; skeleton.setX(skeleton.getX() + speed * delta); - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + ScreenUtils.clear(0, 0, 0, 0); // This shows how to manage state manually. See SimpleTest1 for a higher level API using AnimationState. if (time > total) { diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/NormalMapTest.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/NormalMapTest.java index bd3a928c5..2e18c2dc0 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/NormalMapTest.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/NormalMapTest.java @@ -36,7 +36,6 @@ import com.badlogic.gdx.InputMultiplexer; import com.badlogic.gdx.Preferences; import com.badlogic.gdx.backends.lwjgl.LwjglApplication; import com.badlogic.gdx.files.FileHandle; -import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureAtlas; @@ -55,8 +54,10 @@ import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.ui.Window; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.badlogic.gdx.utils.Align; -import com.esotericsoftware.spine.Animation.MixDirection; +import com.badlogic.gdx.utils.ScreenUtils; + import com.esotericsoftware.spine.Animation.MixBlend; +import com.esotericsoftware.spine.Animation.MixDirection; public class NormalMapTest extends ApplicationAdapter { String skeletonPath, animationName; @@ -138,7 +139,7 @@ public class NormalMapTest extends ApplicationAdapter { lightPosition.x = Gdx.input.getX(); lightPosition.y = (Gdx.graphics.getHeight() - 1 - Gdx.input.getY()); - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + ScreenUtils.clear(0, 0, 0, 0); ambientColor.x = ui.ambientColorR.getValue(); ambientColor.y = ui.ambientColorG.getValue(); diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest1.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest1.java index 7889f248f..c020a07b6 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest1.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest1.java @@ -32,10 +32,10 @@ package com.esotericsoftware.spine; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.backends.lwjgl.LwjglApplication; -import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.badlogic.gdx.utils.ScreenUtils; public class SimpleTest1 extends ApplicationAdapter { OrthographicCamera camera; @@ -82,7 +82,7 @@ public class SimpleTest1 extends ApplicationAdapter { public void render () { state.update(Gdx.graphics.getDeltaTime()); // Update the animation time. - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + ScreenUtils.clear(0, 0, 0, 0); state.apply(skeleton); // Poses skeleton using current animations. This sets the bones' local SRT. skeleton.updateWorldTransform(); // Uses the bones' local SRT to compute their world SRT. diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest2.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest2.java index f7dc47060..b51e81c83 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest2.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest2.java @@ -29,20 +29,20 @@ package com.esotericsoftware.spine; -import com.esotericsoftware.spine.AnimationState.AnimationStateListener; -import com.esotericsoftware.spine.AnimationState.TrackEntry; -import com.esotericsoftware.spine.attachments.BoundingBoxAttachment; - import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.InputAdapter; import com.badlogic.gdx.backends.lwjgl.LwjglApplication; import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.math.Vector3; +import com.badlogic.gdx.utils.ScreenUtils; + +import com.esotericsoftware.spine.AnimationState.AnimationStateListener; +import com.esotericsoftware.spine.AnimationState.TrackEntry; +import com.esotericsoftware.spine.attachments.BoundingBoxAttachment; public class SimpleTest2 extends ApplicationAdapter { OrthographicCamera camera; @@ -145,7 +145,7 @@ public class SimpleTest2 extends ApplicationAdapter { public void render () { state.update(Gdx.graphics.getDeltaTime()); // Update the animation time. - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + ScreenUtils.clear(0, 0, 0, 0); if (state.apply(skeleton)) // Poses skeleton using current animations. This sets the bones' local SRT. skeleton.updateWorldTransform(); // Uses the bones' local SRT to compute their world SRT. diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest3.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest3.java index fed6f8627..3bc4e1c87 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest3.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest3.java @@ -32,10 +32,10 @@ package com.esotericsoftware.spine; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.backends.lwjgl.LwjglApplication; -import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.badlogic.gdx.utils.ScreenUtils; public class SimpleTest3 extends ApplicationAdapter { OrthographicCamera camera; @@ -80,7 +80,7 @@ public class SimpleTest3 extends ApplicationAdapter { public void render () { state.update(Gdx.graphics.getDeltaTime()); // Update the animation time. - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + ScreenUtils.clear(0, 0, 0, 0); if (state.apply(skeleton)) // Poses skeleton using current animations. This sets the bones' local SRT. skeleton.updateWorldTransform(); // Uses the bones' local SRT to compute their world SRT. diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest4.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest4.java index b7a22cddb..2e35a579e 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest4.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SimpleTest4.java @@ -32,9 +32,9 @@ package com.esotericsoftware.spine; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.backends.lwjgl.LwjglApplication; -import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.badlogic.gdx.utils.ScreenUtils; import com.esotericsoftware.spine.utils.TwoColorPolygonBatch; @@ -85,7 +85,7 @@ public class SimpleTest4 extends ApplicationAdapter { public void render () { state.update(Gdx.graphics.getDeltaTime()); // Update the animation time. - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + ScreenUtils.clear(0, 0, 0, 0); state.apply(skeleton); // Poses skeleton using current animations. This sets the bones' local SRT. skeleton.updateWorldTransform(); // Uses the bones' local SRT to compute their world SRT. diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SkeletonAssetManagerTest.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SkeletonAssetManagerTest.java index 85eb6137b..f236bb1d6 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SkeletonAssetManagerTest.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SkeletonAssetManagerTest.java @@ -33,10 +33,10 @@ import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.assets.AssetManager; import com.badlogic.gdx.backends.lwjgl.LwjglApplication; -import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.badlogic.gdx.utils.ScreenUtils; import com.esotericsoftware.spine.utils.SkeletonDataLoader; import com.esotericsoftware.spine.utils.SkeletonDataLoader.SkeletonDataParameter; @@ -71,7 +71,7 @@ public class SkeletonAssetManagerTest extends ApplicationAdapter { } public void render () { - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + ScreenUtils.clear(0, 0, 0, 0); if (skeleton == null) { // Not loaded yet. diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SkeletonAttachmentTest.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SkeletonAttachmentTest.java index c86982515..17f86e181 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SkeletonAttachmentTest.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SkeletonAttachmentTest.java @@ -32,10 +32,11 @@ package com.esotericsoftware.spine; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.backends.lwjgl.LwjglApplication; -import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.badlogic.gdx.utils.ScreenUtils; + import com.esotericsoftware.spine.attachments.SkeletonAttachment; public class SkeletonAttachmentTest extends ApplicationAdapter { @@ -97,7 +98,7 @@ public class SkeletonAttachmentTest extends ApplicationAdapter { goblinState.apply(goblin); goblin.updateWorldTransform(attachmentBone); - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + ScreenUtils.clear(0, 0, 0, 0); camera.update(); batch.getProjectionMatrix().set(camera.combined); diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SkinBonesMixAndMatchTest.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SkinBonesMixAndMatchTest.java index 26cc319b8..510c5198a 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SkinBonesMixAndMatchTest.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/SkinBonesMixAndMatchTest.java @@ -32,10 +32,10 @@ package com.esotericsoftware.spine; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.backends.lwjgl.LwjglApplication; -import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.badlogic.gdx.utils.ScreenUtils; public class SkinBonesMixAndMatchTest extends ApplicationAdapter { OrthographicCamera camera; @@ -90,7 +90,7 @@ public class SkinBonesMixAndMatchTest extends ApplicationAdapter { public void render () { state.update(Gdx.graphics.getDeltaTime()); // Update the animation time. - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + ScreenUtils.clear(0, 0, 0, 0); state.apply(skeleton); // Poses skeleton using current animations. This sets the bones' local SRT. skeleton.updateWorldTransform(); // Uses the bones' local SRT to compute their world SRT. diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/TestHarness.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/TestHarness.java index b6a7cc615..4542e0222 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/TestHarness.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/TestHarness.java @@ -32,42 +32,43 @@ package com.esotericsoftware.spine; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.backends.lwjgl.LwjglApplication; -import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.Interpolation; +import com.badlogic.gdx.utils.ScreenUtils; + import com.esotericsoftware.spine.vertexeffects.SwirlEffect; public class TestHarness extends ApplicationAdapter { -// static String JSON = "coin/coin-pro.json"; -// static String ATLAS = "coin/coin-pma.atlas"; - +// static String JSON = "coin/coin-pro.json"; +// static String ATLAS = "coin/coin-pma.atlas"; + static String JSON = "raptor/raptor-pro.json"; static String ATLAS = "raptor/raptor-pma.atlas"; - + OrthographicCamera camera; PolygonSpriteBatch batch; SkeletonRenderer renderer; - + ShapeRenderer shapes; TextureAtlas atlas; Skeleton skeleton; AnimationState state; - + SwirlEffect swirl; float swirlTime; - public void create () { + public void create () { camera = new OrthographicCamera(); camera.setToOrtho(true); batch = new PolygonSpriteBatch(); renderer = new SkeletonRenderer(); - renderer.setPremultipliedAlpha(true); + renderer.setPremultipliedAlpha(true); shapes = new ShapeRenderer(); - + swirl = new SwirlEffect(400); swirl.setCenterY(-200); renderer.setVertexEffect(swirl); @@ -76,13 +77,13 @@ public class TestHarness extends ApplicationAdapter { SkeletonJson json = new SkeletonJson(atlas); json.setScale(0.5f); SkeletonData skeletonData = json.readSkeletonData(Gdx.files.internal(JSON)); - - skeleton = new Skeleton(skeletonData); + + skeleton = new Skeleton(skeletonData); skeleton.setPosition(320, 590); skeleton.setScaleY(-1); - AnimationStateData stateData = new AnimationStateData(skeletonData); - state = new AnimationState(stateData); + AnimationStateData stateData = new AnimationStateData(skeletonData); + state = new AnimationState(stateData); // state.setAnimation(0, "rotate", false); state.update(0); state.apply(skeleton); @@ -91,30 +92,29 @@ public class TestHarness extends ApplicationAdapter { public void render () { if (Gdx.input.justTouched()) { - state.update(0.25f); // Update the animation time. + state.update(0.25f); // Update the animation time. } state.apply(skeleton); // Poses skeleton using current animations. This sets the bones' local SRT. skeleton.updateWorldTransform(); // Uses the bones' local SRT to compute their world SRT. - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - + ScreenUtils.clear(0, 0, 0, 0); + swirlTime += Gdx.graphics.getDeltaTime(); float percent = swirlTime % 2; if (percent > 1) percent = 1 - (percent - 1); swirl.setAngle(Interpolation.pow2.apply(-60, 60, percent)); - // Configure the camera, SpriteBatch, and SkeletonRendererDebug. camera.update(); - batch.getProjectionMatrix().set(camera.combined); + batch.getProjectionMatrix().set(camera.combined); batch.begin(); renderer.draw(batch, skeleton); // Draw the skeleton images. - batch.end(); + batch.end(); } public void resize (int width, int height) { - camera.setToOrtho(true); // Update camera with new size. + camera.setToOrtho(true); // Update camera with new size. } public void dispose () { diff --git a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/VertexEffectTest.java b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/VertexEffectTest.java index 9a2928cbe..b4f43eb42 100644 --- a/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/VertexEffectTest.java +++ b/spine-libgdx/spine-libgdx-tests/src/com/esotericsoftware/spine/VertexEffectTest.java @@ -33,11 +33,12 @@ import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.backends.lwjgl.LwjglApplication; import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; -import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.math.Interpolation; +import com.badlogic.gdx.utils.ScreenUtils; + import com.esotericsoftware.spine.vertexeffects.SwirlEffect; public class VertexEffectTest extends ApplicationAdapter { @@ -74,7 +75,7 @@ public class VertexEffectTest extends ApplicationAdapter { // Queue animations on tracks 0 and 1. state.setAnimation(0, "walk", true); state.addAnimation(1, "gun-grab", false, 2); // Keys in higher tracks override the pose from lower tracks. - + swirl = new SwirlEffect(400); swirl.setCenter(0, 200); renderer.setVertexEffect(swirl); @@ -92,7 +93,7 @@ public class VertexEffectTest extends ApplicationAdapter { if (percent > 1) percent = 1 - (percent - 1); swirl.setAngle(Interpolation.pow2.apply(-60, 60, percent)); - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + ScreenUtils.clear(0, 0, 0, 0); state.apply(skeleton); // Poses skeleton using current animations. This sets the bones' local SRT. skeleton.updateWorldTransform(); // Uses the bones' local SRT to compute their world SRT.