Hi,

I want to put a IVE Model in the viewer which renders a Texture2D Image as the 
viewer's whole background. 
Now, I put the texture image into a camera and rendered as the background 
successfully. The code is below:

Code:

-(osg::Node *) create2DBGTexture 
{ 
   unsigned int w = 480; 
   unsigned int h = 320; 
    
   float vx = (float)w; 
   float vy = (float)h; 
    
   osg::ref_ptr<osg::Geometry> rectBG_geom = new osg::Geometry; 
    
   osg::Vec3Array * vertices = new osg::Vec3Array; 
   vertices->push_back(osg::Vec3(0.0, 0.0, -1.0)); 
    vertices->push_back(osg::Vec3(0.0, vy, -1.0)); 
    vertices->push_back(osg::Vec3(vx, vy, -1.0)); 
    vertices->push_back(osg::Vec3(vx, 0.0, -1.0)); 
    rectBG_geom->setVertexArray(vertices); 
    
    osg::Vec2Array * texcoords = new osg::Vec2Array; 
    texcoords->push_back(osg::Vec2(0.0, 0.0625)); 
    texcoords->push_back(osg::Vec2(0.0, 0.9375)); 
    texcoords->push_back(osg::Vec2(1.0, 0.9375)); 
    texcoords->push_back(osg::Vec2(1.0, 0.0625)); 
    rectBG_geom->setTexCoordArray(0,texcoords); 
    
    osg::Vec3Array * normals = new osg::Vec3Array; 
    normals->push_back(osg::Vec3(0.0f,0.0f,1.0f)); 
    rectBG_geom->setNormalArray(normals); 
    rectBG_geom->setNormalBinding(osg::Geometry::BIND_OVERALL); 

   rectBG_geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4)); 
    
   BG_image = new osg::Image; 
   BG_image->setImage(AVWidth, AVHeight, 1, GL_RGBA, GL_BGRA, GL_UNSIGNED_BYTE, 
pAVImage, osg::Image::NO_DELETE); 
    
    BG_texture = new osg::Texture2D; 
    BG_texture->setDataVariance(osg::Object::DYNAMIC); 
   BG_texture->setImage(BG_image); 
   BG_texture->setResizeNonPowerOfTwoHint(false); 
   BG_texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::NEAREST); 
   BG_texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::NEAREST); 

   osg::StateSet* stateset = rectBG_geom->getOrCreateStateSet(); 
    
stateset->setTextureAttributeAndModes(0,BG_texture,osg::StateAttribute::ON); 
    
   osg::Geode * BG_geode = new osg::Geode; 
    BG_geode->addDrawable(rectBG_geom); 
    
   return BG_geode; 
} 

-(int)   initOsgTree 
{ 
   int dwError = 0; 
    
   osg::setNotifyLevel(osg::DEBUG_INFO); 
    
   // camera 
   unsigned int w = 480; 
   unsigned int h = 320; 
    
   //create and attach ortho camera for hud text 
   osg::ref_ptr<osg::Camera> hudCamera = new osg::Camera; 
   hudCamera->setProjectionMatrix(osg::Matrix::ortho2D(0,w,0,h)); 
   hudCamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); 
   hudCamera->setViewMatrix(osg::Matrix::identity()); 
   hudCamera->setClearMask(GL_DEPTH_BUFFER_BIT); 
   hudCamera->setRenderOrder(osg::Camera::POST_RENDER); 
    
   osg::ref_ptr<osg::Group> MARRoot = new osg::Group; 
    
MARRoot->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF); 
   hudCamera->addChild([self create2DBGTexture]); 
   MARRoot->addChild(hudCamera.get()); 
    
   // viewer 
   MARViewer = new osgViewer::Viewer(); 
   MARViewer->setSceneData(MARRoot.get()); 
   MARViewer->realize(); 
   MARViewer->frame(); 
    
   return dwError; 
} 




My question is: 
How do i put the model in the viewer so that it can be showed in the front of 
the background? Use two cameras? Put the model in another camera, then add this 
camera as the slave camera into viewer? I ever tried it, but it did not work, 
maybe my code is wrong. Maybe my thought is not right.
I hope you can give me a hand to help me to solve this question. I will 
appreciate you  very much.

 
Thank you!

Cheers,
Tang

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





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

Reply via email to