[osg-users] problem with hud overlay

2010-11-02 Thread Ted Morris
Hi,

I thought this would be extremely trivial. But, perhaps I am missing something. 
I have a HUD ortho2D camera slaved to a main view window camera, rendering a 
polygon. I need to move the polygon when I resize the main window, which I 
attempted by simply placing the geode underneath a MatrixTransform node, first 
setting it to identity() and placing it under the HUD camera. However, when I 
did this, the polygon no longer is rendered in the window at all. 

Note that everything renders fine with a Geode before I placed it under the 
MatrixTransform. 

To recap this is essentially what I tried:

m_HUDcam = new osg::Camera;

 m_HUDcam-setProjectionMatrix( osg::Matrix::ortho2D(0,   
m_viewersize.GetX(),0, m_viewersize.GetY()));

m_HUDcam-setReferenceFrame(osg::Transform::ABSOLUTE_RF);

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-setChild(0, geode);

  //  construct the polygon(s) primitive(s) here ...
  
 // attach it to the HUD camera -- now the polygon(s) don't display.
 m_HUDcam-addChild(matrixtransfm);

 // but uncommenting this out, and polygon displays :
 // m_HUDcam-addChild(geode);

 // viewport, etc.
 m_HUDcam-setViewport(  0 ,0, m_viewersize.GetX(),   
m_viewersize.GetY());

 m_HUDcam-setGraphicsContext(gw);

 m_viewer-addSlave(m_HUDcam, false);

 

 

Thank you!

Cheers,
Ted

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=33347#33347





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] problem with hud overlay

2010-11-02 Thread Jean-Sébastien Guay

Hello Ted,

Gladly you included the code you use, which allowed me to know exactly 
why you don't see anything. Look at this line:



matrixtransfm-setChild(0, geode);


Why did you use setChild(0, geode) instead of addChild(geode)? It is a 
mistake. Look at the first few lines of osg::Group::setChild() 
(MatrixTransform is an indirect subclass of Group):


bool Group::setChild( unsigned  int i, Node* newNode )
{
if (i_children.size()  newNode)
{
// ...
}
else return false;
}

So since your MatrixTransform has no children initially, setChild(0, 
geode) does nothing. There is no index 0 in its children vector, so it 
can't set it to the node you passed...


Try addChild() instead. Incidentally, if you had checked the return 
value of setChild() it would have been false, telling you it had failed 
(I'm not criticising, just making a remark, I wouldn't have checked the 
return value either ;-) ). Or, if you had stepped through your program 
in a debugger, you would have seen that after the call to setChild(0, 
geode), the children vector of the MatrixTransform was still empty.


Hope this helps,

J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] problem with hud overlay

2010-11-02 Thread Ted Morris
Excellent-- Thanks very much!

Cheers,
Ted

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=33350#33350





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org