package com.haxademic.demo.draw.mapping;

import com.haxademic.core.app.P;
import com.haxademic.core.app.PAppletHax;
import com.haxademic.core.app.config.AppSettings;
import com.haxademic.core.app.config.Config;
import com.haxademic.core.draw.context.OpenGLUtil;
import com.haxademic.core.draw.mapping.PGraphicsKeystone;
import com.haxademic.core.file.FileUtil;

import processing.core.PGraphics;
import processing.opengl.PShader;

public class Demo_PGraphicsKeystone_MappedShader
extends PAppletHax {
	public static void main(String args[]) { arguments = args; PAppletHax.main(Thread.currentThread().getStackTrace()[1].getClassName()); }
		
	protected PGraphics buffer;
	protected PGraphicsKeystone pgKeystone;
	protected boolean drawTestPattern = false;
	protected PShader textureShader;
	
	protected void config() {
		Config.setProperty( AppSettings.WIDTH, 1000 );
		Config.setProperty( AppSettings.HEIGHT, 600 );
		Config.setProperty( AppSettings.FULLSCREEN, true );
	}

	protected void firstFrame() {
		buildDrawingSurface();
	}
	
	protected void buildDrawingSurface() {
		// set applet drawing quality
		P.println(OpenGLUtil.getGlVersion(p.g));
		OpenGLUtil.setTextureQualityHigh(p.g);

		// init mappable main drawing canvas
		buffer = p.createGraphics(p.width, p.height, P.P3D);
		buffer.smooth(AppSettings.SMOOTH_HIGH);
		buffer.noStroke();
		OpenGLUtil.setTextureQualityHigh(buffer);
		
		// map it
		pgKeystone = new PGraphicsKeystone(p, buffer, 12, FileUtil.getPath("text/keystoning/keystone-mapped-shader.txt") );
		
		// load a shader
		textureShader = p.loadShader(FileUtil.getPath("haxademic/shaders/textures/cacheflowe-down-void.glsl"));
	}
	
	protected void drawApp() {
		p.background(0);
		p.noStroke();
		
		// update & draw shader
		textureShader.set("time", (float) p.frameCount * 0.03f);
		buffer.filter(textureShader);
		
		// draw buffer to screen
		if(drawTestPattern == true) pgKeystone.drawTestPattern();
		pgKeystone.update(p.g);
	}	
	
	public void keyPressed() {
		super.keyPressed();
		if(p.key == 't') drawTestPattern = !drawTestPattern;
		if(p.key == 'r') pgKeystone.resetCorners();
	}
	
}


@@ -205,16 +205,59 @@
 Config;%0A
+import com.haxademic.core.debug.DebugView;%0A
 import c
@@ -1426,24 +1426,66 @@
 gh(buffer);%0A
+%09%09DebugView.setTexture(%22buffer%22, buffer);%0A
 %09%09%0A%09%09// map 

Update Demo_PGraphicsKeystone_MappedShader.java