package stray.util.render;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;

public class BlendMaskUtil {

	public static void drawAlphaMask(Batch batch, Texture alphamask, float x, float y, float width,
			float height) {
		// disable RGB color, only enable ALPHA to the frame buffer
		Gdx.gl.glColorMask(false, false, false, true);

		// change the blending function for our alpha map
		batch.setBlendFunction(GL20.GL_ONE, GL20.GL_ZERO);

		// draw alpha mask sprite(s)
		batch.draw(alphamask, x, y, width, height);

		// flush the batch to the GPU
		batch.flush();
	}

	public static void drawAlphaMask(Batch batch, Texture alphamask, float x, float y) {
		drawAlphaMask(batch, alphamask, x, y, alphamask.getWidth(), alphamask.getHeight());
	}

	public static void drawSpriteToMask(Batch batch, Texture sprite, int x, int y, int width, int height) {
		// now that the buffer has our alpha, we simply draw the sprite with the
		// mask applied
		Gdx.gl.glColorMask(true, true, true, true);
		batch.setBlendFunction(GL20.GL_DST_ALPHA, GL20.GL_ONE_MINUS_DST_ALPHA);

		// The scissor test is optional, but it depends
		Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST);
		Gdx.gl.glScissor(x, y, width, height);

		// draw our sprite to be masked
		batch.draw(sprite, 0, 0, 250, 250);

		// remember to flush before changing GL states again
		batch.flush();

		// disable scissor before continuing
		Gdx.gl.glDisable(GL20.GL_SCISSOR_TEST);
	}
	
	public static void drawSpriteToMask(Batch batch, Texture sprite, int x, int y){
		drawSpriteToMask(batch, sprite, x, y, sprite.getWidth(), sprite.getHeight());
	}

}

@@ -867,32 +867,28 @@
 ic void 
-draw
+begin
 Sprite
-ToMask
+s
 (Batch b
@@ -895,61 +895,8 @@
 atch
-, Texture sprite, int x, int y, int width, int height
 ) %7B%0A
@@ -1034,16 +1034,16 @@
  true);%0A
+
 %09%09batch.
@@ -1111,535 +1111,8 @@
 HA);
-%0A%0A%09%09// The scissor test is optional, but it depends%0A%09%09Gdx.gl.glEnable(GL20.GL_SCISSOR_TEST);%0A%09%09Gdx.gl.glScissor(x, y, width, height);%0A%0A%09%09// draw our sprite to be masked%0A%09%09batch.draw(sprite, 0, 0, 250, 250);%0A%0A%09%09// remember to flush before changing GL states again%0A%09%09batch.flush();%0A%0A%09%09// disable scissor before continuing%0A%09%09Gdx.gl.glDisable(GL20.GL_SCISSOR_TEST);%0A%09%7D%0A%09%0A%09public static void drawSpriteToMask(Batch batch, Texture sprite, int x, int y)%7B%0A%09%09drawSpriteToMask(batch, sprite, x, y, sprite.getWidth(), sprite.getHeight());
 %0A%09%7D%0A

Simplify sprite rendering