Example #1
0
class MainWindow (QWidget) :
    MainWindow()
        traits = osg.GraphicsContext.Traits(osg.DisplaySettings.instance())
        traits.width = width()
        traits.height = height()
        traits.doubleBuffer = True
        graphicsWindow = osgQt.GraphicsWindowQt(traits)

        grid = QGridLayout()
        grid.setMargin(0)
        grid.addWidget(graphicsWindow.getGLWidget(), 0, 0)
        setLayout(grid)

        _viewer.setThreadingModel(osgViewer.Viewer.SingleThreaded)

        camera = _viewer.getCamera()
        camera.setGraphicsContext(graphicsWindow)
        camera.setViewport(osg.Viewport(0, 0, width(), height()))

        startTimer(10)
def setDomeFaces(viewer, arguments):

    

    wsi = osg.GraphicsContext.getWindowingSystemInterface()
    if  not wsi :
        osg.notify(osg.NOTICE), "Error, no WindowSystemInterface available, cannot create windows."
        return

    unsigned int width, height
    wsi.getScreenResolution(osg.GraphicsContext.ScreenIdentifier(0), width, height)

    while arguments.read("--width",width) : 
    while arguments.read("--height",height) : 

    traits = osg.GraphicsContext.Traits()
    traits.x = 0
    traits.y = 0
    traits.width = width
    traits.height = height
    traits.windowDecoration = True
    traits.doubleBuffer = True
    traits.sharedContext = 0

    gc = osg.GraphicsContext.createGraphicsContext(traits)
    if  not gc :
        osg.notify(osg.NOTICE), "GraphicsWindow has not been created successfully."
        return


    center_x = width/2
    center_y = height/2
    camera_width = 256
    camera_height = 256

    # front face
        camera = osg.Camera()
        camera.setGraphicsContext(gc)
        camera.setViewport(osg.Viewport(center_x-camera_width/2, center_y, camera_width, camera_height))

        buffer =  GL_BACK if (traits.doubleBuffer) else  GL_FRONT
        camera.setDrawBuffer(buffer)
        camera.setReadBuffer(buffer)

        viewer.addSlave(camera, osg.Matrixd(), osg.Matrixd())

    # top face
        camera = osg.Camera()
        camera.setGraphicsContext(gc)
        camera.setViewport(osg.Viewport(center_x-camera_width/2, center_y+camera_height, camera_width, camera_height))
        buffer =  GL_BACK if (traits.doubleBuffer) else  GL_FRONT
        camera.setDrawBuffer(buffer)
        camera.setReadBuffer(buffer)

        viewer.addSlave(camera, osg.Matrixd(), osg.Matrixd.rotate(osg.inDegrees(-90.0), 1.0,0.0,0.0))

    # left face
        camera = osg.Camera()
        camera.setGraphicsContext(gc)
        camera.setViewport(osg.Viewport(center_x-camera_width*3/2, center_y, camera_width, camera_height))
        buffer =  GL_BACK if (traits.doubleBuffer) else  GL_FRONT
        camera.setDrawBuffer(buffer)
        camera.setReadBuffer(buffer)

        viewer.addSlave(camera, osg.Matrixd(), osg.Matrixd.rotate(osg.inDegrees(-90.0), 0.0,1.0,0.0))

    # right face
        camera = osg.Camera()
        camera.setGraphicsContext(gc)
        camera.setViewport(osg.Viewport(center_x+camera_width/2, center_y, camera_width, camera_height))
        buffer =  GL_BACK if (traits.doubleBuffer) else  GL_FRONT
        camera.setDrawBuffer(buffer)
        camera.setReadBuffer(buffer)

        viewer.addSlave(camera, osg.Matrixd(), osg.Matrixd.rotate(osg.inDegrees(90.0), 0.0,1.0,0.0))

    # bottom face
        camera = osg.Camera()
        camera.setGraphicsContext(gc)
        camera.setViewport(osg.Viewport(center_x-camera_width/2, center_y-camera_height, camera_width, camera_height))
        buffer =  GL_BACK if (traits.doubleBuffer) else  GL_FRONT
        camera.setDrawBuffer(buffer)
        camera.setReadBuffer(buffer)

        viewer.addSlave(camera, osg.Matrixd(), osg.Matrixd.rotate(osg.inDegrees(90.0), 1.0,0.0,0.0))

    # back face
        camera = osg.Camera()
        camera.setGraphicsContext(gc)
        camera.setViewport(osg.Viewport(center_x-camera_width/2, center_y-2*camera_height, camera_width, camera_height))
        buffer =  GL_BACK if (traits.doubleBuffer) else  GL_FRONT
        camera.setDrawBuffer(buffer)
        camera.setReadBuffer(buffer)

        viewer.addSlave(camera, osg.Matrixd(), osg.Matrixd.rotate(osg.inDegrees(-180.0), 1.0,0.0,0.0))

    viewer.getCamera().setProjectionMatrixAsPerspective(90.0, 1.0, 1, 1000.0)

    viewer.assignSceneDataToCameras()

