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

Joined: 28 Feb 2018
Posts: 16

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


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

What should I do to solve this problem?

Best regards,


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->setText("HELLO WORLD !!!!!");
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

// set the view matrix

// only clear the depth buffer
camera->setClearMask(  GL_COLOR_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->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 ) ;

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( "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->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.

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 );

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

osgUtil::Optimizer optimizer;

viewer->addSlave(hudCamera, false);

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 Use PNG as texture for terrain in osg... Rodrigo General [3rdparty] 12 Mon Jan 07, 2019 5:13 pm View latest post
No new posts class osgEarth::Map has no member nam... Rodrigo General [3rdparty] 3 Wed Jan 02, 2019 4:39 pm View latest post
No new posts osgEarth often crashes in multi-displ... xdfanfan General 0 Mon Nov 26, 2018 8:07 am View latest post
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

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