package com.processing.buffertest;
import java.util.Stack;
import processing.core.PApplet;
import processing.core.PFont;
import processing.core.PGraphicsAndroid3D;
import processing.core.PImage;
import android.util.Log;
import android.view.MotionEvent;
public class OffscreenBufferTestActivity extends PApplet {
String TAG = "TestApplet";
int pointerCount = 0;
PFont font;
PGraphicsAndroid3D buff;
Stack<Runnable> runners = new Stack<Runnable>();
final PApplet p = this;
int bg = 0;
PImage tempImage;
public void setup() {
buff = (PGraphicsAndroid3D) createGraphics(screenWidth, screenHeight, P3D);
}
public String sketchRenderer() {
return P3D;
}
public void draw() {
buff.beginDraw();
buff.background(0);
buff.fill(255, 0, 0);
buff.rect(0, 0, screenWidth / 2, screenHeight / 2);
buff.endDraw();
background(255);
fill(0, 0, 255);
// rect(0, 0, screenWidth / 2, screenHeight / 2);
if (!runners.empty()) {
runners.pop().run();
}
}
static public void main(String args[]) {
PApplet.main(new String[] { "Test" });
}
public boolean surfaceTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
final int mx = (int) event.getX();
final int my = (int) event.getY();
runners.push(new Runnable() {
@Override
public void run() {
// buff.loadPixels();
// int id = buff.pixels[my*screenWidth+mx];
int pixelColor = get(mx, my);
Log.d("Primary", "Primary get() = " + p.get(mx, my));
Log.d("Buffer", "Buffer get() = " + pixelColor + " motionX = " + mx + " motionY = " + my);
}
});
} else if (event.getAction() == MotionEvent.ACTION_UP) {
}
return super.surfaceTouchEvent(event);
}
}
thanks for any help