[osg-users] CompositeViewer Node render order problem Win32 osg 3.4

Robert Osfield robert.osfield at gmail.com
Mon Nov 30 09:40:19 PST 2015


Hi Ted,

With a quick scan of your post I can't spot a reason for the redendering
order issue, in general I would expect that OSG-3.4 will be functioning
more correctly than OSG-2.8.x as there have been lots of improvements over
the years, sometimes fixes actually mean that something that worked by
fluke before no longer works as the OSG is actually doing what the settings
are telling it to rather than ignoring them.  So spotting the undefined
elements may well be key.

As a general note, osgViewer::CompositeViewer should have osgViewer::View
attached to it NOT osgViewer::Viewer as you are doing - it's a composite of
View's not composite of Viewer.  If you look at all the OSG example they
illustrate the correct usage.  It might be that this helps address the
problem you are seeing.

If it doesn't then modifying an existing OSG example to illustrate your
usage case and share this as a complete example so that others can
reproduce the problem first hand.

Robert.


On 30 November 2015 at 16:39, ted morris <ted.morris at gmail.com> wrote:

>
> Greetings OSG'ers.
>
> I have a program which utilizes CompositeViewer to render a "corner
> window" view of my scene graph, within a bigger main window view. To
> achieve a boarder effect around the corner window viewport, a HUD overlay
> used to render a grey box underneath the 2nd view corner window.
>
> It worked without a hitch  in an older version, 2.8.5 win32 of
> OpenSceneGraph (build with VisualStudio).
>
> But when I recompiled the program with a later built version (CMake.exe/VS
> 2013), I get rather strange object rendering order problems with the
> objects in the same scene graph with the **2nd, corner window**  of the
> osgCompositeViewer.  The **first main window** renders perfectly fine. The
> essence of the code is below. A lot of extra code  is used for determining
> the appropriate window and HUD boarder 'frame' dimensions and camera view
> frustums, but barring that,  it is pretty straight forward and not much to
> it, I think.
>
> To simplify the code a little bit for brevity, I have the removed
> Trackball code because with much testing on various configurations this
> doesn't change the observed behavior anyway (nor does any lighting mode).
>
> I did try clone(osg::CopyOp::SHALLOW_COPY) of the entire scene graph
> model, and even re-creating parts ofit from scratch and the same
> strange rendering order behavior resulted.
>
> Any advice or insights would be greatly appreciated,
>
> thanks all,
>
> ted
>
>
> <snip>
> .
> .
> .
> // osgViewers decl on the heap
>     osg::ref_ptr<osgViewer::Viewer>  m_viewer;
> osg::ref_ptr<osgViewer::Viewer>  m_OVERLAYviewer;
> osg::ref_ptr<osgViewer::CompositeViewer>  m_dualviewer;
> osg::Camera  * m_HUDcam;
> // view manipulators configured and constrained as appropriate...
> // <-- code removed for brevity...>
> osgGA::NodeTrackerManipulator   * m_Camera_followcar;
> osgGA::NodeTrackerManipulator::TrackerMode   m_trackerMode;
> osgGA::NodeTrackerManipulator::RotationMode  m_rotationMode;
> osgGA::TrackballManipulator  * m_tbm;
>
> // NOTE: gw is a wxWidgets OpenGL context canvas set up earlier...
> m_viewer->getCamera()->setGraphicsContext(gw);
> m_viewer->getCamera()->setClearColor(osg::Vec4(153./0xff, 216./0xff,
> 238./0xff, 1.0));
> // use CullMask to hide rendering of specific nodes in the scene
> m_viewer->getCamera()->setCullMask(0x04);
>
> m_viewer->getCamera()->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
>
> // create a camera to set up the projection and model view matrices, and
> the subgraph to drawn in the HUD
>     osg::Camera* camera = new osg::Camera;
>
>     // set the projection matrix
>     //camera->setProjectionMatrix(osg::Matrix::ortho2D(0,1280,0,1024));
> m_width_fraction_of_mainW  = 0.225;  // 0.25;
> m_height_fraction_of_mainW = 0.275; //(1.0/3.0);
> // ll => "lower left", ur => "upper right"
> int xll = -(int)(m_width_fraction_of_mainW  * m_viewersize.GetX())/2;
> int yll = -(int)(m_height_fraction_of_mainW * m_viewersize.GetY())/2;
> int yur = -yll;
> double left = (double)xll/(double)(yur-yll);
> double right = -left;
> double bottom = -0.5;
> double top = 0.5;
> double zfar = 13000.0; // make arbitrarily huge ... but not too big so for
> things like a skydome won't get clipped
> double znear = 4.5;
> // scale everything so clipping plane is about 0.25 meters
> double scale_fac = 0.5/znear;
>
> znear  *= scale_fac;
> left   *= scale_fac;
> right  *= scale_fac;
> top    *= scale_fac;
> bottom *= scale_fac;
>
> camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
>     // draw subgraph after main camera view.
>
>     // we don't want the camera to grab event focus from the viewers main
> camera(s).
>     //camera->setAllowEventFocus(true);
> camera->setAllowEventFocus(false);
>
> double cornerX0 = 1.0 - m_width_fraction_of_mainW;
> double cornerY0 = 1.0 - m_height_fraction_of_mainW;
> camera->setViewport(
>                 (int)( cornerX0 * m_viewersize.GetX()+5 ),
>                 (int)( cornerY0 * m_viewersize.GetY()+5 ),
> (int)( m_width_fraction_of_mainW *  m_viewersize.GetX()-5 ),
> (int)( m_height_fraction_of_mainW * m_viewersize.GetY()-5 )
> );
> zfar = 10000;
> camera->setProjectionMatrixAsFrustum(left,right, bottom, top, znear, zfar);
> camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
> camera->setGraphicsContext(gw);
> camera->setCullMask(0x02);
> camera->setRenderOrder(osg::Camera::POST_RENDER,1);
> // =false: we don't want the camera to grab event focus from the viewers
> main camera(s).
> camera->setAllowEventFocus(true); //(false);
> m_OVERLAYviewer->setCamera(camera);
> m_OVERLAYviewer->getCamera()->setGraphicsContext(gw);
>
> // <!-- basic NodeTracker manipulator code removed for brevety... -->
> m_Camera_followcar = new osgGA::NodeTrackerManipulator;
> .
> .
> .
> // set up the scene for the camera and camera view using the loaded scene
> // model
> m_OVERLAYviewer->setSceneData(themodel);
> // try HUD slave cam for drawing a boarder
> m_HUDcam = new osg::Camera;
>
> //HUDcam->setProjectionMatrixAsOrtho(0.5*xll,0.5*xur,0.5*yll, 0.5*yur,
> -1000.0,1000.0);
> m_HUDcam->setProjectionMatrix( osg::Matrix::ortho2D(0,
> m_viewersize.GetX(),0, m_viewersize.GetY()));
> // don't let other cam influence this camera's transform view matrix
>     m_HUDcam->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
>
>     // only clear the depth buffer for HUD, so other pixels behind it
> don't get erased.
>     m_HUDcam->setClearMask(GL_DEPTH_BUFFER_BIT);
>
> // draw subgraph after main camera view.
>     m_HUDcam->setRenderOrder(osg::Camera::POST_RENDER,0);
> m_HUDcam->setAllowEventFocus(false);
>
> // create the frame
> osg::MatrixTransform * matrixtransfm = new osg::MatrixTransform;
> matrixtransfm->setMatrix(osg::Matrix::identity());
> // create the Geode (Geometry Node) to contain all our osg::Geometry
> objects.
>     osg::Geode* geode = new osg::Geode();
> osg::StateSet* stateset = geode->getOrCreateStateSet();
>     stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
> matrixtransfm->addChild(geode);
>
> osg::ref_ptr<osg::Vec4Array> shared_colors = new osg::Vec4Array;
> shared_colors->push_back(osg::Vec4(0.75f,0.75f,0.75f,1.0f));
> // same trick for shared normal.
>     osg::ref_ptr<osg::Vec3Array> shared_normals = new osg::Vec3Array;
>     shared_normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f));
>
> // create POLYGON
> {
>         // create Geometry object to store all the vertices and lines
> primitive.
>         osg::Geometry* polyGeom = new osg::Geometry();
>
>         // this time we'll a C arrays to initialize the vertices.
>         // note, anticlockwise ordering.
>         // note II, OpenGL polygons must be convex plan polygons,
> otherwise
>         // undefined results will occur.  If you have concave polygons or
> ones
>         // that cross over themselves then use the osgUtil::Tessellator to
> fix
>         // the polygons into a set of valid polygons.
> double xll =  -2.0;
> double yll =  -2.0;
> double xlr =  m_width_fraction_of_mainW  * m_viewersize.GetX()+2;
> double yur =  m_height_fraction_of_mainW * m_viewersize.GetY()+2;
>         osg::Vec3 myCoords[] =
>         {
>             osg::Vec3( xll,yll, 0),
>             osg::Vec3( xlr, yll, 0),
>             osg::Vec3( xlr, yur, 0),
>             osg::Vec3(xll, yur, 0)
>         };
>
> m_HUDxaxis = xlr - xll;
> m_HUDyaxis = yur - yll;
>
>         int numCoords = sizeof(myCoords)/sizeof(osg::Vec3);
>
>         osg::Vec3Array* vertices = new osg::Vec3Array(numCoords,myCoords);
>
>         // pass the created vertex array to the points geometry object.
>         polyGeom->setVertexArray(vertices);
>
>         // use the shared color array.
>         polyGeom->setColorArray(shared_colors.get());
>         polyGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
>
>
>         // use the shared normal array.
>         polyGeom->setNormalArray(shared_normals.get());
>         polyGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
>
>         // This time we simply use primitive, and hardwire the number of
> coords to use
>         // since we know up front,
>         polyGeom->addPrimitiveSet(new
> osg::DrawArrays(osg::PrimitiveSet::POLYGON,0,numCoords));
>
>         // add the points geometry to the geode.
>         geode->addDrawable(polyGeom);
>     }
> matrixtransfm->setMatrix(osg::Matrix::translate(-200.0,-200.0,0.0));
> m_HUDcam->addChild(matrixtransfm);
>
> m_HUDcam->setViewport(  0 ,0, m_viewersize.GetX(), m_viewersize.GetY());
>
> m_HUDcam->setGraphicsContext(gw);
>
> m_viewer->addSlave(m_HUDcam, false);
>
> // <!-- basic trackball manipulator code removed for brevety... -->
> m_tbm = new osgGA::TrackballManipulator;
> .
> .
>   .
> // take the loaded scene graph, "themodel" and associate with the 'main
> window' osgViewer
> m_viewer->setSceneData(themodel);
>
>
> m_viewer->getCamera()->setViewport(0,0,m_viewersize.GetWidth(),m_viewersize.GetHeight());
> m_viewer->addEventHandler(new osgViewer::StatsHandler);
>     m_viewer->setThreadingModel(osgViewer::Viewer::SingleThreaded);
>     double zfocal = 1.5; // w.r.t normalized screen coords were min/max
> vertical= -0.5/+0.5
> this->AdjustPerspective(zfocal);
> int width = m_viewersize.GetWidth();
>
> m_dualviewer = new osgViewer::CompositeViewer;
> m_dualviewer->addView(m_viewer);
> m_dualviewer->addView(m_OVERLAYviewer);
> <snip>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20151130/48835076/attachment-0003.htm>


More information about the osg-users mailing list