Hi,
i used the osgviewerQt example with the following modifications:
- added a toggle stereo on/off event handler
- added traits->quadBufferStereo = true; when creating the graphic context
When i start the program with OSG_STEREO=ON and OSG_STEREO_MODE=QUAD_BUFFER the
program works as expected. But when i turn off the stereo mode (press 'b'),
then the program does not render correctly. I need to describe the result in
word here, because a screenshot does not work.
It seems like two screen buffers (most likely left and right) and show on top
of each other. E.g. the coordinate axis in the example is show without an
rotation and with a rotation of 45 degree.
When i use the mouse to rotate the view only of one of the frames is changed
(according to the new settings by the manipulator) and the other frame remains
still.
When i turn on stereo again, everything works fine.
I checked the same with the regular osgviewer (with the added toggle stereo
mode event handler) and there everything works fine. No remaining/old left over
frames from stereo operation. So i assume it's something wrong in the osgQt
setup. Any ideas what?
Thank you!
Cheers,
Andreas
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=37033#37033
#include <QtCore/QTimer>
#include <QtGui/QApplication>
#include <QtGui/QGridLayout>
#include <osgViewer/CompositeViewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgGA/TrackballManipulator>
#include <osgDB/ReadFile>
#include <osgQt/GraphicsWindowQt>
#include <iostream>
struct ToggleStereoHandler : public osgGA::GUIEventHandler
{
bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa )
{
if ( ea.getEventType() == ea.KEYDOWN )
{
if(ea.getKey() == 'b')
{
bool stereo = osg::DisplaySettings::instance()->getStereo();
osg::DisplaySettings::instance()->setStereo(stereo ? false : true);
}
}
return false;
}
};
class ViewerWidget : public QWidget, public osgViewer::CompositeViewer
{
public:
ViewerWidget() : QWidget()
{
setThreadingModel(osgViewer::CompositeViewer::SingleThreaded);
QWidget* widget1 = addViewWidget( createCamera(0,0,100,100), osgDB::readNodeFile("cow.osg") );
QWidget* widget2 = addViewWidget( createCamera(0,0,100,100), osgDB::readNodeFile("glider.osg") );
QWidget* widget3 = addViewWidget( createCamera(0,0,100,100), osgDB::readNodeFile("axes.osg") );
QWidget* widget4 = addViewWidget( createCamera(0,0,100,100), osgDB::readNodeFile("fountain.osg") );
QWidget* popupWidget = addViewWidget( createCamera(900,100,320,240,"Popup window",true),
osgDB::readNodeFile("dumptruck.osg") );
popupWidget->show();
QGridLayout* grid = new QGridLayout;
grid->addWidget( widget1, 0, 0 );
grid->addWidget( widget2, 0, 1 );
grid->addWidget( widget3, 1, 0 );
grid->addWidget( widget4, 1, 1 );
setLayout( grid );
connect( &_timer, SIGNAL(timeout()), this, SLOT(update()) );
_timer.start( 10 );
}
QWidget* addViewWidget( osg::Camera* camera, osg::Node* scene )
{
osgViewer::View* view = new osgViewer::View;
view->setCamera( camera );
addView( view );
view->setSceneData( scene );
view->addEventHandler( new osgViewer::StatsHandler );
view->addEventHandler( new ToggleStereoHandler);
view->setCameraManipulator( new osgGA::TrackballManipulator );
osgQt::GraphicsWindowQt* gw = dynamic_cast<osgQt::GraphicsWindowQt*>( camera->getGraphicsContext() );
return gw ? gw->getGraphWidget() : NULL;
}
osg::Camera* createCamera( int x, int y, int w, int h, const std::string& name="", bool windowDecoration=false )
{
osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->windowName = name;
traits->windowDecoration = windowDecoration;
traits->x = x;
traits->y = y;
traits->width = w;
traits->height = h;
traits->doubleBuffer = true;
traits->alpha = ds->getMinimumNumAlphaBits();
traits->stencil = ds->getMinimumNumStencilBits();
traits->sampleBuffers = ds->getMultiSamples();
traits->samples = ds->getNumMultiSamples();
traits->quadBufferStereo = true;
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setGraphicsContext( new osgQt::GraphicsWindowQt(traits.get()) );
camera->setClearColor( osg::Vec4(0.2, 0.2, 0.6, 1.0) );
camera->setViewport( new osg::Viewport(0, 0, traits->width, traits->height) );
camera->setProjectionMatrixAsPerspective(
30.0f, static_cast<double>(traits->width)/static_cast<double>(traits->height), 1.0f, 10000.0f );
return camera.release();
}
virtual void paintEvent( QPaintEvent* event )
{ frame(); }
protected:
QTimer _timer;
};
int main( int argc, char** argv )
{
QApplication app(argc, argv);
ViewerWidget* viewWidget = new ViewerWidget;
viewWidget->setGeometry( 100, 100, 800, 600 );
viewWidget->show();
return app.exec();
}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org