package com.blarg.gdx.graphics;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
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, Camera projectionCamera, BitmapFont font, Vector3 origin) {
		renderCoordinateSystemAxis(shapeRenderer, spriteBatch, projectionCamera, font, origin, 5.0f);
	}

	public static void renderCoordinateSystemAxis(ShapeRenderer shapeRenderer, ExtendedSpriteBatch spriteBatch, Camera projectionCamera, BitmapFont font, Vector3 origin, float axisLength) {
		shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
		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);
		spriteBatch.setColor(Color.WHITE);
		spriteBatch.draw(font, origin.x + 0.0f, origin.y + axisLength, origin.z + 0.0f, "UP (+Y)", 0.5f);

		shapeRenderer.setColor(Color.BLACK);
		shapeRenderer.line(origin.x, origin.y, origin.z, origin.x + 0.0f, origin.y + -axisLength, origin.z + 0.0f);
		spriteBatch.setColor(Color.BLACK);
		spriteBatch.draw(font, origin.x + 0.0f, origin.y + -axisLength, origin.z + 0.0f, "DOWN (-Y)", 0.5f);

		shapeRenderer.setColor(Color.GREEN);
		shapeRenderer.line(origin.x, origin.y, origin.z, origin.x + -axisLength, origin.y + 0.0f, origin.z + 0.0f);
		spriteBatch.setColor(Color.GREEN);
		spriteBatch.draw(font, origin.x + -axisLength, origin.y + 0.0f, origin.z + 0.0f, "LEFT (-X)", 0.5f);

		shapeRenderer.setColor(Color.RED);
		shapeRenderer.line(origin.x, origin.y, origin.z, origin.x + axisLength, origin.y + 0.0f, origin.z + 0.0f);
		spriteBatch.setColor(Color.RED);
		spriteBatch.draw(font, origin.x + axisLength, origin.y + 0.0f, origin.z + 0.0f, "RIGHT (+X)", 0.5f);

		shapeRenderer.setColor(Color.CYAN);
		shapeRenderer.line(origin.x, origin.y, origin.z, origin.x + 0.0f, origin.y + 0.0f, origin.z + -axisLength);
		spriteBatch.setColor(Color.CYAN);
		spriteBatch.draw(font, origin.x + 0.0f, origin.y + 0.0f, origin.z + -axisLength, "FORWARD (-Z)", 0.5f);

		shapeRenderer.setColor(Color.YELLOW);
		shapeRenderer.line(origin.x, origin.y, origin.z, origin.x + 0.0f, origin.y + 0.0f, origin.z + axisLength);
		spriteBatch.setColor(Color.YELLOW);
		spriteBatch.draw(font, origin.x + 0.0f, origin.y + 0.0f, origin.z + axisLength, "BACKWARD (+Z)", 0.5f);

		spriteBatch.end();
		shapeRenderer.end();
	}

	/**
	 * Same as {@link Texture#draw}, but also allows drawing the source Pixmap object to an unmanaged Texture object.
	 * Note that doing so will mean that the original texture image data will be restored if the OpenGL context is
	 * restored (any Pixmap's drawn to it will need to be redrawn after the context restore).
	 */
	public static void drawToTexture (Texture destTexture, Pixmap srcPixmap, int x, int y) {
		Gdx.gl.glBindTexture(GL10.GL_TEXTURE_2D, destTexture.getTextureObjectHandle());
		Gdx.gl.glTexSubImage2D(
				GL10.GL_TEXTURE_2D, 0,
				x, y,
				srcPixmap.getWidth(), srcPixmap.getHeight(),
				srcPixmap.getGLFormat(),
				srcPixmap.getGLType(),
				srcPixmap.getPixels()
		);
	}
}

@@ -196,16 +196,54 @@
 nderer;%0A
+import com.badlogic.gdx.math.Matrix4;%0A
 import c
@@ -2643,16 +2643,512 @@
 ();%0A%09%7D%0A%0A
+%09public static void renderGridPlane(ShapeRenderer shapeRenderer, int width, int depth, Matrix4 transform) %7B%0A%09%09shapeRenderer.begin(ShapeRenderer.ShapeType.Line);%0A%09%09shapeRenderer.setTransformMatrix(transform);%0A%09%09shapeRenderer.setColor(Color.WHITE);%0A%0A%09%09for (int i = 0; i %3C= width; ++i)%0A%09%09%09shapeRenderer.line((float)i, 0.0f, 0.0f, (float)i, 0.0f, (float)depth);%0A%09%09for (int i = 0; i %3C= depth; ++i)%0A%09%09%09shapeRenderer.line(0.0f, 0.0f, (float)i, (float)width, 0.0f, (float)i);%0A%0A%09%09shapeRenderer.end();%0A%09%7D%0A%0A
 %09/**%0A%09 *

add debug helper method for rendering wireframe grid planes