def createDomeDistortionMesh(origin, widthVector, heightVector, arguments):

    
    sphere_radius = 1.0
    if arguments.read("--radius", sphere_radius) : 

    collar_radius = 0.45
    if arguments.read("--collar", collar_radius) : 

    center = osg.Vec3d(0.0,0.0,0.0)
    eye = osg.Vec3d(0.0,0.0,0.0)

    distance = sqrt(sphere_radius*sphere_radius - collar_radius*collar_radius)
    if arguments.read("--distance", distance) : 

    centerProjection = False

    projector = eye - osg.Vec3d(0.0,0.0, distance)


    osg.notify(osg.NOTICE), "Projector position = ", projector
    osg.notify(osg.NOTICE), "distance = ", distance


    # create the quad to visualize.
    geometry = osg.Geometry()

    geometry.setSupportsDisplayList(False)

    xAxis = osg.Vec3(widthVector)
    width = widthVector.length()
    xAxis /= width

    yAxis = osg.Vec3(heightVector)
    height = heightVector.length()
    yAxis /= height

    noSteps = 50

    vertices = osg.Vec3Array()
    texcoords = osg.Vec3Array()
    colors = osg.Vec4Array()

    bottom = origin
    dx = xAxis*(width/((float)(noSteps-1)))
    dy = yAxis*(height/((float)(noSteps-1)))

    screenCenter = origin + widthVector*0.5 + heightVector*0.5
    screenRadius = heightVector.length() * 0.5

    int i,j
    if centerProjection :
        for(i=0i<noSteps++i)
            cursor = bottom+dy*(float)i
            for(j=0j<noSteps++j)
                delta = osg.Vec2(cursor.x() - screenCenter.x(), cursor.y() - screenCenter.y())
                theta = atan2(-delta.y(), delta.x())
                phi = osg.PI_2 * delta.length() / screenRadius
                if phi > osg.PI_2 : phi = osg.PI_2

                phi *= 2.0

                # osg.notify(osg.NOTICE), "theta = ", theta, "phi=", phi

                texcoord = osg.Vec3(sin(phi) * cos(theta),
                                   sin(phi) * sin(theta),
                                   cos(phi))

                vertices.push_back(cursor)
                colors.push_back(osg.Vec4(1.0,1.0,1.0,1.0))
                texcoords.push_back(texcoord)

                cursor += dx
            # osg.notify(osg.NOTICE)
    else:
