osg osgViewer::View::setUpViewInWindow()

Current position: osgViewer / View.cpp line 575, osgViewer :: View :: setUpViewInWindow () This function has five parameters passed: Window Upper left coordinates x, y, width width, height height, and the number of screen screenNum. Its role as the name suggests is to create a graphics device according to the given parameters window.

_displayType: Display Type, the default is MONITOR (monitor), in addition to support POWERWALL (power walls), REALITY_CENTER (virtual reality center) and HEAD_MOUNTED_DISPLAY (head mounted display).

_stereoMode: the stereoscopic display mode, default anaglyphic (complementary color), in addition to support QUAD_BUFFER (tetragonal buffer), a HORIZONTAL_SPLIT (horizontal split), VERTICAL_SPLIT (vertical split), LEFT_EYE (left eye), RIGHT_EYE (right eye), HORIZONTAL_INTERLACE (horizontal interleave), VERTICAL_INTERLACE (vertically staggered), cHECKERBOARD (checkerboard interleaving for a DLP display).
_eyeSeparation: eyes physical distance, the default is 0.05.
_screenWidth, _screenHeight: the actual width and height of the screen, the default settings are 0.325 and 0.26, they affect only the current view of the aspect ratio when using perspective projection.
_screenDistance: people your eyes from the screen, the default is 0.5.
_splitStereoHorizontalEyeMapping: The default is LEFT_EYE_LEFT_VIEWPORT (left eye rendered viewport), can also be set LEFT_EYE_RIGHT_VIEWPORT (left and right viewport rendering).
_splitStereoHorizontalSeparation: distance (number of pixels) between the left and right viewport viewport, the default is 0.
_splitStereoVerticalEyeMapping: default LEFT_EYE_TOP_VIEWPORT (top left rendering viewport), can also be set LEFT_EYE_BOTTOM_VIEWPORT (bottom left rendering viewport).
_splitStereoVerticalSeparation: distance between the top and bottom viewport viewport (number of pixels), the default is 0.
_splitStereoAutoAdjustAspectRatio: The default is true, to compensate for the aspect ratio after its split screen.
_maxNumOfGraphicsContexts: (device context) in the user program number GraphicsContext most available, the default is 32.
_numMultiSamples: sub-pixel multi-sampling number of samples, the default is 0. If the video card supports it, open multi-sampling anti-aliasing effects can be greatly improved (anti-aliasing) is.

There are also many types of variables that can be set, such as _minimumNumberStencilBits (template cache minimum number of digits), with its default settings were osg :: DisplaySettings :: setDefaults function to complete, some of the variables may not have effect. It should be noted that the role of DisplaySettings only may be used to save all data in the system display, the class itself does not change any system settings accordingly and rendering.

It is commendable that, DisplaySettings can easily access user settings of the display device from the system environment variables or command line arguments, detailed call methods can be found in DisplaySettings :: readEnvironmentalVariables and content DisplaySettings :: readCommandLine two functions, is very popular easy to understand.

If you want to change the display settings DisplaySettings in the user program, make sure before you perform visual function's realize, of course, that is, before the start of the cycle simulation. It is also to Remember.

void View::setUpViewInWindow(int x, int y, int width, int height, unsigned int screenNum)
{
    apply(new osgViewer::SingleWindow(x, y, width, height, screenNum));
}

 

void View::apply(ViewConfig* config)
{
    if (config)
    {
        OSG_INFO<<"Applying osgViewer::ViewConfig : "<<config->className()<<std::endl;
        config->configure(*this);
    }
    _lastAppliedViewConfig = config;
}

 

View::View():
    _fusionDistanceMode(osgUtil::SceneView::PROPORTIONAL_TO_SCREEN_DISTANCE),
    _fusionDistanceValue(1.0f)
{
    // OSG_NOTICE<<"Constructing osgViewer::View"<<std::endl;

    _startTick = 0;

    _frameStamp = new osg::FrameStamp;
    _frameStamp->setFrameNumber(0);
    _frameStamp->setReferenceTime(0);
    _frameStamp->setSimulationTime(0);

    _scene = new Scene;

    // make sure View is safe to reference multi-threaded.
    setThreadSafeRefUnref(true);

    // need to attach a Renderer to the master camera which has been default constructed
    getCamera()->setRenderer(createRenderer(getCamera()));

    setEventQueue(new osgGA::EventQueue);

    setStats(new osg::Stats("View"));
}

 

