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.
Page Index Toggle Pages: 1
OpenGL blending (Read 2392 times)
OpenGL blending
Aug 8th, 2009, 9:05am
 
Hello,

I just started to work with OpenGL and now I need some help.

I try to blend two camera-images together, but I don't know how.

Code:
gl.glViewport(0, 0, width, height);
box(50);
gl.glViewport(0, 0, width, height);
box(100);

That's how I created two seperate images, now the second should blend over the first like the "Overlay"-Blend-Mode in photoshop. How can I do this?

I hope you can help.

Yours,

Electronix
Re: OpenGL blending
Reply #1 - Aug 8th, 2009, 3:50pm
 
If you want two nested semitransparent cubes, I suggest textures, with the method I mentioned in a recent "GL textures 101" question.  Not sure why you'd use glViewport, though.  Also, you'll have trouble with box() if you want to use pure GL, since that's a Processing command.
--Ben
Re: OpenGL blending
Reply #2 - Aug 9th, 2009, 4:40am
 
Hello,

I want to make a 3D image. I change the camera position between the Viewpoints and the first Image is red and the other one blue. Now I want that they blend this.

For the resulting image, just the red-channel from the first and the green- and blue-channel from the second image should be taken. How can I do something like that?

By the way, what is the OpenGL-command for a box?

Yours,

Electronix
Re: OpenGL blending
Reply #3 - Aug 9th, 2009, 8:14am
 
Hi -- if I understand correctly, you want to make a stereoscopic image that can be viewed with 3-D glasses, starting with a flat image?  You can "fake" this by separating the channels as you describe, and varying the tilt between the two images, but I don't know how cubes will help you (flat, tilted images would do the same thing).

That said, a cube in pure openGL can most easily be constructed from 6 quads, although triangle_strips tend to be slightly faster (same points, in a Z pattern rather than a |_| pattern).  Look up "gl cube," "gl trangle_strip", or "gl quads."

Textures are nice for fast rendering, and if you want them to be moving around in 3D and blending, I would check those out.  Otherwise I'm not sure why you'd use straight GL rather than Pimage, or P5's texture functions.

I think glLookat is enough to change your camera position; if I understand the viewport function, it's just for changing the size of the resulting image.  If not I'd be happy to be corrected...

--Ben
Re: OpenGL blending
Reply #4 - Aug 9th, 2009, 9:14am
 
Ah that's what you're trying to do.

You don't need the gl.glviewport commands to do such a thing, that's for limiting drawing to just one area of screen.

There's a magic bit of code:

Code:

gl.glColorMask(true,false,false,true); // only allow red/alpha channel writing.

// Draw one view

gl.glClear(GL.GL_DEPTH_BUFFER_BIT); // clear the depth buffer so you can draw the 2nd image
gl.glColorMask(false,true,true,true); //blue/green and alpha

//draw other view

gl.glColorMask(true,true,true,true); //reset things.
Re: OpenGL blending
Reply #5 - Aug 13th, 2009, 3:34am
 
Hi,

I think that Ben slightly misunderstood my intention, but thanks for your help.

But JohnG, thats exactly what I needed! It really works.
Thanks a lot!

Greetings,

Electronix
Re: OpenGL blending
Reply #6 - Dec 30th, 2009, 9:20pm
 
Keep in mind you don't actually want to be using 'Blue' as a colour (as stated by John in his code).

You need the colour which is at the opposite end of the Additive colour wheel to Red, which is Cyan (Blue and Green).
Your glasses will most likely also have Red/Cyan tinted lenses as well, unless they are really old.

The other type of glasses available are Green/Magenta (colours that at also at the opposite end of the wheel).
Page Index Toggle Pages: 1