def setDomeCorrection(viewer, arguments):

    

    wsi = osg.GraphicsContext.getWindowingSystemInterface()
    if  not wsi :
        osg.notify(osg.NOTICE), "Error, no WindowSystemInterface available, cannot create windows."
        return

    unsigned int width, height
    wsi.getScreenResolution(osg.GraphicsContext.ScreenIdentifier(0), width, height)

    while arguments.read("--width",width) : 
    while arguments.read("--height",height) : 

    traits = osg.GraphicsContext.Traits()
    traits.x = 0
    traits.y = 0
    traits.width = width
    traits.height = height
    traits.windowDecoration = False
    traits.doubleBuffer = True
    traits.sharedContext = 0



    gc = osg.GraphicsContext.createGraphicsContext(traits)
    if  not gc :
        osg.notify(osg.NOTICE), "GraphicsWindow has not been created successfully."
        return

    tex_width = 512
    tex_height = 512

    camera_width = tex_width
    camera_height = tex_height

    texture = osg.TextureCubeMap()

    texture.setTextureSize(tex_width, tex_height)
    texture.setInternalFormat(GL_RGB)
    texture.setFilter(osg.Texture.MIN_FILTER,osg.Texture.LINEAR)
    texture.setFilter(osg.Texture.MAG_FILTER,osg.Texture.LINEAR)

#if 0
    renderTargetImplementation = osg.Camera.SEPERATE_WINDOW
    buffer = GL_FRONT
#else:
    renderTargetImplementation = osg.Camera.FRAME_BUFFER_OBJECT
    buffer = GL_FRONT
