We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Stereo Anaglyph: OPENGL off-screen buffer
Page Index Toggle Pages: 1
Stereo Anaglyph: OPENGL off-screen buffer (Read 3236 times)
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);
}

Re: Stereo Anaglyph: OPENGL off-screen buffer
Reply #1 - Jul 8th, 2008, 10:28am
 
I think you can probably do it without any offscreen buffers in OpenGL with glColorMask ( http://www.cs.rutgers.edu/~decarlo/428/gl_man/colormask.html ), e.g.

Code:

void draw()
{
 //setup camera for left eye
 GL gl=((PgraphicsOpenGL)g).beginGL();
 gl.glColorMask(true,false,false,true);
 //draw scene
 ((PgraphicsOpenGL)g).endGL();
 //setup camera for right eye
 gl=((PgraphicsOpenGL)g).beginGL();
 gl.glColorMask(false,true,true,true);
 //draw scene
 ((PgraphicsOpenGL)g).endGL();  
}
Re: Stereo Anaglyph: OPENGL off-screen buffer
Reply #2 - Jul 10th, 2008, 2:29am
 
This worked really well, the fps shot up over 100.  I don't understand the difference though of using processing methods like box(1); inside and outside of the gl.begin() and end() block.  They seem to be drawn in a different world space.

When I took them out of the block they were still tinted.  I don't understand how this code knows which geometry to colorize and how to overlay it with the other block.
Re: Stereo Anaglyph: OPENGL off-screen buffer
Reply #3 - Jul 10th, 2008, 10:44am
 
The code jsut says "from this point, until I tell you differently, only allow red colour to be drawn", even a endGL() doesn't stop that from being true, but it's necessary for processing object to be drawn differently, or they get transformed twice, once by processing, and once by OpenGL.
Re: Stereo Anaglyph: OPENGL off-screen buffer
Reply #4 - Jul 11th, 2008, 7:13am
 
I would like to make color anaglyphs.  This website shows the math involved, just some multiplication.

http://3dtv.at/Knowhow/AnaglyphComparison_en.aspx

The half color and optimized color examples are among the most convincing anaglyphs I've seen on the internet.

Your solution is nice and simple, but it doesn't allow for additional processing to the image.  I am having trouble understanding the full OpenGL implementation described in "OpenGL Offscreen buffer for glow effect", and am so unfortunate to own a macbookPro unsupported by the glTexture library.

I sense I am close, so I'll keep reading the forums over until I understand it and post what I figure out.  And of course, if you have any idea or can point me in the right direction, drop them here like they are hot.
Re: Stereo Anaglyph: OPENGL off-screen buffer
Reply #5 - Jul 22nd, 2008, 11:20am
 
you can multiply pixel values using opengl FFP or even better use a shader to do that for you..
Re: Stereo Anaglyph: OPENGL off-screen buffer
Reply #6 - Jul 25th, 2008, 2:58am
 
What is an FFP?  It must to expand to something...  A shader would seem to be the way to go, so that is on my list of things to learn.  

I have had more success with the ColorMask() method.  A good deal of the ghosting I was seeing turned out to be because my glasses were red cyan not red blue.  After fixing that things go a lot better.
Re: Stereo Anaglyph: OPENGL off-screen buffer
Reply #7 - Jul 26th, 2008, 3:26pm
 
by ffp i meant fixed pipeline. you can use blend modes to multiply pixels or use shaders to do it easier.
Re: Stereo Anaglyph: OPENGL off-screen buffer
Reply #8 - Sep 11th, 2008, 10:09pm
 
In this example of a GLTetureFilter, the filter is given a source and a destination.  If I am to implement a half-color anaglyph filter than I need to have two source images (left and right).

Does anyone know how to code this?

Thank you.

import processing.opengl.*;
import codeanticode.glgraphics.*;

size(200, 200, GLConstants.GLGRAPHICS);
 
// Initializing source and destination textures.
GLTexture texSrc = new GLTexture(this, "image.jpg");
GLTexture texDest = new GLTexture(this, texSrc.width, texSrc.height);

// Initializing filter.
GLTextureFilter blur = new GLTextureFilter(this, "blur.xml");

// Applying the filter on texture texSrc
// and writing the result to texDest.
texSrc.filter(blur, texDest);

// Drawing the resulting image.
image(texDest, 0, 0, width, height);
Page Index Toggle Pages: 1