OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Qt OsgEarth HudCamera Composition


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
aozdin
Newbie


Joined: 28 Feb 2018
Posts: 16

PostPosted: Fri Mar 16, 2018 10:34 am    Post subject:
Qt OsgEarth HudCamera Composition
Reply with quote

Hi,

I can not see hud camera text. I only see main camera output which is generated by osg Earth manipulator. This problem comes up with integration with Qt. Before integrating with Qt, this derived hud view example works great. I am sharing a sample of code. What is the reason that I could not see the text created with createText function. I think the problem is related to buffer bits again like in there http://forum.openscenegraph.org/viewtopic.php?t=17146

What should I do to solve this problem?

Best regards,

Code:




void ExampleWidget::addText(osg::ref_ptr<osg::Geode> geode)
{
osg::Vec3 position( 200.0f, 25.0f, 0.0f);
osgText::Text* text = new  osgText::Text;
std::string timesFont("fonts/arial.ttf");
text->setAlignment(osgText::TextBase::AlignmentType::LEFT_BOTTOM_BASE_LINE);
text->setFont(timesFont);
text->setPosition(position);
text->setText("HELLO WORLD !!!!!");
text->setCharacterSize(50.0);
geode->addDrawable( text );
}


osg::ref_ptr<osg::Camera> ExampleWidget::createHUD()
{
// create a camera to set up the projection and model view matrices, and the subgraph to draw in the HUD
osg::ref_ptr<osg::Camera> camera = new osg::Camera;

// set the projection matrix
camera->setProjectionMatrix(osg::Matrix::ortho2D(0,1280,0,1024));

// set the view matrix
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
camera->setViewMatrix(osg::Matrix::identity());

// only clear the depth buffer
camera->setClearMask(  GL_COLOR_BUFFER_BIT );
// draw subgraph after main camera view.
camera->setRenderOrder(osg::Camera::POST_RENDER);

// we don't want the camera to grab event focus from the viewers main camera(s).
camera->setAllowEventFocus(false);

camera->getOrCreateStateSet()->setAttributeAndModes( new osg::Depth( osg::Depth::LEQUAL, 0.0, 0.0) );

return camera.get();
}

ExampleWidget::ExampleWidget(QWidget* parent, Qt::WindowFlags f, osgViewer::ViewerBase::ThreadingModel threadingModel )
: QWidget(parent, f)
{
viewer = new osgViewer::Viewer;
setThreadingModel( threadingModel ) ;
setKeyEventSetsDone(0);

QWidget* widget1 = create();

QGridLayout* grid = new QGridLayout;   
grid->addWidget( widget1, 0, 0 );
setLayout( grid );

connect( &_timer, SIGNAL(timeout()), this, SLOT(update()) );
_timer.start( 10 );
}

QWidget* ExampleWidget::create( )
{
osg::ArgumentParser arguments(&argc,argv);
osg::ref_ptr<osg::Group> group = MapNodeHelper().load(arguments, viewer);//osg::ref_ptr<osg::Node> group = osgDB::readRefNodeFiles(arguments);
manipulator = new EarthManipulator(  /*arguments*/ );
viewer->setCameraManipulator( manipulator );

osgEarth::Config c;
c.add("srs","wgs84");
c.add("vdatum","egm96");
c.add( "x", 39.0  );
c.add( "y",  32.0);
c.add( "z", 1300 );
//c.add( "range", 0 );
c.add( "heading", 0.0 );
c.add( "pitch", -90.0 );      
Viewpoint v;
manipulator->zoom(0.0,0.0);
manipulator->setHomeViewpoint( Viewpoint(c) );

osg::ref_ptr<osg::Camera> hudCamera = createHUD();

osg::ref_ptr<osg::Geode> geode = new osg::Geode();
// turn lighting off for the text and disable depth test to ensure it's always ontop.
geode->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);

addText(geode);
hudCamera->addChild(geode);
hudCamera->setClearColor( osg::Vec4(255.0, 0.0, 0.0, 1.0) );

viewer->addEventHandler( new osgViewer::StatsHandler );

osgQt::GraphicsWindowQt* gw = createGraphicsWindow(0,0,500,500);
const osg::GraphicsContext::Traits* traits = gw->getTraits();
osg::Viewport* wp = new osg::Viewport( 0, 0, traits->width, traits->height );


hudCamera->setGraphicsContext( gw );
hudCamera->setViewport( wp );

viewer->getCamera()->setGraphicsContext( gw );
viewer->getCamera()->setViewport( wp );

group->setDataVariance(osg::Object::DataVariance::STATIC);
manipulator->setDataVariance( osg::Object::DataVariance::DYNAMIC );


osgUtil::Optimizer optimizer;
optimizer.optimize(group.get());

viewer->addSlave(hudCamera, false);
viewer->setSceneData(group);

addView( viewer );


return gw->getGLWidget();

}

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts osgEarth Android (and iOS) Chris Hanson General 0 Mon Jun 25, 2018 11:08 pm View latest post
No new posts Shader composition with multiple func... hartwigw General 1 Sat May 12, 2018 9:59 pm View latest post
No new posts Having issue with osgText rendering o... pixelord General 0 Mon Apr 16, 2018 4:16 am View latest post
No new posts osg::Geode is not seen when added as ... aozdin General 2 Wed Feb 28, 2018 1:42 pm View latest post
No new posts How to open shape file (.shp) or open... GISDeveloper General 0 Thu Oct 05, 2017 3:30 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP