Adapt existing code for OpenGL stereoscopic rendering?
I'm trying to implement stereoscopic 3d in OpenGL using a side-by-side technique.
I've re开发者_StackOverflow社区ad this article which in great detail explains how to set up the camera for left and right views. It uses a camera model and set up the left and right views using gluLookAt.
However in my case I want to adapt existing code that already set up the projection.
See the following example where "existingcode" represents the code that I cannot make changes to.
//Render left view
// setUpCamera set the gl projection and model matrix
existingcode.setUpCamera()
..
here I want to somehow modify the current gl projection matrix for the left view
..
existingcode.renderScene()
//.. then render right view
Can it be done, perhaps by calling glGetMatrix and modify it somehow?
What you've to do is employ some lens shiftig.
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
stereo_offset = eye * near * parallax_factor / convergence_distance;
glFrustum(stereo_offset + left, stereo_offset + right, bottom, top, near, far);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(eye * parallax_factor * convergence_distance, 0, 0);
/* now use gluLookAt here as this were a normal 2D rendering */
parallax_factor
should be no larger than the ratio of half_eye_distance / screen_width, so the larger the screen gets the smaller the parallax_factor is. A good value for parallax_factor for computer display use is 0.05, for large screens (think cinema) it's something like 0.01
This projection shifting technique is exactly what I used for re-rendering Elephants Dream in stereoscopic 3D, although, since Blenders offline renderer doesn't use OpenGL the code looks a little bit different http://www.youtube.com/watch?v=L-tmaMR1p3w
精彩评论