[Newbie warning.]
I searched the knowledge base and the list archives and the examples and
cannot find a way to create one viewport in stereo and another in 2D (with
the same data). I'm probably going about this in the wrong way.
I copied and modified osgviewer.cpp and added code from osgcamera.cpp to
create the two viewports and then tried to change one of the viewports into
HORIZONTAL_SPLIT mode. I get an exception at the point where I am trying to
change the DisplaySettings (at the bottom of the routine included here):
void singleWindowMultipleCameras(osgViewer::Viewer& viewer)
{
osg::GraphicsContext::WindowingSystemInterface* wsi =
osg::GraphicsContext::getWindowingSystemInterface();
if (!wsi)
{
osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface
available, cannot create windows."<<std::endl;
return;
}
unsigned int width, height;
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0),
width, height);
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new
osg::GraphicsContext::Traits;
traits->x = 0;
traits->y = 0;
traits->width = width;
traits->height = height;
//traits->windowDecoration = true;
traits->windowDecoration = false;
traits->doubleBuffer = true;
traits->sharedContext = 0;
osg::ref_ptr<osg::GraphicsContext> gc =
osg::GraphicsContext::createGraphicsContext(traits.get());
if (gc.valid())
{
osg::notify(osg::INFO)<<" GraphicsWindow has been created
successfully."<<std::endl;
// 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.2f,0.2f,0.6f,1.0f));
gc->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
else
{
osg::notify(osg::NOTICE)<<" GraphicsWindow has not been created
successfully."<<std::endl;
}
//
// We want one camera viewport set at the bottom portion of the
screen.
// we want the second camera to fill the upper part of the screen.
//
unsigned int numCameras = 2;
double aspectRatioScale = 1.0;///(double)numCameras;
//
// First camera viewport ... the whole screen.
//
{
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setGraphicsContext(gc.get());
camera->setViewport(new osg::Viewport(0, 0, width, height));
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
camera->setDrawBuffer(buffer);
camera->setReadBuffer(buffer);
//aspectRatioScale = (double)width/480.0;
viewer.addSlave(camera.get(), osg::Matrixd(),
osg::Matrixd::scale(aspectRatioScale,1.0,1.0));
}
//
// Second camera viewport ... stereo l/r placed at the bottom of the
screen.
//
{
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setGraphicsContext(gc.get());
unsigned int x, w, y, h;
unsigned int basicWidth = 480;
if(basicWidth > width/2)
{
x = 0;
y = 0;
w = width;
h = width/2;
}
else
{
x = width/2 - basicWidth;
y = 0;
w = 2*basicWidth;
h = basicWidth;
}
osg::notify(osg::NOTICE)<<" stereo viewport (x, y, w, h) " <<
x << ", " <<
y << ", " <<
w << ", " <<
h <<
std::endl;
camera->setViewport(new osg::Viewport(x, y, w, h));
GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
camera->setDrawBuffer(buffer);
camera->setReadBuffer(buffer);
//aspectRatioScale = (double)width/((double)height - 480.0);
viewer.addSlave(camera.get(), osg::Matrixd(),
osg::Matrixd::scale(aspectRatioScale,1.0,1.0));
viewer.getDisplaySettings()->setStereoMode(osg::DisplaySettings::HORIZONTAL_SPLIT);
}
}
Thanks for any help you can offer.
Regards,
Dave Modl
[email protected]
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org