freakTheMighty
YaBB Newbies
Offline
Posts: 24
Stereo Anaglyph: OPENGL off-screen buffer
Jul 8th , 2008, 8:46am
I am looking for examples of people loading a frame into an off-screen buffer using OPENGL. I would like to replicated this code in hardware. Currently I am only getting a handful of frames a second and would like the sketch to run closer to 60fps. This is the code using P3D off-screen buffers. import processing.opengl.*; import saito.objloader.*; PGraphics buffer; PGraphics bufferLeft; PImage img; PImage leftEye; PImage comp; PImage target; PImage grid; OBJModel targets; void setup() { size(1000, 1000, P3D); frameRate(60); // background(255); // Create an off-screen buffer. buffer = createGraphics(1000, 1000, P3D); bufferLeft = createGraphics(1000, 1000, P3D); comp = loadImage("filler2.jpg"); grid = loadImage("fatty_v2.jpg"); targets = new OBJModel(this); // targets.load("targets.obj"); } void draw() { // noStroke(); bufferLeft.beginDraw(); bufferLeft.stroke(100); bufferLeft.background(0); bufferLeft.lights(); bufferLeft.camera(0, 0, 120, 0, 0, 1, 0.0, 1.0, 0.0); bufferLeft.translate(-1,0,-mouseX+100); bufferLeft.image(grid,0,0); // bufferLeft.targets.draw(); bufferLeft.rotateY(radians(45)); bufferLeft.box(45); bufferLeft.translate(-mouseY,-10,50); bufferLeft.box(10); bufferLeft.endDraw(); buffer.beginDraw(); buffer.background(0); buffer.lights(); buffer.camera(0, 0, 120.0, 0, 0, 1, 0.0, 1.0, 0.0); buffer.translate(0,0,-mouseX+100); buffer.image(grid,0,0); //buffer.targets.draw(); buffer.rotateY(radians(45)); buffer.box(45); buffer.translate(-mouseY,-10,50); buffer.box(10); buffer.endDraw(); img = buffer.get(0, 0, buffer.width, buffer.height); for (int i = 0; i <img.width*img.height; i++){ img.pixels[i]=blendColor(img.pixels[i],color(255,0,0), MULTIPLY); } leftEye = bufferLeft.get(0,0,bufferLeft.width, bufferLeft.height); for (int i = 0; i <leftEye.width*leftEye.height; i++){ leftEye.pixels[i]=blendColor(leftEye.pixels[i],color(0,0,255), MULTIPLY); } for (int i = 0; i <leftEye.width*leftEye.height; i++){ comp.pixels[i]=blendColor(leftEye.pixels[i],img.pixels[i], ADD); } image(comp,0,0); println(frameRate); }