View::View(const osgViewer::View& view, const osg::CopyOp& copyop):
    osg::Object(view, copyop),
    osg::View(view,copyop),
    osgGA::GUIActionAdapter(),
    _startTick(0),
    _fusionDistanceMode(view._fusionDistanceMode),
    _fusionDistanceValue(view._fusionDistanceValue)
{
    _scene = new Scene;

    // need to attach a Renderer to the master camera which has been default constructed
    getCamera()->setRenderer(createRenderer(getCamera()));

    setEventQueue(new osgGA::EventQueue);

    setStats(new osg::Stats("View"));
}

 

 

void SingleWindow::configure(osgViewer::View& view) const
{
    osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
    if (!wsi)
    {
        OSG_NOTICE<<"SingleWindow::configure() : Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
        return;
    }

    osg::DisplaySettings* ds = getActiveDisplaySetting(view);
    
    osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits(ds);

    traits->readDISPLAY();
    if (traits->displayNum<0) traits->displayNum = 0;

    traits->screenNum = _screenNum;
    traits->x = _x;
    traits->y = _y;
    traits->width = _width;
    traits->height = _height;
    traits->windowDecoration = _windowDecoration;
    traits->overrideRedirect = _overrideRedirect;
    traits->doubleBuffer = true;
    traits->sharedContext = 0;
    
    if (traits->width<=0 || traits->height<=0 ) 
    {
        osg::GraphicsContext::ScreenIdentifier si;
        si.readDISPLAY();

        // displayNum has not been set so reset it to 0.
        if (si.displayNum<0) si.displayNum = 0;

        si.screenNum = _screenNum;

        unsigned int width, height;
        wsi->getScreenResolution(si, width, height);
        if (traits->width<=0) traits->width = width;
        if (traits->height<=0) traits->height = height;
    }
    
    osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());

    view.getCamera()->setGraphicsContext(gc.get());

    osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(gc.get());
    if (gw)
    {
        OSG_INFO<<"SingleWindow::configure - GraphicsWindow has been created successfully."<<std::endl;
        gw->getEventQueue()->getCurrentEventState()->setWindowRectangle(traits->x, traits->y, traits->width, traits->height );
    }
    else
    {
        OSG_NOTICE<<"SingleWindow::configure - GraphicsWindow has not been created successfully."<<std::endl;
        return;
    }

    double fovy, aspectRatio, zNear, zFar;
    view.getCamera()->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar);

    double newAspectRatio = double(traits->width) / double(traits->height);
    double aspectRatioChange = newAspectRatio / aspectRatio;
    if (aspectRatioChange != 1.0)
    {
        view.getCamera()->getProjectionMatrix() *= osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0);
    }

    view.getCamera()->setViewport(new osg::Viewport(0, 0, traits->width, traits->height));

    GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;

    view.getCamera()->setDrawBuffer(buffer);
    view.getCamera()->setReadBuffer(buffer);

    if (ds->getKeystoneHint())
    {
        if (ds->getKeystoneHint() && !ds->getKeystoneFileNames().empty()) 
        {
            osgViewer::Keystone::loadKeystoneFiles(ds);
        }
        if (ds->getKeystones().empty()) ds->getKeystones().push_back(new Keystone);
        
        view.assignStereoOrKeystoneToCamera(view.getCamera(), ds);
    }
    else if (ds->getStereo() && ds->getUseSceneViewForStereoHint())
    {
        view.assignStereoOrKeystoneToCamera(view.getCamera(), ds);
    }
}

 

 

 

 

Text Reference: Wang Rui teacher, "the longest one."
Code reference: OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield (osg3.4)

Guess you like

Origin www.cnblogs.com/herd/p/11110529.html