'advanced blending' of Photoshop? (for making 3D image)

I am trying to make 3d image by using 2 webcams now based on below manual.
http://www.opentutorial.com/Make-3d-images

Based on the tutorial, "Red’ channel need to be turned off while blending. I have test with glColor3F to take out red channel but it just removed it but don’t blend as the tutorial.

glColor3f( 0.0f, 1.0f, 1.0f );

Could you share your idea?

If there is other way to make 3d image, it’s quite welcome

I would do this on a per-pixel level by writing a loop that goes through the pixel array and copies the components as necessary. Something like:

  
  
unsigned char[] left = leftImage.getPixels();  
unsigned char[] right = rightImage.getPixels();  
unsigned char[] result = resultImage.getPixels();  
int length = left.getWidth() * left.getHeight();  
for(int i = 0; i < length; i++) {  
  result[i++] = left[i];  
  result[i++] = (left[i] + right[i]) / 2;  
  result[i++] = right[i];  
}  
result.update();  
  

But you can probably do it with one glBlendFunc call too :slight_smile:

I’ve never tried to do anaglyph stereo, so don’t know anything about it, but I have heard lots of nightmare stories from lots of people trying to do it with opengl. Looking at Kyles code though, if that is what you want to do it is very doable with opengl. Two methods come to mind:

  1. Write a fragment shader that takes two textures, and simply outputs left.r, (left.g+right.g)/2, right.b. This is probably the most efficient, and most flexible way. You can probably already find this shader online

  2. Turn on additive blending, render the left image with glColor(1, 0.5, 0) and then render the right image with glColor(0, 0.5, 1); This method is so simple I’m questioning whether it would work or not - but it seems to me that it would do exactly what Kyle’s code is doing.

Hope that helps.

Yeah, this is what I was thinking of. I’m pretty sure this is the way I saw Golan do it at OF lab with his dancing manekins.

Thank you guys for all answers. Unfortunately it doesn’t generate correct images for 3D vision. After couple of different setting, I found a result making reasonable results.

Here is codes I set.

  
  
int length = videoW*videoH*3;  
for(int i = 0; i < length; i+=3)   
{  
	resultPixels[i] = rightPixels[i];  
	resultPixels[i+1] = (leftPixels[i+1]*9 + rightPixels[i+1]) / 10;  
	resultPixels[i+2] = (leftPixels[i+2]*9 + rightPixels[i+2]) / 10;  
}  
  

Even thought I used different web cams but they works well.

Hi thedofl!!

maybe the right solution is using glColorMask as many openGL tutorials said, and I think it so much easy and clear to implemet.

you can take a look here, maybe it helps you:

http://local.wasp.uwa.edu.au/~pbourke/t-…-/anaglyph/

I was playing a bit with the example of the page and I got this:

[attachment=0:3a78pn5f]anaglyph red-cyan.jpg[/attachment:3a78pn5f]

and the OF code:

  
  
         //IN SETUP  
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);  
	glEnable(GL_DEPTH_TEST);  
  
        //IN DRAW  
  
        glDrawBuffer(GL_BACK);  
	glReadBuffer(GL_BACK);  
	  
	/* Clear things */  
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  
      
    glColorMask(GL_TRUE,GL_FALSE,GL_FALSE,GL_TRUE);  
	imgRight.draw(0,0);  
	  
	glFlush();  
	glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);   
	  
  
	glDrawBuffer(GL_BACK);  
	glClear(GL_DEPTH_BUFFER_BIT);  
	glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);  
	glColorMask(GL_FALSE,GL_TRUE,GL_TRUE,GL_TRUE);  
  
	imgLeft.draw(0,0);  
	  
	glFlush();  
	glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);   
  

I hope it helps!

cheers!!

![](http://forum.openframeworks.cc/uploads/default/683/anaglyph red-cyan.jpg)