Hi,

haven't looked at the code in detail, but in an ortho projection you can still put things in front of others by using the z coordinate.

jp

Akilan Thangamani wrote:
Hi robert,

True. I do follow the osgHud example. But I am trying to display lat, lon 
values as text on mouse move over texture set from buffer. Anyway we use our 
own tranformation. But I couldn 't set the transparency. Have a look @ my code 
and let me get the mistake i do.



Code:


osg::Camera* createTex()
{       
   osg::Group* group=new osg::Group;

   osg::Geometry  *geom;
osg::Camera* camera = new osg::Camera;
    camera->setProjectionMatrix(osg::Matrix::ortho2D(0,1920,0,1200));
    camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
    camera->setViewMatrix(osg::Matrix::identity());
    camera->setClearMask(GL_DEPTH_BUFFER_BIT);
camera->setRenderOrder(osg::Camera::POST_RENDER); camera->setAllowEventFocus(true);

    {
                        
                osg::Vec3 top_left(0.0f ,0.0f ,1200.0f);
                osg::Vec3 bottom_left(0.0f ,0.0f ,0.0f);
                osg::Vec3 bottom_right(1920.0f ,0.0f, 0.0f);
                osg::Vec3 top_right(1920.0f, 0.0f, 1200.0f);

                geom = new osg::Geometry;

        
                osg::Vec3Array* vertices = new osg::Vec3Array(4);


        
                (*vertices)[0] = top_left;
                (*vertices)[1] = bottom_left;
                (*vertices)[2] = bottom_right;  
                (*vertices)[3] = top_right;
                geom->setVertexArray(vertices);

osg::Vec2Array* texcoords = new osg::Vec2Array(4);

                (*texcoords)[0].set(0.0f,1.0f);
                (*texcoords)[1].set(0.0f,0.0f);
                (*texcoords)[2].set(1.0f,0.0f);
                (*texcoords)[3].set(1.0f,1.0f);

                geom->setTexCoordArray(0,texcoords);

                osg::Vec3Array* normals = new osg::Vec3Array(1);

                (*normals)[0].set(0.0f,0.0f,1.0f);
                geom->setNormalArray(normals);
                geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
osg::Vec4Array* colors = new osg::Vec4Array(1);
                (*colors)[0].set(1.0f,1.0f,1.0f,0.2f);
                geom->setColorArray(colors);
                geom->setColorBinding(osg::Geometry::BIND_OVERALL);

                geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4));
osg::Geode* geom_geode = new osg::Geode;
                geom_geode->addDrawable(geom);

texture = new osg::Texture2D;
                texture->setName("TEXTURE");                                    
   
texture->setDataVariance(osg::Object::DYNAMIC); texture->setResizeNonPowerOfTwoHint(false);

                // Setting buffer
osg::Image* image = new osg::Image; image->setName("BUFFER"); image->setOrigin(osg::Image::BOTTOM_LEFT); image->setImage(buf_width, buf_height, 1, GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE,buf, osg::Image::NO_DELETE);
                texture->setImage(image);    
                osg::StateSet* stateset = geom->getOrCreateStateSet();
                
stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);       
             
                stateset->setMode(GL_LIGHTING, osg::StateAttribute::OVERRIDE | 
osg::StateAttribute::OFF);
                stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
                camera->addChild(geom_geode);
        }

    return camera;
}

osg::Node* createLatLonLabel()
{
        osg::Group* root=new osg::Group;

        osg::Camera* camera = new osg::Camera;
        root->addChild(camera);

        camera->setProjectionMatrix(osg::Matrix::ortho2D(0,1920,0,1200));
        camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
        camera->setViewMatrix(osg::Matrix::identity());
        camera->setClearMask(GL_DEPTH_BUFFER_BIT);
        camera->setRenderOrder(osg::Camera::POST_RENDER);    
        camera->setAllowEventFocus(true);

        {               
        osg::Geode* geode = new osg::Geode();
std::string timesFont("fonts/arial.ttf"); osg::StateSet* stateset = geode->getOrCreateStateSet();

        stateset->setMode(GL_LIGHTING, osg::StateAttribute::OVERRIDE | 
osg::StateAttribute::OFF);
        stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
        stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
osg::Vec3 position(0.0f,0.0f,0.0f);
        {
            latLonDisp = new  osgText::Text;
            geode->addDrawable( latLonDisp );

            latLonDisp->setFont(timesFont);
            latLonDisp->setCharacterSize(15);
            latLonDisp->setFontResolution(25,25);
            latLonDisp->setPosition(position);
latLonDisp->setText("(0,0)"); latLonDisp->setAlignment(osgText::Text::CENTER_TOP);
            latLonDisp->setAxisAlignment(osgText::Text::XY_PLANE);   
                        
        }               
        camera->addChild(geode);
    }

        return root;
}

main()
{

.....
.............
                // Init image buffer
                initImage();
                                
                 // construct the viewer.
                 osgViewer::CompositeViewer viewer;
                 osgViewer::Viewer::Windows windows;
// Main View { osgViewer::View* view = new osgViewer::View;
                        viewer.addView(view);                           
                        view->setSceneData(createLatLonLabel());                
     
                        view->setUpViewAcrossAllScreens();                      
                     
                        viewer.getWindows(windows);
                        if (windows.empty()) return 1;
                        osgGA::TrackballManipulator* tm=new 
osgGA::TrackballManipulator;
                        view->setCameraManipulator(tm);                         
                                                     
} // Create HUD {
                        osg::Camera* hudCamera = createTex();

                        hudCamera->setGraphicsContext(windows[SCREEN_NO]);
                        
hudCamera->setViewport(0,0,windows[SCREEN_NO]->getTraits()->width, 
windows[SCREEN_NO]->getTraits()->height);
osgViewer::View* hudView = new osgViewer::View;
                        hudView->setCamera(hudCamera);
                        osgGA::TrackballManipulator* tm=new 
osgGA::TrackballManipulator();              
                        hudView->setCameraManipulator(tm);   

                        
                        hudView->addEventHandler(new PickModeHandler());
                        hudView->addEventHandler( new 
osgGA::StateSetManipulator(hudView->getCamera()->getOrCreateStateSet()) );
                
                        viewer.addView(hudView);
                }

}





Thanks

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





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.

This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. MailScanner thanks Transtec Computers for their support.

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to