#endif

    # front face
        camera = osg.Camera()
        camera.setName("Front face camera")
        camera.setGraphicsContext(gc)
        camera.setViewport(osg.Viewport(0,0,camera_width, camera_height))
        camera.setDrawBuffer(buffer)
        camera.setReadBuffer(buffer)
        camera.setAllowEventFocus(False)
        # tell the camera to use OpenGL frame buffer object where supported.
        camera.setRenderTargetImplementation(renderTargetImplementation)

        # attach the texture and use it as the color buffer.
        camera.attach(osg.Camera.COLOR_BUFFER, texture, 0, osg.TextureCubeMap.POSITIVE_Y)

        viewer.addSlave(camera, osg.Matrixd(), osg.Matrixd())


    # top face
        camera = osg.Camera()
        camera.setName("Top face camera")
        camera.setGraphicsContext(gc)
        camera.setViewport(osg.Viewport(0,0,camera_width, camera_height))
        buffer =  GL_BACK if (traits.doubleBuffer) else  GL_FRONT
        camera.setDrawBuffer(buffer)
        camera.setReadBuffer(buffer)
        camera.setAllowEventFocus(False)

        # tell the camera to use OpenGL frame buffer object where supported.
        camera.setRenderTargetImplementation(renderTargetImplementation)

        # attach the texture and use it as the color buffer.
        camera.attach(osg.Camera.COLOR_BUFFER, texture, 0, osg.TextureCubeMap.POSITIVE_Z)

        viewer.addSlave(camera, osg.Matrixd(), osg.Matrixd.rotate(osg.inDegrees(-90.0), 1.0,0.0,0.0))

    # left face
        camera = osg.Camera()
        camera.setName("Left face camera")
        camera.setGraphicsContext(gc)
        camera.setViewport(osg.Viewport(0,0,camera_width, camera_height))
        camera.setDrawBuffer(buffer)
        camera.setReadBuffer(buffer)
        camera.setAllowEventFocus(False)

        # tell the camera to use OpenGL frame buffer object where supported.
        camera.setRenderTargetImplementation(renderTargetImplementation)

        # attach the texture and use it as the color buffer.
        camera.attach(osg.Camera.COLOR_BUFFER, texture, 0, osg.TextureCubeMap.NEGATIVE_X)

        viewer.addSlave(camera, osg.Matrixd(), osg.Matrixd.rotate(osg.inDegrees(-90.0), 0.0,1.0,0.0) * osg.Matrixd.rotate(osg.inDegrees(-90.0), 0.0,0.0,1.0))

    # right face
        camera = osg.Camera()
        camera.setName("Right face camera")
        camera.setGraphicsContext(gc)
        camera.setViewport(osg.Viewport(0,0,camera_width, camera_height))
        camera.setDrawBuffer(buffer)
        camera.setReadBuffer(buffer)
        camera.setAllowEventFocus(False)

        # tell the camera to use OpenGL frame buffer object where supported.
        camera.setRenderTargetImplementation(renderTargetImplementation)

        # attach the texture and use it as the color buffer.
        camera.attach(osg.Camera.COLOR_BUFFER, texture, 0, osg.TextureCubeMap.POSITIVE_X)

        viewer.addSlave(camera, osg.Matrixd(), osg.Matrixd.rotate(osg.inDegrees(90.0), 0.0,1.0,0.0 ) * osg.Matrixd.rotate(osg.inDegrees(90.0), 0.0,0.0,1.0))

    # bottom face
        camera = osg.Camera()
        camera.setGraphicsContext(gc)
        camera.setName("Bottom face camera")
        camera.setViewport(osg.Viewport(0,0,camera_width, camera_height))
        camera.setDrawBuffer(buffer)
        camera.setReadBuffer(buffer)
        camera.setAllowEventFocus(False)

        # tell the camera to use OpenGL frame buffer object where supported.
        camera.setRenderTargetImplementation(renderTargetImplementation)

        # attach the texture and use it as the color buffer.
        camera.attach(osg.Camera.COLOR_BUFFER, texture, 0, osg.TextureCubeMap.NEGATIVE_Z)

        viewer.addSlave(camera, osg.Matrixd(), osg.Matrixd.rotate(osg.inDegrees(90.0), 1.0,0.0,0.0) * osg.Matrixd.rotate(osg.inDegrees(180.0), 0.0,0.0,1.0))

    # back face
        camera = osg.Camera()
        camera.setName("Back face camera")
        camera.setGraphicsContext(gc)
        camera.setViewport(osg.Viewport(0,0,camera_width, camera_height))
        camera.setDrawBuffer(buffer)
        camera.setReadBuffer(buffer)
        camera.setAllowEventFocus(False)

        # tell the camera to use OpenGL frame buffer object where supported.
        camera.setRenderTargetImplementation(renderTargetImplementation)

        # attach the texture and use it as the color buffer.
        camera.attach(osg.Camera.COLOR_BUFFER, texture, 0, osg.TextureCubeMap.NEGATIVE_Y)

        viewer.addSlave(camera, osg.Matrixd(), osg.Matrixd.rotate(osg.inDegrees(180.0), 1.0,0.0,0.0))

    viewer.getCamera().setProjectionMatrixAsPerspective(90.0, 1.0, 1, 1000.0)



    # distortion correction set up.
        geode = osg.Geode()
        geode.addDrawable(createDomeDistortionMesh(osg.Vec3(0.0,0.0,0.0), osg.Vec3(width,0.0,0.0), osg.Vec3(0.0,height,0.0), arguments))

        # we need to add the texture to the mesh, we do so by creating a
        # StateSet to contain the Texture StateAttribute.
        stateset = geode.getOrCreateStateSet()
        stateset.setTextureAttributeAndModes(0, texture,osg.StateAttribute.ON)
        stateset.setMode(GL_LIGHTING,osg.StateAttribute.OFF)

        camera = osg.Camera()
        camera.setGraphicsContext(gc)
        camera.setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT )
        camera.setClearColor( osg.Vec4(0.1,0.1,1.0,1.0) )
        camera.setViewport(osg.Viewport(0, 0, width, height))
        buffer =  GL_BACK if (traits.doubleBuffer) else  GL_FRONT
        camera.setDrawBuffer(buffer)
        camera.setReadBuffer(buffer)
        camera.setReferenceFrame(osg.Camera.ABSOLUTE_RF)
        camera.setAllowEventFocus(False)
        #camera.setInheritanceMask(camera.getInheritanceMask()  ~osg.CullSettings.CLEAR_COLOR  ~osg.CullSettings.COMPUTE_NEAR_FAR_MODE)
        #camera.setComputeNearFarMode(osg.CullSettings.DO_NOT_COMPUTE_NEAR_FAR)

        camera.setProjectionMatrixAsOrtho2D(0,width,0,height)
        camera.setViewMatrix(osg.Matrix.identity())

        # add subgraph to render
        camera.addChild(geode)

        camera.setName("DistortionCorrectionCamera")

        viewer.addSlave(camera, osg.Matrixd(), osg.Matrixd(), False)

    viewer.getCamera().setNearFarRatio(0.0001)
