Awefull processing code :
10 millions point at 30fps, video incoming
import javax.media.opengl.GL2;
import java.nio.*;
int nvert = 10000000;
int SIZEOF_INT = Integer.SIZE / 8;
int SIZEOF_FLOAT = Float.SIZE / 8;
final int MINITER = 20;
final int MAXITER = 400;
final float P_ALPHA = 0.1;
final float p = 2.0;
int step, oldstep = 0;
float[][] pts = new float[MAXITER+1][3];
PGL pgl;
IntBuffer vboName;
FloatBuffer vertData;
void setup() {
size(1600, 1200, P3D);
frameRate(2000);
createGeometry();
initVBO();
}
void draw() {
background(0);
translate(width/2, height/2,-1000);
rotateY(frameCount * 0.001);
pgl = beginPGL();
GL2 gl2 = ((PJOGL)pgl).gl.getGL2();
pgl.bindBuffer(PGL.ARRAY_BUFFER, vboName.get(0));
gl2.glEnableClientState(GL2.GL_VERTEX_ARRAY);
gl2.glEnableClientState(GL2.GL_COLOR_ARRAY);
gl2.glVertexPointer(3, PGL.FLOAT, 7 * SIZEOF_FLOAT, 0);
gl2.glColorPointer(4, PGL.FLOAT, 7 * SIZEOF_FLOAT, 3 * SIZEOF_FLOAT);
pgl.drawArrays(PGL.POINTS, 0, nvert);
gl2.glDisableClientState(GL2.GL_VERTEX_ARRAY);
gl2.glDisableClientState(GL2.GL_COLOR_ARRAY);
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
endPGL();
if (frameCount % 60 == 0) println("fps: " + frameRate);
}
void createGeometry() {
float[] temp = new float[nvert * 7];
for (int n = 0; n < nvert; n++) {
boolean needrefresh = false;
while(!needrefresh) {
float x,y,z,nx,ny,nz,r,r2p,th,ph = 0.0;
int iter = 0;
x = random(-2.0,2.0);
y = random(-2.0,2.0);
z = random(-2.0,2.0);
iter = 0;
r = 0.0;
nx = x;
ny = y;
nz = z;
r=sqrt(x*x+y*y+z*z);
th=atan(y/x)*p;
ph=asin(z/r)*p;
while(iter<MAXITER && r<2.0 && nx!=0.0 && r!=0.0 && nx!=-0.0 && r!=-0.0) {
r2p = pow(r,p);
th=atan(ny/nx)*p;
ph=asin(nz/r)*p;
nx=r2p*cos(ph)*cos(th)+x;
ny=r2p*cos(ph)*sin(th)+y;
nz=r2p*sin(ph)+z;
pts[iter][0] = nx;
pts[iter][1] = ny;
pts[iter][2] = nz;
r=sqrt(nx*nx+ny*ny+nz*nz);
iter++;
}
if(r<2.0 && iter > MINITER) {
for(int i = MINITER; i < iter && n < nvert-1 ; i++) {
if(pts[i][0]*pts[i][0] + pts[i][1]*pts[i][1] + pts[i][2]*pts[i][2] < 4) {
// position
temp[n * 7 + 0] = pts[i][0]*(width/2.0);
temp[n * 7 + 1] = pts[i][1]*(width/2.0);
temp[n * 7 + 2] = pts[i][2]*(width/2.0);
// color
temp[n * 7 + 3] = abs(pts[0][0]);
temp[n * 7 + 4] = abs(pts[0][1]);
temp[n * 7 + 5] = abs(pts[0][2]);
temp[n * 7 + 6] = 0.8;
n++;
}
}
needrefresh = true;
}
}
}
vertData = allocateDirectFloatBuffer(nvert * 7);
vertData.rewind();
vertData.put(temp);
vertData.position(0);
}
void initVBO() {
vboName = allocateDirectIntBuffer(1);
pgl = beginPGL();
pgl.genBuffers(1, vboName);
pgl.bindBuffer(PGL.ARRAY_BUFFER, vboName.get(0));
pgl.bufferData(PGL.ARRAY_BUFFER, nvert * 7 * SIZEOF_FLOAT, vertData, PGL.STATIC_DRAW);
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
endPGL();
}
IntBuffer allocateDirectIntBuffer(int n) {
return ByteBuffer.allocateDirect(n * SIZEOF_INT).order(ByteOrder.nativeOrder()).asIntBuffer();
}
FloatBuffer allocateDirectFloatBuffer(int n) {
return ByteBuffer.allocateDirect(n * SIZEOF_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
}