diff --git a/src/com/blarg/gdx/graphics/ExtendedSpriteBatch.java b/src/com/blarg/gdx/graphics/ExtendedSpriteBatch.java index cb38c62..c9dcd33 100644 --- a/src/com/blarg/gdx/graphics/ExtendedSpriteBatch.java +++ b/src/com/blarg/gdx/graphics/ExtendedSpriteBatch.java @@ -1,6 +1,7 @@ package com.blarg.gdx.graphics; import com.badlogic.gdx.graphics.Camera; +import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.SpriteBatch; @@ -13,9 +14,12 @@ import com.badlogic.gdx.math.Vector3; * are to make drawing sprites at projected screen coordinates easier. * * Projected screen coordinate sprite rendering requires a perspective camera to project the 3D coordinates correctly. - * A camera _must_ be set via {@link #setProjectionCamera} before any of these draw methods are called. + * A camera _must_ be set via {@link #begin(Camera)} (instead of using {@link #begin()}) before any of these draw + * methods are called. */ public class ExtendedSpriteBatch extends SpriteBatch { + static final float DEFAULT_COLOR = Color.WHITE.toFloatBits(); + static final Vector3 tmp1 = new Vector3(); Camera projectionCamera; @@ -41,16 +45,29 @@ public class ExtendedSpriteBatch extends SpriteBatch { super(size, buffers, defaultShader); } - public void setProjectionCamera(Camera camera) { - this.projectionCamera = camera; - } - public void setPixelScale(int pixelScale) { if (pixelScale <= 0) throw new IllegalArgumentException(); this.pixelScale = pixelScale; } + @Override + public void begin() { + super.begin(); + setColor(DEFAULT_COLOR); + } + + public void begin(Camera projectionCamera) { + begin(); + this.projectionCamera = projectionCamera; + } + + @Override + public void end() { + super.end(); + this.projectionCamera = null; + } + /**************************************************************************/ public void draw(Texture texture, float x, float y, float z) { diff --git a/src/com/blarg/gdx/graphics/GraphicsHelpers.java b/src/com/blarg/gdx/graphics/GraphicsHelpers.java index 36acf6a..8d1a8db 100644 --- a/src/com/blarg/gdx/graphics/GraphicsHelpers.java +++ b/src/com/blarg/gdx/graphics/GraphicsHelpers.java @@ -1,19 +1,19 @@ package com.blarg.gdx.graphics; +import com.badlogic.gdx.graphics.Camera; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.BitmapFont; -import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.Vector3; public final class GraphicsHelpers { - public static void renderCoordinateSystemAxis(ShapeRenderer shapeRenderer, ExtendedSpriteBatch spriteBatch, BitmapFont font, Vector3 origin) { - renderCoordinateSystemAxis(shapeRenderer, spriteBatch, font, origin, 5.0f); + public static void renderCoordinateSystemAxis(ShapeRenderer shapeRenderer, ExtendedSpriteBatch spriteBatch, Camera projectionCamera, BitmapFont font, Vector3 origin) { + renderCoordinateSystemAxis(shapeRenderer, spriteBatch, projectionCamera, font, origin, 5.0f); } - public static void renderCoordinateSystemAxis(ShapeRenderer shapeRenderer, ExtendedSpriteBatch spriteBatch, BitmapFont font, Vector3 origin, float axisLength) { + public static void renderCoordinateSystemAxis(ShapeRenderer shapeRenderer, ExtendedSpriteBatch spriteBatch, Camera projectionCamera, BitmapFont font, Vector3 origin, float axisLength) { shapeRenderer.begin(ShapeRenderer.ShapeType.Line); - spriteBatch.begin(); + spriteBatch.begin(projectionCamera); shapeRenderer.setColor(Color.WHITE); shapeRenderer.line(origin.x, origin.y, origin.z, origin.x + 0.0f, origin.y + axisLength, origin.z + 0.0f); diff --git a/src/com/blarg/gdx/graphics/RenderContext.java b/src/com/blarg/gdx/graphics/RenderContext.java index 8d84820..02d37e1 100644 --- a/src/com/blarg/gdx/graphics/RenderContext.java +++ b/src/com/blarg/gdx/graphics/RenderContext.java @@ -80,7 +80,6 @@ public class RenderContext implements Disposable { public void onPreRender() { spriteBatch.setProjectionMatrix(orthographicCamera.combined); - spriteBatch.setProjectionCamera(perspectiveCamera); spriteBatch.setPixelScale(pixelScaler.getScale()); debugGeometryRenderer.setProjectionMatrix(perspectiveCamera.combined); billboardSpriteBatch.begin(decalBatch, perspectiveCamera);