Example #4
0
def main(argv):


    

    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)

    # read the scene from the list of file specified commandline args.
    scene = osgDB.readNodeFiles(arguments)

    if  not scene :
        print argv[0], ": requires filename argument."
        return 1

    # construct the viewer.
    viewer = osgViewer.CompositeViewer(arguments)

    if arguments.read("-1") :
            view = osgViewer.View()
            view.setName("Single view")
            view.setSceneData(osgDB.readNodeFile("fountain.osgt"))

            view.addEventHandler( osgViewer.StatsHandler )()

            view.setUpViewAcrossAllScreens()
            view.setCameraManipulator(osgGA.TrackballManipulator)()
            viewer.addView(view)

    if arguments.read("-2") :

        # view one
            view = osgViewer.View()
            view.setName("View one")
            viewer.addView(view)

            view.setUpViewOnSingleScreen(0)
            view.setSceneData(scene)
            view.setCameraManipulator(osgGA.TrackballManipulator)()

            # add the state manipulator
            statesetManipulator = osgGA.StateSetManipulator()
            statesetManipulator.setStateSet(view.getCamera().getOrCreateStateSet())

            view.addEventHandler( statesetManipulator )

        # view two
            view = osgViewer.View()
            view.setName("View two")
            viewer.addView(view)

            view.setUpViewOnSingleScreen(1)
            view.setSceneData(scene)
            view.setCameraManipulator(osgGA.TrackballManipulator)()

            view.addEventHandler( osgViewer.StatsHandler )()


            # add the handler for doing the picking
            view.addEventHandler(PickHandler())


    if arguments.read("-3")  or  viewer.getNumViews()==0 :

        wsi = osg.GraphicsContext.getWindowingSystemInterface()
        if  not wsi :
            osg.notify(osg.NOTICE), "Error, no WindowSystemInterface available, cannot create windows."
            return 1

        unsigned int width, height
        wsi.getScreenResolution(osg.GraphicsContext.ScreenIdentifier(0), width, height)

        traits = osg.GraphicsContext.Traits()
        traits.x = 100
        traits.y = 100
        traits.width = 1000
        traits.height = 800
        traits.windowDecoration = True
        traits.doubleBuffer = True
        traits.sharedContext = 0

        gc = osg.GraphicsContext.createGraphicsContext(traits)
        if gc.valid() :
            osg.notify(osg.INFO), "  GraphicsWindow has been created successfully."

            # need to ensure that the window is cleared make sure that the complete window is set the correct colour
            # rather than just the parts of the window that are under the camera's viewports
            gc.setClearColor(osg.Vec4f(0.2,0.2,0.6,1.0))
            gc.setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        else:
            osg.notify(osg.NOTICE), "  GraphicsWindow has not been created successfully."

        # view one
            view = osgViewer.View()
            view.setName("View one")
            viewer.addView(view)

            view.setSceneData(scene)
            view.getCamera().setName("Cam one")
            view.getCamera().setViewport(osg.Viewport(0,0, traits.width/2, traits.height/2))
            view.getCamera().setGraphicsContext(gc)
            view.setCameraManipulator(osgGA.TrackballManipulator)()

            # add the state manipulator
            statesetManipulator = osgGA.StateSetManipulator()
            statesetManipulator.setStateSet(view.getCamera().getOrCreateStateSet())

            view.addEventHandler( statesetManipulator )

            view.addEventHandler( osgViewer.StatsHandler )()
            view.addEventHandler( osgViewer.HelpHandler )()
            view.addEventHandler( osgViewer.WindowSizeHandler )()
            view.addEventHandler( osgViewer.ThreadingHandler )()
            view.addEventHandler( osgViewer.RecordCameraPathHandler )()

        # view two
            view = osgViewer.View()
            view.setName("View two")
            viewer.addView(view)

            view.setSceneData(scene)
            view.getCamera().setName("Cam two")
            view.getCamera().setViewport(osg.Viewport(traits.width/2,0, traits.width/2, traits.height/2))
            view.getCamera().setGraphicsContext(gc)
            view.setCameraManipulator(osgGA.TrackballManipulator)()

            # add the handler for doing the picking
            view.addEventHandler(PickHandler())


        # view three
            view = osgViewer.View()
            view.setName("View three")
            viewer.addView(view)

            view.setSceneData(osgDB.readNodeFile("cessnafire.osgt"))

            view.getCamera().setName("Cam three")
            view.getCamera().setProjectionMatrixAsPerspective(30.0, double(traits.width) / double(traits.height/2), 1.0, 1000.0)
            view.getCamera().setViewport(osg.Viewport(0, traits.height/2, traits.width, traits.height/2))
            view.getCamera().setGraphicsContext(gc)
            view.setCameraManipulator(osgGA.TrackballManipulator)()



    while arguments.read("-s") :  viewer.setThreadingModel(osgViewer.CompositeViewer.SingleThreaded) 
    while arguments.read("-g") :  viewer.setThreadingModel(osgViewer.CompositeViewer.CullDrawThreadPerContext) 
    while arguments.read("-c") :  viewer.setThreadingModel(osgViewer.CompositeViewer.CullThreadPerCameraDrawThreadPerContext) 

     # run the viewer's main frame loop
     return viewer.run()
