OpenGL is a standard API for hardware accelerated 3D rendering, it is supported across a wide range of hardware platforms including most UNIX, Macintosh, and Windows platforms. At the lowest level it is possible to specify the projection in terms of matrices, this means that an OpenGL program can create the offaxis frustums directly. While OpenGL based applications cannot create the high quality rendering possible using a raytracing package, it can be used to create interactive environments. The OpenGL API doesn't address user input devices or the windowing environment. Perhaps the most widely used library for that is GLUT, it will be used here. A quite important component of the windowing system and operating system is getting fullscreen support. For frame sequential stereo with active glasses it isn't so critical (although usually desirable) but for passive stereo using dual displays it is critical since any other windows or decorations will be in one eye and not the other.
Sample code This code "vpacsample.c" and "vpacsample.h" is a minimal but still useful standard C program whose main purpose is to illustrate how to set up n OpenGL application for both frame sequential and dual display stereoscopic projection. Indeed, this example could be used as it is for many projects by simply rewriting the function CreateGeometry(). The source code is reasonably commented but some of the important aspects will be outlined below. Although the sample code supports frame sequenial (active) stereo, only those aspects relevant to the VPAC passive stereo hardware will be discussed here. The glut library is firstly initialised, a window context created, handlers specified for the different modes of user interaction, and finally control is passed to glutMainLoop(). glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutCreateWindow("VPAC Stereo3D Demo"); glutReshapeWindow(camera.screenwidth,camera.screenheight); glutFullScreen(); glutDisplayFunc(HandleDisplay); glutReshapeFunc(HandleReshape); glutKeyboardFunc(HandleKeyboard); glutSpecialFunc(HandleSpecialKeyboard); glutMouseFunc(HandleMouse); glutMotionFunc(HandleMouseMotion); glutPassiveMotionFunc(HandlePassiveMotion); glutVisibilityFunc(HandleVisibility); glutSetCursor(GLUT_CURSOR_NONE); glutIdleFunc(HandleIdle); glutMainLoop(); The offaxis frustum is specified by the following line. This is done once for each eye. glFrustum(left,right,bottom,top,camera.near,camera.far); The drawing of the left eye to the left half of the dual display and the right eye to the right half of the dual display is accomplished with. glViewport(camera.screenwidth/2,0,camera.screenwidth/2,camera.screenheight);and glViewport(0,0,camera.screenwidth/2,camera.screenheight); Finally, the camera is positioned with the following. gluLookAt(camera.vp.x + r.x,camera.vp.y + r.y,camera.vp.z + r.z, camera.vp.x + r.x + camera.vd.x, camera.vp.y + r.y + camera.vd.y, camera.vp.z + r.z + camera.vd.z, camera.vu.x,camera.vu.y,camera.vu.z);and gluLookAt(camera.vp.x - r.x,camera.vp.y - r.y,camera.vp.z - r.z, camera.vp.x - r.x + camera.vd.x, camera.vp.y - r.y + camera.vd.y, camera.vp.z - r.z + camera.vd.z, camera.vu.x,camera.vu.y,camera.vu.z); For complete information on the function calls here please refer to the GLUT users guide, and a reference on OpenGL. The official OpenGL manuals are referred to as the "red" and "blue" book, the former is in the form of a tutorial, the later is a pure reference work documenting each function in the library. Command line argumentsThe sample application doesn't have any required command line arguments, running it with a "-h" option will list the available options and keystrokes. Usage: vpacsample [command line options] Command line options -h this text -f full screen -s active stereo -ss dual screen stereo Mouse buttons left camera rotate shift left camera pan middle camera roll shift middle camera forward, reverse Key Strokes arrow keys camera rotate <,> camera forward, reverse +,- camera zoom in, out [,] camera roll r toggle window recording w capture window ESC,q quit For passive stereo one would normally use "-f" and "-ss". For active stereo one would normally use "-f" and "-s". Without any command like arguments vapcsample will create a non stereo view in a window. This sample application has the ability to create single screen captures or animation capture, see 'r' and 'w' keystroke commands. A window capture in dualstereo mode should look like the following.
|