package testing;
import processing.core.PApplet;
import processing.opengl.*;
import codeanticode.glgraphics.*;
import remixlab.proscene.Camera;
public class textureCrop extends PApplet{
public static void main(String[] args) {
if(false) {
PApplet.main(new String[] { "--present", "testing.textureCrop" });
} else{
PApplet.main(new String[] { "testing.textureCrop" });
}
}
/////////////////////////////////////////
GLModel points;
int numPoints = 10000;
float a = 0;
GLGraphicsOffScreen pointsCanvas;
/////////////////////////////////////////
GLModel sprites;
GLTexture spriteTex;
Camera spritesCam;
float[] coords;
float[] colors;
int numSprites = 10000;
GLGraphicsOffScreen spritesCanvas;
int drawElement = 1;
public void setup() {
size(640, 480, GLConstants.GLGRAPHICS);
// Preparing points.
pointsCanvas = new GLGraphicsOffScreen(this, 640, 480);
points = new GLModel(this, numPoints, POINTS, GLModel.DYNAMIC);
points.initColors();
points.beginUpdateVertices();
for (int i = 0; i < numPoints; i++) points.updateVertex(i, 100 * random(-1, 1), 100 * random(-1, 1), 100 * random(-1, 1));
points.endUpdateVertices();
points.beginUpdateColors();
for (int i = 0; i < numPoints; i++) points.updateColor(i, random(0, 255), random(0, 255), random(0, 255), 225);
points.endUpdateColors();
// Preparing sprites.
spritesCanvas = new GLGraphicsOffScreen(this, 640, 480);
spritesCam = new Camera(this);
sprites = new GLModel(this, numSprites, GLModel.POINT_SPRITES, GLModel.DYNAMIC);
sprites.initColors();
spriteTex = new GLTexture(this, dataPath("particle.bmp"));
coords = new float[4 * numSprites];
colors = new float[4 * numSprites];
for (int i = 0; i < numSprites; i++) {
for (int j = 0; j < 3; j++) coords[4 * i + j] = 100.0f * random(-1, 1);
coords[4 * i + 3] = 1.0f;
for (int j = 0; j < 3; j++) colors[4 * i + j] = random(0, 1);
colors[4 * i + 3] = 0.5f;
}
sprites.updateVertices(coords);
sprites.updateColors(colors);
sprites.initTexures(1);
sprites.setTexture(0, spriteTex);
sprites.setPointSize(60);
sprites.setSpriteFadeSize(40);
sprites.setBlendMode(ADD);
}
public void draw(){
// Drawing points.
pointsCanvas.beginDraw();
pointsCanvas.beginGL();
pointsCanvas.clear(0);
points.beginUpdateVertices();
for (int i = 0; i < numPoints; i++) points.displaceVertex(i, random(-0.5f, 0.5f), random(-0.5f, 0.5f), random(-0.5f, 0.5f));
points.endUpdateVertices();
pointsCanvas.translate(width/2,height/2,0);
pointsCanvas.rotateY(a);
pointsCanvas.model(points);
pointsCanvas.endGL();
pointsCanvas.endDraw();
if (drawElement == 3) image(pointsCanvas.getTexture(), 0, 0);
// Drawing sprites.
spritesCanvas.beginDraw();
spritesCanvas.beginGL();
for (int i = 0; i < numSprites; i++)
for (int j = 0; j < 3; j++)
coords[4 * i + j] += random(-0.5f, 0.5f);
sprites.updateVertices(coords);
//spritesCam.feed();
spritesCanvas.translate(width/2, height/2, 400);
spritesCanvas.model(sprites);
spritesCanvas.endGL();
spritesCanvas.endDraw();
if (drawElement == 2) image(spritesCanvas.getTexture(), 0, 0);
if (drawElement == 1) {
pointsCanvas.beginDraw();
pointsCanvas.image(spritesCanvas.getTexture(), mouseX, mouseY, width / 4, height / 4);
pointsCanvas.endDraw();
image(pointsCanvas.getTexture(), 0, 0);
}
}
public void mouseMoved()
{
// spritesCam.dolly(mouseY - pmouseY);
}
public void keyPressed() {
if (key == '1') drawElement = 1;
else if (key == '2') drawElement = 2;
else if (key == '3') drawElement = 3;
}
}