[osg-users] getWindowingSystemInterface() fails on Ubuntu 18.04

Robert Osfield robert.osfield at gmail.com
Wed Sep 5 07:50:42 PDT 2018

On Wed, 5 Sep 2018 at 15:22, Julien Valentin <julienvalentin51 at 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:

    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.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp
Type: text/x-c++src
Size: 1191 bytes
Desc: not available
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20180905/fdc50bcf/attachment.cpp>

More information about the osg-users mailing list