On Wed, 5 Sep 2018 at 15:22, Julien Valentin <julienvalenti...@gmail.com> wrote:
> for your code you should replace
> wsi->getNumScreens()
> with
> wsi->getNumScreens(osg::GraphicsContext::ScreenIdentifier(1))
> to work on DISPLAY=:1.0

Sounds like we are getting to the bottom of things now :-)

FYI, WindowingSystemInterface::getNumScreens() is implemented in
include/osg/GraphicsContext as:

            virtual unsigned int getNumScreens(const ScreenIdentifier&
screenIdentifier = ScreenIdentifier()) = 0;

The default constructed ScreenIdentifier is:

GraphicsContext::ScreenIdentifier::ScreenIdentifier():
    displayNum(0),
    screenNum(0) {}

Which is fine if the system doesn't change the default DISPLAY from 0.0.

Support for DISPLAY is actually built into ScreenIdentifier via the
readDISPLAY() method:

            /** Read the DISPLAY environmental variable, and set the
ScreenIdentifier accordingly.
              * Note, if either of displayNum or screenNum are not
defined then -1 is set respectively to
              * signify that this parameter has not been set. When
parameters are undefined one can call
              * call setUndefinedScreenDetailsToDefaultScreen() after
readDISPLAY() to ensure valid values. */
            void readDISPLAY();

To is not called by the constructor though, so you need to call it
explicitly.  The various Viewer config implementations do actually
call readDISPLAY:

~/OpenSceneGraph/src/osgViewer$ grep readDISPLAY */*.cpp
config/AcrossAllScreens.cpp:    si.readDISPLAY();
config/PanoramicSphericalDisplay.cpp:    si.readDISPLAY();
config/SingleWindow.cpp:    traits->readDISPLAY();
config/SingleWindow.cpp:        si.readDISPLAY();
config/SphericalDisplay.cpp:    si.readDISPLAY();
config/WoWVxDisplay.cpp:    si.readDISPLAY();

So I'd suggest using this, such as (modified main.cpp for osgtest:

    std::cout << wsi->getNumScreens() << " screen(s) detected" << std::endl;
    for ( unsigned int screen=0 ; screen <
wsi->getNumScreens(main_screen_id); screen++ )
    {
        osg::GraphicsContext::ScreenIdentifier screen_id(screen);
        osg::GraphicsContext::ScreenSettings screen_settings;
        wsi->getScreenSettings( screen_id, screen_settings );
        std::cout << "  Screen #" << screen << " : "
                  << screen_settings.width << "x" <<
screen_settings.height << " "
                  << screen_settings.refreshRate << "Hz "
                  << screen_settings.colorDepth << " bit" << std::endl;
    }

I have also attached the full modified file.

Robert.
#include <iostream>
#include <osgViewer/Viewer>

int main(int argc, char** argv)
{

    osg::ArgumentParser arguments(&argc, argv);

    osgViewer::Viewer viewer(arguments);

    osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
    if ( !wsi )
    {
        std::cout << "ERROR. Could not access the Windowing System Interface" << std::endl;
        throw -1;
    }

    osg::GraphicsContext::ScreenIdentifier main_screen_id;
    main_screen_id.readDISPLAY();

    std::cout << wsi->getNumScreens() << " screen(s) detected" << std::endl;
    for ( unsigned int screen=0 ; screen < wsi->getNumScreens(main_screen_id); screen++ )
    {
        osg::GraphicsContext::ScreenIdentifier screen_id(screen);
        osg::GraphicsContext::ScreenSettings screen_settings;
        wsi->getScreenSettings( screen_id, screen_settings );
        std::cout << "  Screen #" << screen << " : "
                  << screen_settings.width << "x" << screen_settings.height << " "
                  << screen_settings.refreshRate << "Hz "
                  << screen_settings.colorDepth << " bit" << std::endl;
    }

    viewer.run();

    return 0;

}
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to