Example #5
0
        else:
            numY = int(ceilf(multiplier_y))
            numX = int(ceilf(float(models.size())/float(numY)))

    # populate the view with the required view to view each model.
    for(unsigned int i=0 i<models.size() ++i)
        view = osgViewer.View()
        
        xCell = i % numX
        yCell = i / numX
    
        vx = int((float(xCell)/float(numX)) * float(width))
        vy = int((float(yCell)/float(numY)) * float(height))
        vw = int(float(width) / float(numX))
        vh = int(float(height) / float(numY))

        view.setSceneData(models[i])
        view.getCamera().setProjectionMatrixAsPerspective(30.0, double(vw) / double(vh), 1.0, 1000.0)
        view.getCamera().setViewport(osg.Viewport(vx, vy, vw, vh))    
        view.getCamera().setGraphicsContext(gc)
        view.getCamera().setClearMask(0)
        view.setCameraManipulator(trackball)

        viewer.addView(view)

    return viewer.run()


if __name__ == "__main__":
    main(sys.argv)
            
        else:
            double fovy, aspectRatio, zNear, zFar
            viewer.getCamera().getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar)

            newAspectRatio = double(traits.width) / double(traits.height)
            aspectRatioChange = newAspectRatio / aspectRatio
            if aspectRatioChange  not = 1.0 :
                viewer.getCamera().getProjectionMatrix() *= osg.Matrix.scale(fovx_multiple/aspectRatioChange,fovy_multiple,1.0)

        # set up stereo masks
        viewer.getCamera().setCullMask(0xffffffff)
        viewer.getCamera().setCullMaskLeft(0x00000001)
        viewer.getCamera().setCullMaskRight(0x00000002)

        viewer.getCamera().setViewport(osg.Viewport(0, 0, traits.width, traits.height))

        buffer =  GL_BACK if (traits.doubleBuffer) else  GL_FRONT

        viewer.getCamera().setDrawBuffer(buffer)
        viewer.getCamera().setReadBuffer(buffer)

    outputPath = osgDB.getFilePath(fc.getOutputFileName())
    if  not outputPath.empty() :
        type = osgDB.fileType(outputPath)
        switch(type)
            case(osgDB.FILE_NOT_FOUND):
                if  not osgDB.makeDirectory(outputPath) :
                    OSG_NOTICE, "Error: could not create directory [", outputPath, "]."                    
                    return 1
                OSG_NOTICE, "Created directory [", outputPath, "]."
