I'm trying to create an anaglyph. I've been playing with glColorMask, but I can't figure out the perspective stuff with the camera. I can separate the colors, I don't know how to shift it the images for each eye. Could someone help me out.
Code:import peasy.*;
import processing.opengl.*;
import javax.media.opengl.GL;
PeasyCam cam;
PGraphicsOpenGL pgl;
GL gl;
float fov;
float cameraZ;
void setup() {
size(500,500, OPENGL);
cam = new PeasyCam(this, 100);
cam.setMinimumDistance(50);
cam.setMaximumDistance(500);
pgl = (PGraphicsOpenGL) g;
gl = pgl.gl;
fov = PI/3.0;
cameraZ = (height/2.0) / tan(fov/2.0);
}
void draw() {
background(0);
for(int x3d = 0; x3d < 2; x3d++) {
if(x3d == 0) {
println(fov);
// translate(1,1,1);
perspective(fov, float(width)/float(height),
cameraZ/10.0, cameraZ*10.0);
gl.glColorMask(true, false, false, true);
}
else {
//translate(-1,-1,-1);
perspective(fov-.03, float(width)/float(height),
cameraZ/10.0, cameraZ*10.0);
gl.glColorMask(false, true, true, true);
}
pushMatrix();
fill(255,0,0);
box(30);
translate(0,0,20);
fill(0,0,255);
box(5);
translate(0,20,-20);
fill(0,255,0);
box(5);
translate(20,-20,0);
fill(255,255,0);
box(5);
translate(-40,0,0);
fill(255,128,0);
box(5);
translate(20,-20,0);
fill(128,0,255);
box(5);
translate(0,20,-20);
fill(128,128,128);
box(5);
popMatrix();
}
gl.glColorMask(true, true, true, true);
}