#!/usr/bin/env python # Copyright (C) 2002-2003 Gideon May (gideon@computer.org) # # Permission to copy, use, sell and distribute this software is granted # provided this copyright notice appears in all copies. # Permission to modify the code and to distribute modified code is granted # provided this copyright notice appears in all copies, and a notice # that the code was modified is included with the copyright notice. # # This software is provided "as is" without express or implied warranty, # and with no claim as to its suitability for any purpose. # -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield # # This application is open source and may be redistributed and/or modified # freely and without restriction, both in commericial and non commericial applications, # as long as this copyright notice is maintained. # # This application is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # from PyOSG import Producer from PyOSG import osg from PyOSG import osgDB from PyOSG import osgGA from PyOSG import osgProducer from PyOSG import osgUtil import OpenGL import sys TWO_SEPARATE_WINDOWS = 1 keep = [] def BuildConfig(): global keep if TWO_SEPARATE_WINDOWS: rs1 = Producer.RenderSurface() keep.append(rs1) rs1.setScreenNum(0) rs1.setWindowName("osgwindows") #rs1.useBorder(false) rs1.setWindowRectangle(0,0,640,480) camera1 = Producer.Camera() keep.append(camera1) camera1.setRenderSurface(rs1) camera1.setOffset( 1.0, 0.0 ) rs2 = Producer.RenderSurface() keep.append(rs2) rs2.setScreenNum(0) rs2.setWindowName("osgwindows") #rs2.useBorder(false) rs2.setWindowRectangle(640,0,640,480) camera2 = Producer.Camera() keep.append(camera2) camera2.setRenderSurface(rs2) camera2.setOffset( -1.0, 0.0 ) rs1.setInputRectangle( Producer.RenderSurface.InputRectangle(0.0,0.5,0.0,1.0)) rs2.setInputRectangle( Producer.RenderSurface.InputRectangle(0.5,1.0,0.0,1.0)) ia = Producer.InputArea() keep.append(ia) ia.addRenderSurface(rs1) ia.addRenderSurface(rs2) cfg = Producer.CameraConfig() keep.append(cfg) cfg.addCamera("Camera 1",camera1) cfg.addCamera("Camera 2", camera2) cfg.setInputArea(ia) else: # one window with four camera's. pcam1 = Producer.Camera() pcam1.setProjectionRectangle (0.0, 0.5, 0.5, 1.0) pcam2 = Producer.Camera() pcam2.setRenderSurface (pcam1.getRenderSurface ()) pcam2.setProjectionRectangle (0.5, 1.0, 0.5, 1.0) pcam3 = Producer.Camera() pcam3.setRenderSurface (pcam1.getRenderSurface ()) pcam3.setProjectionRectangle (0.0, 0.5, 0.0, 0.5) pcam4 = Producer.Camera() pcam4.setRenderSurface (pcam1.getRenderSurface ()) pcam4.setProjectionRectangle (0.5, 1.0, 0.0, 0.5) cfg = Producer.CameraConfig() cfg.addCamera("Camera 1",pcam1) cfg.addCamera("Camera 2",pcam2) cfg.addCamera("Camera 3",pcam3) cfg.addCamera("Camera 4",pcam4) return cfg def main(argv): # use an ArgumentParser object to manage the program arguments. arguments = osg.ArgumentParser(argv) # set up the usage document, in case we need to print out how to use this program. arguments.getApplicationUsage().setApplicationName(arguments.getApplicationName()) arguments.getApplicationUsage().setDescription(arguments.getApplicationName()+" is the example which demonstrate hows to set up programitically a Producer.CameraConfig and use it to set up multiple window views.") arguments.getApplicationUsage().setCommandLineUsage(arguments.getApplicationName()+" [options] filename ...") arguments.getApplicationUsage().addCommandLineOption("-h or --help","Display this information") # construct the viewer. viewer = osgProducer.Viewer(BuildConfig()) # set up the value with sensible default event handlers. viewer.setUpViewer(osgProducer.Viewer.STANDARD_SETTINGS) # get details on keyboard and mouse bindings used by the viewer. viewer.getUsage(arguments.getApplicationUsage()) # if user request help write it out to cout. if arguments.read("-h") or arguments.read("--help"): arguments.getApplicationUsage().write() return 1 # any option left unread are converted into errors to write out later. arguments.reportRemainingOptionsAsUnrecognized() # report any errors if they have occured when parsing the program aguments. if arguments.errors(): arguments.writeErrorMessages() return 1 if arguments.argc()<=1: arguments.getApplicationUsage().write(osg.ApplicationUsage.COMMAND_LINE_OPTION) return 1 # read the scene from the list of file specified commandline args. loadedModel = osgDB.readNodeFiles(arguments) # if no model has been successfully loaded report failure. if not loadedModel : print arguments.getApplicationName(), ": No data loaded" return 1 # optimize the scene graph, remove rendundent nodes and state etc. optimizer = osgUtil.Optimizer() optimizer.optimize(loadedModel) # set the scene to render viewer.setSceneData(loadedModel) # create the windows and run the threads. viewer.realize() while not viewer.done(): # wait for all cull and draw threads to complete. viewer.sync() # update the scene by traversing it with the the update visitor which will # call all node update callbacks and animations. viewer.update() # fire off the cull and draw traversals of the scene. viewer.frame() # wait for all cull and draw threads to complete before exit. viewer.sync() return 0 if __name__ == "__main__": main(sys.argv)