def main(argv):

    

    # use an ArgumentParser object to manage the program arguments.
    arguments = osg.ArgumentParser(argv)

    arguments.getApplicationUsage().addCommandLineOption("--zeroconf","uses zeroconf to advertise the osc-plugin and to discover it")
    arguments.getApplicationUsage().addCommandLineOption("--sender","create a view which sends its events via osc")
    arguments.getApplicationUsage().addCommandLineOption("--recevier","create a view which receive its events via osc")



    # read the scene from the list of file specified commandline args.
    scene = osgDB.readNodeFiles(arguments)

    if  not scene :
        print argv[0], ": requires filename argument."
        return 1

    use_zeroconf = bool(False)
    use_sender = bool(False)
    use_receiver = bool(False)
    if arguments.find("--zeroconf") > 0 :  use_zeroconf = True 
    if arguments.find("--sender") > 0 :  use_sender = True 
    if arguments.find("--receiver") > 0 :  use_receiver = True 
    # construct the viewer.
    viewer = osgViewer.CompositeViewer(arguments)

    # receiver view
    if use_receiver : 
        traits = osg.GraphicsContext.Traits()
        traits.x = 600
        traits.y = 100
        traits.width = 400
        traits.height = 400
        traits.windowDecoration = True
        traits.doubleBuffer = True
        traits.sharedContext = 0
        traits.windowName = "Receiver / view two"

        gc = osg.GraphicsContext.createGraphicsContext(traits)

        view = osgViewer.View()
        view.setName("View two")
        viewer.addView(view)

        group = osg.Group()
        group.addChild(scene)
        geode = osg.Geode()
        group.addChild(geode)

        text = osgText.Text()
        geode.addDrawable( text )

        text.setFont("Arial.ttf")
        text.setText("Waiting for data")
        text.setPosition(osg.Vec3(-50,0,30))
        text.setAxisAlignment(osgText.TextBase.SCREEN)
        text.setDataVariance(osg.Object.DYNAMIC)
        text.setCharacterSize(2.0)
        view.setSceneData(group)
        view.getCamera().setName("Cam two")
        view.getCamera().setViewport(osg.Viewport(0,0, traits.width, traits.height))
        view.getCamera().setGraphicsContext(gc)

        view.addEventHandler( osgViewer.StatsHandler )()
        view.addEventHandler( UserEventHandler(text) )

        device = osgDB.readFile<osgGA.Device>("0.0.0.0:9000.receiver.osc")
        if device.valid()  and  (device.getCapabilities()  osgGA.Device.RECEIVE_EVENTS) :
            view.addDevice(device)

            # add a zeroconf device, advertising the osc-device
            if use_zeroconf :
                zeroconf_device = osgDB.readFile<osgGA.Device>("_osc._udp:9000.advertise.zeroconf")
                if zeroconf_device :
                    view.addDevice(zeroconf_device)
        else:
            OSG_WARN, "could not open osc-device, receiving will not work"
