fix examples context creation for X11

(when display not :0.0)
This commit is contained in:
mp3butcher
2018-09-08 18:18:33 +02:00
committed by Robert Osfield
parent 960f4d1ef2
commit 385cfa0cbf
18 changed files with 144 additions and 64 deletions

View File

@@ -45,6 +45,8 @@ class MyGraphicsContext {
traits->doubleBuffer = false; traits->doubleBuffer = false;
traits->sharedContext = 0; traits->sharedContext = 0;
traits->pbuffer = true; traits->pbuffer = true;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen();
_gc = osg::GraphicsContext::createGraphicsContext(traits.get()); _gc = osg::GraphicsContext::createGraphicsContext(traits.get());

View File

@@ -249,6 +249,8 @@ int main( int argc, char **argv )
traits->width = 1 << 12; traits->width = 1 << 12;
traits->height = 1 << 12; traits->height = 1 << 12;
traits->pbuffer = true; traits->pbuffer = true;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen();
} }
osg::ref_ptr<osg::GraphicsContext> pbuffer = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::GraphicsContext> pbuffer = osg::GraphicsContext::createGraphicsContext(traits.get());
if (pbuffer.valid()) if (pbuffer.valid())

View File

@@ -209,6 +209,8 @@ osgViewer::View* createView(osg::ref_ptr<osg::Node> scenegraph, osg::ref_ptr<osg
traits->windowDecoration = true; traits->windowDecoration = true;
traits->doubleBuffer = true; traits->doubleBuffer = true;
traits->sharedContext = 0; traits->sharedContext = 0;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen();
gc = osg::GraphicsContext::createGraphicsContext(traits.get()); gc = osg::GraphicsContext::createGraphicsContext(traits.get());
if (!gc) if (!gc)
@@ -267,7 +269,11 @@ int main(int argc, char** argv)
} }
unsigned int width, height; unsigned int width, height;
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height); osg::GraphicsContext::ScreenIdentifier main_screen_id;
main_screen_id.readDISPLAY();
main_screen_id.setUndefinedScreenDetailsToDefaultScreen();
wsi->getScreenResolution(main_screen_id, width, height);
unsigned int x=0, y=0; unsigned int x=0, y=0;
while(arguments.read("--window", x, y, width, height)) {} while(arguments.read("--window", x, y, width, height)) {}
@@ -283,6 +289,8 @@ int main(int argc, char** argv)
traits->windowDecoration = true; traits->windowDecoration = true;
traits->doubleBuffer = true; traits->doubleBuffer = true;
traits->sharedContext = 0; traits->sharedContext = 0;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen();
gc = osg::GraphicsContext::createGraphicsContext(traits.get()); gc = osg::GraphicsContext::createGraphicsContext(traits.get());
if (!gc) if (!gc)

View File

@@ -83,7 +83,11 @@ void singleWindowMultipleCameras(osgViewer::Viewer& viewer)
} }
unsigned int width, height; unsigned int width, height;
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height); osg::GraphicsContext::ScreenIdentifier main_screen_id;
main_screen_id.readDISPLAY();
main_screen_id.setUndefinedScreenDetailsToDefaultScreen();
wsi->getScreenResolution(main_screen_id, width, height);
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->x = 0; traits->x = 0;
@@ -93,6 +97,8 @@ void singleWindowMultipleCameras(osgViewer::Viewer& viewer)
traits->windowDecoration = true; traits->windowDecoration = true;
traits->doubleBuffer = true; traits->doubleBuffer = true;
traits->sharedContext = 0; traits->sharedContext = 0;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen();
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
if (gc.valid()) if (gc.valid())
@@ -134,7 +140,11 @@ void multipleWindowMultipleCameras(osgViewer::Viewer& viewer, bool multipleScree
} }
unsigned int width, height; unsigned int width, height;
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height); osg::GraphicsContext::ScreenIdentifier main_screen_id;
main_screen_id.readDISPLAY();
main_screen_id.setUndefinedScreenDetailsToDefaultScreen();
wsi->getScreenResolution(main_screen_id, width, height);
unsigned int numCameras = 6; unsigned int numCameras = 6;
@@ -151,6 +161,8 @@ void multipleWindowMultipleCameras(osgViewer::Viewer& viewer, bool multipleScree
traits->windowDecoration = true; traits->windowDecoration = true;
traits->doubleBuffer = true; traits->doubleBuffer = true;
traits->sharedContext = 0; traits->sharedContext = 0;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen();
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
if (gc.valid()) if (gc.valid())

View File

@@ -289,7 +289,11 @@ int main( int argc, char **argv )
} }
unsigned int width, height; unsigned int width, height;
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height); osg::GraphicsContext::ScreenIdentifier main_screen_id;
main_screen_id.readDISPLAY();
main_screen_id.setUndefinedScreenDetailsToDefaultScreen();
wsi->getScreenResolution(main_screen_id, width, height);
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->x = 100; traits->x = 100;
@@ -299,6 +303,8 @@ int main( int argc, char **argv )
traits->windowDecoration = true; traits->windowDecoration = true;
traits->doubleBuffer = true; traits->doubleBuffer = true;
traits->sharedContext = 0; traits->sharedContext = 0;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen();
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
if (gc.valid()) if (gc.valid())

