HI Giana,

As I suspected the bug is introduced by the Qt code example that you've
reused.  I had to fix the osgviewerQt example so that it didn't create it's
own local Camera, instead uses the view's master Camera() that the view
initializes in a suitable way to work as a topmost Camera.  Have a look at
the code for osgviewerQt in OSG-3.2 or svn/trunk.

The other solution to the bug in the usage approach is to initialize the
StateSet of the Camera so it's suitable for using as the topmost Camera
that defines the state, the line is simply:

  camera->getOrCreateStateSet()->setGlobalDefaults();

Why this wasn't required before was the internally SceneView would override
the Camera's StateSet rewriting it's values to use the ones defined by
setGlobalDefaults(), however, this meant the any state that applications
would set on the viewer's Camera would be discarded which is the bug that
needed to be resolved.  By default View creates a master Camera and does
the camera->getOrCreateStateSet()->setGlobalDefaults(); for you so that is
no reason for SceneView to override the values.

The problem comes with applications that explicitly assign their own
osg::Camera but never set the state for it so you just end up with OpenGL
defaults, such as having depth test off - which results in the problem you
see.  The SceneView hide this so you never got to see the bug in the
original viewer setup code that you had.

Most OSG users aren't affected by this as they don't create their own
osg::Camera and assign it to the View(er). Unfortunately this invalid usage
slipped into OSG examples and was replicated by a few user applications.
 The OSG examples are now fixed.

Robert.


On 21 November 2013 15:05, Gianni Ambrosio <[email protected]> wrote:

>
> robertosfield wrote:
> > Does the problem appear with your own viewer?  Does you own viewer setup
> the Camera's replacing the viewer's master Camera?  Does this override
> neglect to set up any default OpenGL state?
> >
>
>
> I use the following class:
>
> class ViewerWidget : public osgQt::GLWidget, public
> osgViewer::CompositeViewer
>
> Here is a code snippet of the constructor:
>
> Code:
>
> ViewerWidget::ViewerWidget(QWidget* iParent, const QGLWidget*
> iShareWidget, Qt::WindowFlags iFlags)
> : osgQt::GLWidget(iParent, iShareWidget, iFlags)
> ,timer(0)
> {
>    osgViewer::View* view = new osgViewer::View;
>    view->setName("Main view");
>    addView(view);
>
>    view->setCamera(createCamera(viframework::viosg::screenWidth(),
> viframework::viosg::screenHeight()));
>    view->setCameraManipulator(new osgGA::TrackballManipulator);
>    initWindowManager(view);
> }
>
> osg::Camera* ViewerWidget::createCamera(int width, int height)
> {
>    osg::ref_ptr<osg::Camera> camera = new osg::Camera;
>    camera->setGraphicsContext(new osgQt::GraphicsWindowQt(this));
>    camera->setClearColor(osg::Vec4(0.2, 0.2, 0.6, 1.0));
>    camera->setViewport(new osg::Viewport(0, 0, width, height));
>
>    double aspect_ratio =
> 2.0*static_cast<double>(width)/static_cast<double>(height);
>    camera->setProjectionMatrixAsPerspective(30.0, aspect_ratio, 1.0,
> 10000.0);
>    return camera.release();
> }
>
> void ViewerWidget::initWindowManager(osgViewer::View* iView)
> {
>    osg::ref_ptr<osgWidget::WindowManager> wm = new
> osgWidget::WindowManager(iView, 1280.0f, 1024.0f, MASK_2D,
> osgWidget::WindowManager::WM_USE_RENDERBINS);
>    osg::Camera* camera = wm->createParentOrthoCamera();
>    SceneManager manager;
>    manager.getRoot()->addChild(camera);
>    manager.setWindowManager(wm);
>    wm->resizeAllWindows();
>
>    iView->addEventHandler(new osgWidget::MouseHandler(wm));
>    iView->addEventHandler(new osgWidget::ResizeHandler(wm, camera));
> }
>
> unsigned int viframework::viosg::screenHeight()
> {
>    osg::GraphicsContext::WindowingSystemInterface* wsi =
> osg::GraphicsContext::getWindowingSystemInterface();
>    osg::GraphicsContext::ScreenSettings settings;
>    osg::GraphicsContext::Traits traits;
>    wsi->getScreenSettings(traits, settings);
>    return static_cast<unsigned int>(settings.height);
> }
>
> unsigned int viframework::viosg::screenWidth()
> {
>    osg::GraphicsContext::WindowingSystemInterface* wsi =
> osg::GraphicsContext::getWindowingSystemInterface();
>    osg::GraphicsContext::ScreenSettings settings;
>    osg::GraphicsContext::Traits traits;
>    wsi->getScreenSettings(traits, settings);
>    return static_cast<unsigned int>(settings.width);
> }
>
>
>
>
> Cheers,
> Gianni
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=57362#57362
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to