# Copyright (c) 2001, Stanford University # All rights reserved # # See the file LICENSE.txt for information on redistributing this software. # This configuration forces a (monoscopic) GL app to run in # quad-buffered (aka "active") stereo mode. That is, we'll force the # app to render each frame twice and inject calls to # glDrawBuffer(GL_LEFT) and glDrawBuffer(GL_RIGHT) automatically. # # Key things for tilesort configuration: # - set force_quad_buffering = 1 # - set stereo_mode = "CrystalEyes" XXX more??? # - set servers' view_matrix = left eye's viewing transformation matrix # - set servers' projection_matrix = left eye's projection transformation matrix # - set servers' right_view_matrix = right eye's viewing transformation matrix # - set servers' right_projection_matrix = right eye's projection transformation matrix # import sys sys.path.append( "../server" ) from mothership import * import crmatrix Demo = "stereocube" StereoMode = "SideBySide" CrossEyed = 0 # set to 1 if you want to do cross-eyed side-by-side stereo # parse args args = sys.argv[1:] # copy list, skipping program name while len(args) > 0: arg = args[0] if arg == "-mode": StereoMode = args[1] args = args[2:] # chop off first 2 args elif arg[0] != "-": Demo = arg print "--> Note: you may have to tweak the config's stereo parameters!" args = args[1:] # chop off first arg else: print "Unknown option %s" % arg sys.exit(1) print "--> Running %s in forced quad-buffer mode." % Demo print "--> Stereo mode is %s" % StereoMode if Demo == "stereocube": # Parameters copied from sterecube.c demo EyeSep = 0.3 Width = 12.0 Hither = 1.0 Yon = 25.0 FocalDist = 5.0 elif Demo == "city": EyeSep = 0.3 Width = 12.0 Hither = 1.0 Yon = 250.0 FocalDist = 5.0 elif Demo == "atlantis": # atlantis uses some really big numbers! # not a great demo for stereo, either. EyeSep = 0.3 Width = 2000.0 Hither = 10000.0 Yon = 400000.0 FocalDist = Hither * 2.0 elif Demo == "paraview": # Note: seems to work with "blow.vtk" dataset EyeSep = 2.0 Width = 40.0 Hither = 120.0 Yon = 180.0 FocalDist = 150 else: # some default values that seem to work for some Mesa demos EyeSep = 0.3 # half of interocular distance Width = 2.0 # frustum width at FocalDist Hither = 1.0 # near clip plane distance from eye Yon = 250.0 # far clip plane distance from eye FocalDist = 4.0 # focal distance for stereo imaging # If doing SideBySide stereo, we normally are showing the "defocussed" # stereo pair. If you'd rather do "cross-eyed" stereo, need to reverse # the left/right projections. Easily done by negating the eye separation. if StereoMode == "SideBySide" and CrossEyed: EyeSep = -EyeSep cr = CR() cr.MTU( 1024*1024 ) if StereoMode == "SideBySide": TileWidth = 400 TileHeight = 200 Aspect = 1.0 else: TileWidth = 400 TileHeight = 400 Aspect = float(TileWidth) / float(TileHeight) # Setup tilesort SPU tilesortspu = SPU("tilesort") tilesortspu.Conf('bucket_mode', 'Test All Tiles') ##'Uniform Grid') tilesortspu.Conf('force_quad_buffering', 1) tilesortspu.Conf('stereo_mode', StereoMode) # Setup app node w/ tilesort SPU clientnode = CRApplicationNode( ) clientnode.StartDir( crbindir ) clientnode.SetApplication( Demo ) clientnode.AddSPU( tilesortspu ) cr.AddNode( clientnode ) # Setup server node with render SPU renderspu = SPU( 'render' ) renderspu.Conf( 'window_geometry', [0, 0, TileWidth, TileHeight] ) if StereoMode == 'CrystalEyes': renderspu.Conf('default_visual', 'rgb, z, double, stereo') servernode = CRNetworkNode( ) servernode.AddTile( 0, 0, TileWidth, TileHeight ) servernode.Conf('optimize_bucket', 0) # just to be safe servernode.AddSPU( renderspu ) cr.AddNode( servernode ) tilesortspu.AddServer( servernode, protocol='tcpip', port=7000 ) # Need to specify the left and right view/projection matrices Width = 0.5 * Width # want half width below s = Hither / FocalDist top = s * Width bottom = -top for eye in range(2): # View matrix v = crmatrix.CRMatrix() if eye == 0: v.Translate(+EyeSep, 0, 0) else: v.Translate(-EyeSep, 0, 0) # Projection matrix p = crmatrix.CRMatrix() if eye == 0: left = s * ((Width * -Aspect) - EyeSep); right = s * ((Width * Aspect) - EyeSep); else: left = s * (Width * -Aspect + EyeSep); right = s * (Width * Aspect + EyeSep); p.Frustum(left, right, bottom, top, Hither, Yon) if eye == 0: servernode.Conf('view_matrix', v.ToList()) servernode.Conf('projection_matrix', p.ToList()) else: servernode.Conf('right_view_matrix', v.ToList()) servernode.Conf('right_projection_matrix', p.ToList()) cr.Go()