View File

@@ -79,7 +79,11 @@ struct CommandLineOptions
return; return;
} }
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height); osg::GraphicsContext::ScreenIdentifier main_screen_id;
main_screen_id.readDISPLAY();
main_screen_id.setUndefinedScreenDetailsToDefaultScreen();
wsi->getScreenResolution(main_screen_id, width, height);
distance = sqrt(sphere_radius*sphere_radius - collar_radius*collar_radius); distance = sqrt(sphere_radius*sphere_radius - collar_radius*collar_radius);
} }
@@ -274,6 +278,8 @@ void setDomeFaces(osgViewer::Viewer& viewer, CommandLineOptions& options)
traits->windowDecoration = true; traits->windowDecoration = true;
traits->doubleBuffer = true; traits->doubleBuffer = true;
traits->sharedContext = 0; traits->sharedContext = 0;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen();
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
if (!gc) if (!gc)
@@ -502,6 +508,8 @@ void setDomeCorrection(osgViewer::Viewer& viewer, CommandLineOptions& options)
traits->windowDecoration = false; traits->windowDecoration = false;
traits->doubleBuffer = true; traits->doubleBuffer = true;
traits->sharedContext = 0; traits->sharedContext = 0;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen();
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
if (!gc) if (!gc)

View File

@@ -722,6 +722,8 @@ GraphicsContext* setupGC(osgViewer::Viewer& viewer, ArgumentParser& arguments)
traits->windowDecoration = decoration; traits->windowDecoration = decoration;
traits->doubleBuffer = true; traits->doubleBuffer = true;
traits->sharedContext = 0; traits->sharedContext = 0;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen();
ref_ptr<GraphicsContext> gc = GraphicsContext::createGraphicsContext(traits.get()); ref_ptr<GraphicsContext> gc = GraphicsContext::createGraphicsContext(traits.get());
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(gc.get()); osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(gc.get());

View File

@@ -159,6 +159,8 @@ int main( int argc, char **argv )
traits->windowDecoration = true; traits->windowDecoration = true;
traits->doubleBuffer = true; traits->doubleBuffer = true;
traits->sharedContext = 0; traits->sharedContext = 0;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen();
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
if (gc.valid()) if (gc.valid())

View File

@@ -65,6 +65,8 @@ class ContextTest : public MemoryTest
traits->height = _height; traits->height = _height;
traits->windowDecoration = true; traits->windowDecoration = true;
traits->pbuffer = _pbuffer; traits->pbuffer = _pbuffer;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen();
osg::ref_ptr<osg::GraphicsContext> window = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::GraphicsContext> window = osg::GraphicsContext::createGraphicsContext(traits.get());
if (window.valid()) if (window.valid())

View File

@@ -641,7 +641,11 @@ int main(int argc, char** argv)
if (wsi) if (wsi)
{ {
unsigned int width, height; unsigned int width, height;
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height); osg::GraphicsContext::ScreenIdentifier main_screen_id;
main_screen_id.readDISPLAY();
main_screen_id.setUndefinedScreenDetailsToDefaultScreen();
wsi->getScreenResolution(main_screen_id, width, height);
screenAspectRatio = float(width) / float(height); screenAspectRatio = float(width) / float(height);
} }

View File

@@ -91,7 +91,11 @@ int main( int argc, char **argv )
} }
unsigned int width, height; unsigned int width, height;
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height); osg::GraphicsContext::ScreenIdentifier main_screen_id;
main_screen_id.readDISPLAY();
main_screen_id.setUndefinedScreenDetailsToDefaultScreen();
wsi->getScreenResolution(main_screen_id, width, height);
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->x = 100; traits->x = 100;
@@ -101,6 +105,8 @@ int main( int argc, char **argv )
traits->windowDecoration = true; traits->windowDecoration = true;
traits->doubleBuffer = true; traits->doubleBuffer = true;
traits->sharedContext = 0; traits->sharedContext = 0;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen();
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
if (gc.valid()) if (gc.valid())

