archive_

Xinerama OpenGL Stereo Rendering

This article describes how to use OpenGL to let your application render in xinerama stereo mode. I am also calling this mode: passive stereo mode, because it renders both views of the scene (for left and right eye) on the screen without at the same time. The description use native OpenGL function calls and provide also at the end a camera class, which can be used for this purpose.

There are some examples how it will looks like in real time (rendered with OpenGL in widescreen mode 16:9)

Here is a list of steps (in my own words) on how to create such stereo rendering view:

precalculate projection matrices for both eyes (left, right) using this parameters: eye separation=0.04 (4 cm), focal length=~1 (1 m). Better you find out what parameters are best for your application. But this should be optimal. The focal length should also be used in the way that it corresponds to the distance of your stereo projectors (or screen) to your eyes.

// Use OpenGL to do calculations for us glLoadIdentity(); glFrustum(left,right,bottom,top,nearPlane,farPlane); glGetFloatv(GL_PROJECTION_MATRIX, asymmetricProjectionLeft); //store projection of left eye

Set camera to the position of the left eyecamera.pos -= camera.rightDirection * eyeSeparatio

render your stuff (NOTE: be careful if you use render to texture, because now you render only on a left half of your framebuffer)

switch the viewport to the right eye (glViewport(1280,0,2560,height))

move your camera again but now to the right (according to what you have done before: restore modelview and move with eyeSeparation/2 or with eyeSeparation, if you moved your camera without pushing the modelview matrix on the stack)

This class also provides some more useful methods: for example frustum culling. You are free to use it in your applications.

I hope this article does help somebody to understand how "passive" stereo mode works. The screenshots were taken from my first OpenGL project "newReality" made for the rendering competition in Computer Graphics I Lecture in the WS04/05 at the University of Saarland, Germany.