Chromatic Anaglyph

Any simple way to render chromatic anaglyph stereo images in a running OpenGL program? (not pictures, but moving objects) thx.

I just tried this in my app and it seems to work. You have to fiddle with the camera rotation to get the focus right but you should be able to get the idea from this.

Basically you just do two passes, left eye red mask, right eye blue mask.

  for (int nPass = 0; nPass < 2; nPass++)
  	{
  	switch (nPass)
  		{
  		case 0:
  			glColorMask(1, 0, 0, 0);
  			activecamera->rotation.y -= 1.0f;
  			break;
  		case 1:
  			glColorMask(0, 0, 1, 0);
  			activecamera->position.x += 0.25f;
  			activecamera->position.z -= 0.25f;
  			activecamera->rotation.y += 1.0f;
  			break;
  		}
  	// Render your scene here.
  	}

Edit I should add that the transformation of my camera position is possible because my camera is always looking with -45degs rotation on the yaxis. You basically just need to shift your camera a bit to the right (for the right eye) and then rotate it a bit to bring your target into focus… (Hope that makes sense)

[This message has been edited by rgpc (edited 03-16-2003).]

thx for ur idea, i’m currently working on it.

Originally posted by ffkiller:
Any simple way to render chromatic anaglyph stereo images in a running OpenGL program? (not pictures, but moving objects) thx.

There are several issues you need to address:

o Two pass rendering of your scene -

clear the depth and color buffer. Draw
left eye with a red glColorMask.

Clear the depth buffer, but not the
color. Draw right eye with blue/cyan
glColorMask.

o Ideally you want to covert your RGB
fragments into a grey scale.
glColorMatrix would seem like the most
obvious tool to do this, but alas it
only function for a restricted set of
operations in the OpenGL pipeline and
can’t be reused for general purpose
color modication.

A fragment program could be the thing
to do the color matrix by hand, but
I havn't tried this yet.

You can get still get stereo images
without this step, so I wouldn't loose
too much sleep over it, its more
about quality than an essential.

o You need to modify both the modelview
and projection matrices to generate the
correct eye offsets, just offsetting
the eye and rotating it isn’t correct.
You might get something that “looks”
stereo but it won’t generate the correct
stereo images - distortions will appear
as objects move away from the parallax.

If you want code examples then download the OpenSceneGraph from http://www.openscenegraph.org. All the demos can be run with the -stereo option which by default will render in anaglyphic stereo with the correct modelview and projection offsets. The code to look out for is in src/osgUtil/SceneView.cpp.

Code is in there for quad buffer and split screen stereo as well.

Robert.