Example #8
0
def singleWindowSideBySideCameras(viewer):

    
    wsi = osg.GraphicsContext.getWindowingSystemInterface()
    if  not wsi : 
        osg.notify(osg.NOTICE), "Error, no WindowSystemInterface available, cannot create windows."
        return
    
    unsigned int width, height
    wsi.getScreenResolution(osg.GraphicsContext.ScreenIdentifier(0), width, height)



    # Not fullscreen
    width /= 2
    height /= 2

    traits = osg.GraphicsContext.Traits()
    traits.x = 100
    traits.y = 100
    traits.width = width
    traits.height = height
    traits.windowDecoration = True
    traits.doubleBuffer = True
    traits.sharedContext = 0

    gc = osg.GraphicsContext.createGraphicsContext(traits)
    if gc.valid() :
        osg.notify(osg.INFO), "  GraphicsWindow has been created successfully."

        # need to ensure that the window is cleared make sure that the complete window is set the correct colour
        # rather than just the parts of the window that are under the camera's viewports
        gc.setClearColor(osg.Vec4f(0.2,0.2,0.6,1.0))
        gc.setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    else:
        osg.notify(osg.NOTICE), "  GraphicsWindow has not been created successfully."


    master = viewer.getCamera()

    # get the default settings for the camera
    double fovy, aspectRatio, zNear, zFar
    master.getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar)

    # reset this for the actual apsect ratio of out created window
    windowAspectRatio = double(width)/double(height)
    master.setProjectionMatrixAsPerspective(fovy, windowAspectRatio, 1.0, 10000.0)

    master.setName("MasterCam")

    camera = osg.Camera()
    camera.setCullMask(1)
    camera.setName("Left")
    camera.setGraphicsContext(gc)
    camera.setViewport(osg.Viewport(0, 0, width/2, height))
    buffer =  GL_BACK if (traits.doubleBuffer) else  GL_FRONT
    camera.setDrawBuffer(buffer)
    camera.setReadBuffer(buffer)
    viewer.addSlave(camera, osg.Matrixd.scale(1.0,0.5,1.0), osg.Matrixd())

    camera = osg.Camera()
    camera.setCullMask(2)
    camera.setName("Right")
    camera.setGraphicsContext(gc)
    camera.setViewport(osg.Viewport(width/2, 0, width/2, height))
    buffer =  GL_BACK if (traits.doubleBuffer) else  GL_FRONT
    camera.setDrawBuffer(buffer)
    camera.setReadBuffer(buffer)
    viewer.addSlave(camera, osg.Matrixd.scale(1.0,0.5,1.0), osg.Matrixd())
    traits.width = width traits.height = height
    traits.windowDecoration = True
    traits.doubleBuffer = True
    traits.glContextVersion = version
     gc = osg.GraphicsContext.createGraphicsContext( traits )
    if   not gc.valid()  :
        osg.notify( osg.FATAL ), "Unable to create OpenGL v", version, " context."
        return( 1 )

    # Create a Camera that uses the above OpenGL context.
    cam = osg.Camera()
    cam.setGraphicsContext( gc )
    # Must set perspective projection for fovy and aspect.
    cam.setProjectionMatrix( osg.Matrix.perspective( 30., (double)width/(double)height, 1., 100. ) )
    # Unlike OpenGL, OSG viewport does *not* default to window dimensions.
    cam.setViewport( osg.Viewport( 0, 0, width, height ) )

    viewer = osgViewer.Viewer()
    viewer.setCamera( cam )
    viewer.setSceneData( root )

    # for non GL3/GL4 and non GLES2 platforms we need enable the osg_ uniforms that the shaders will use,
    # you don't need thse two lines on GL3/GL4 and GLES2 specific builds as these will be enable by default.
    gc.getState().setUseModelViewAndProjectionUniforms(True)
    gc.getState().setUseVertexAttributeAliasing(True)

    return( viewer.run() )

#
#
#Building OSG for OpenGL 3.x
            traits.green = src_traits.green
            traits.blue = src_traits.blue
            traits.alpha = src_traits.alpha
            traits.depth = src_traits.depth
            traits.pbuffer = True
         else:
            #viewer would use fullscreen size (unknown here) pbuffer will use 4096 x4096 (or best avaiable)
            traits.width = 1, 12
            traits.height = 1, 12
            traits.pbuffer = True
        pbuffer = osg.GraphicsContext.createGraphicsContext(traits)
        if pbuffer.valid() :
            osg.notify(osg.NOTICE), "Pixel buffer has been created successfully."
            camera = osg.Camera(*viewer.getCamera())
            camera.setGraphicsContext(pbuffer)
            camera.setViewport(osg.Viewport(0,0,traits.width,traits.height))
            buffer =  GL_BACK if (pbuffer.getTraits().doubleBuffer) else  GL_FRONT
            camera.setDrawBuffer(buffer)
            camera.setReadBuffer(buffer)
            viewer.setCamera(camera)
        else:
            osg.notify(osg.NOTICE), "Pixel buffer has not been created successfully."

    # Read camera settings for screenshot
    lat = 50
    lon = 10
    alt = 2000
    heading = 0
    incline = 45
    roll = 0
    camera_specified = False