TA的每日心情 | 开心 2020-3-20 17:50 |
---|
签到天数: 1 天 [LV.1]初来乍到
|
楼主 |
发表于 2020-4-14 10:15:59
|
显示全部楼层
参考使用 PlaceNode 就可以。不使用Js ,因为不支持中文。
所以最后还是后台代码使用来实现
GeoPoint pntt(osgEarth::Registry::instance()->getGlobalGeodeticProfile()->getSRS(),0.0,0.0, 1000.0, ALTMODE_ABSOLUTE);
PlaceNode *place = new PlaceNode(mapNode, pntt, "" );
osg::Group* attachedpoint = place->getAttachPoint();
//this must be first - boundind box
{
osgText::Text* t = new osgText::Text();
t->setAutoRotateToScreen( false );
t->setCharacterSizeMode( osgText::Text::OBJECT_COORDS );
t->setCharacterSize( 32.0f );
// t->setColor(Color::Yellow );
t->setBoundingBoxColor( osg::Vec4d(1.0, 1.0, 1.0, 0.5));
t->setBoundingBoxMargin(3);
t->setPosition(osg::Vec3d(0.0, 0.0, 0.0));
t->setDrawMode(1|2|4);
t->setText("onetwothree\nfour\nfive");
t->setAlignment(osgText::Text::AlignmentType::RIGHT_CENTER);
osgText::Font* font= osgText::readFontFile( "fonts/arial.ttf" );
t->setFont(font);
osg::Geode* geode = new osg::Geode();
geode->addDrawable(t);
osg::StateSet* stateSet = geode->getOrCreateStateSet();
stateSet->setAttributeAndModes( new osg:epth(osg::Depth::ALWAYS), 1 );
Registry::shaderGenerator().run(geode);
attachedpoint->addChild(geode);
}
//this must be second
{
osgText::Text* t = new osgText::Text();
t->setAutoRotateToScreen( false );
t->setCharacterSizeMode( osgText::Text::OBJECT_COORDS );
t->setCharacterSize( 32.0f );
t->setPosition(osg::Vec3d(0.0, 0.0, 0.0));
t->setBoundingBoxMargin(0);
t->setBoundingBoxColor( osg::Vec4d(0.0, 0.0, 0.0, 0.5));
t->setBackdropColor(osg::Vec4(0.3, 0.3, 0.3, 1));
t->setBackdropType(osgText::Text::OUTLINE);
t->setText("onetwothree\nfour\nfive");
t->setAlignment(osgText::Text::AlignmentType::RIGHT_CENTER);
osgText::Font* font= osgText::readFontFile( "fonts/arial.ttf" );
t->setFont(font);
t->setDrawMode(1|2|4);
osg::Geode* geode = new osg::Geode();
geode->addDrawable(t);
osg::StateSet* stateSet = geode->getOrCreateStateSet();
stateSet->setAttributeAndModes( new osg::Depth(osg::Depth::ALWAYS), 1 );
attachedpoint->addChild(geode);
Registry::shaderGenerator().run(geode);
} |
|