View File

@@ -443,6 +443,8 @@ int main( int argc, char **argv )
traits->doubleBuffer = true; traits->doubleBuffer = true;
traits->sharedContext = 0; traits->sharedContext = 0;
traits->windowName = "Receiver / view two"; traits->windowName = "Receiver / view two";
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen();
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
@@ -509,6 +511,8 @@ int main( int argc, char **argv )
traits->doubleBuffer = true; traits->doubleBuffer = true;
traits->sharedContext = 0; traits->sharedContext = 0;
traits->windowName = "Sender / view one"; traits->windowName = "Sender / view one";
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen();
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());

View File

@@ -712,6 +712,8 @@ int main(int argc, char** argv)
traits->pbuffer = true; traits->pbuffer = true;
traits->doubleBuffer = true; traits->doubleBuffer = true;
traits->sharedContext = 0; traits->sharedContext = 0;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen();
pbuffer = osg::GraphicsContext::createGraphicsContext(traits.get()); pbuffer = osg::GraphicsContext::createGraphicsContext(traits.get());
if (pbuffer.valid()) if (pbuffer.valid())

View File

@@ -182,7 +182,11 @@ void singleWindowSideBySideCameras(osgViewer::Viewer& viewer)
} }
unsigned int width, height; unsigned int width, height;
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height); osg::GraphicsContext::ScreenIdentifier main_screen_id;
main_screen_id.readDISPLAY();
main_screen_id.setUndefinedScreenDetailsToDefaultScreen();
wsi->getScreenResolution(main_screen_id, width, height);
@@ -198,6 +202,8 @@ void singleWindowSideBySideCameras(osgViewer::Viewer& viewer)
traits->windowDecoration = true; traits->windowDecoration = true;
traits->doubleBuffer = true; traits->doubleBuffer = true;
traits->sharedContext = 0; traits->sharedContext = 0;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen();
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
if (gc.valid()) if (gc.valid())

View File

@@ -87,6 +87,8 @@ int main( int argc, char** argv )
traits->windowDecoration = true; traits->windowDecoration = true;
traits->doubleBuffer = true; traits->doubleBuffer = true;
traits->glContextVersion = version; traits->glContextVersion = version;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen();
osg::ref_ptr< osg::GraphicsContext > gc = osg::GraphicsContext::createGraphicsContext( traits.get() ); osg::ref_ptr< osg::GraphicsContext > gc = osg::GraphicsContext::createGraphicsContext( traits.get() );
if( !gc.valid() ) if( !gc.valid() )
{ {

View File

@@ -142,6 +142,8 @@ int main( int argc, char **argv )
traits->doubleBuffer = true; traits->doubleBuffer = true;
traits->sharedContext = 0; traits->sharedContext = 0;
traits->pbuffer = false; traits->pbuffer = false;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen();
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
if (!gc || !gc->valid()) if (!gc || !gc->valid())

View File

@@ -146,7 +146,11 @@ int main(int argc, char** argv)
unsigned int width, height; unsigned int width, height;
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height); osg::GraphicsContext::ScreenIdentifier main_screen_id;
main_screen_id.readDISPLAY();
main_screen_id.setUndefinedScreenDetailsToDefaultScreen();
wsi->getScreenResolution(main_screen_id, width, height);
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits; osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->x = 0; traits->x = 0;
@@ -155,6 +159,8 @@ int main(int argc, char** argv)
traits->height = height; traits->height = height;
traits->windowDecoration = false; traits->windowDecoration = false;
traits->doubleBuffer = true; traits->doubleBuffer = true;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen();
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
if (!gc) if (!gc)

View File

@@ -58,6 +58,8 @@ int main( int argc, char **argv )
traits->windowDecoration = true; traits->windowDecoration = true;
traits->doubleBuffer = true; traits->doubleBuffer = true;
traits->sharedContext = 0; traits->sharedContext = 0;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen();
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
@@ -82,6 +84,8 @@ int main( int argc, char **argv )
traits->windowDecoration = true; traits->windowDecoration = true;
traits->doubleBuffer = true; traits->doubleBuffer = true;
traits->sharedContext = 0; traits->sharedContext = 0;
traits->readDISPLAY();
traits->setUndefinedScreenDetailsToDefaultScreen();
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());