回复 2# array #include<osgViewer/ViewerEventHandlers> #include <osgDB/ReadFile> #include <osgViewer/Viewer> #include <osg/Geode> #include <osg/Depth> #include <osg/CameraNode> #include <osgText/Text> osg::Node* createHUD() {
osg::Geode* geode = new osg::Geode();
//设置字体,必须是汉字字体,如果没有可以自己找个黑体宋体什么的,这里是华文彩云。 // std::string caiyun("fonts/STCAIYUN.TTF");
std::string caiyun("fonts/arial.ttf");
//设置状态,关闭灯光
osg::StateSet* stateset = geode->getOrCreateStateSet();
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
osg::Vec3 position(600.0f,500.0f,0.0f);
//设置字体属性
osgText::Text* text = new osgText::Text;
geode->addDrawable(text);
//设置字体
text->setFont(caiyun);
//设置位置
text->setPosition(position);
text->setText(
www.osgChina.org);
//设置相机
osg::Camera* camera = new osg::CameraNode;
//设置透视矩阵
camera->setProjectionMatrix(osg::Matrix:rtho2D(600,1200,0,600));// 1360...768
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
//得到默认设置
camera->setViewMatrix(osg::Matrix::identity());
//设置背景为透明,否则的话可以设置ClearColor
camera->setClearMask(GL_DEPTH_BUFFER_BIT);
//设置渲染顺序,必须在最后渲染
camera->setRenderOrder(osg::CameraNode:OST_RENDER);
camera->addChild(geode);
return camera;
};
int main( int argc, char **argv ) {
osgViewer::Viewer viewer;
osg::ref_ptr<osg::Node> scene = osgDB::readNodeFile("ceep.ive");
osg::ref_ptr<osg::Group> group = new osg::Group;
if (scene.valid())group->addChild(scene.get());
//创建HUD //
group->addChild(createHUD());
group->addChild(createHUD());
viewer.addEventHandler(new osgViewer::WindowSizeHandler());
viewer.setSceneData(group.get());
viewer.realize();
viewer.run() ;
return 0;
} 代码就是教材上显示文字的那一节,提示wanging:could not find plugin to read objects from fine.D:\....\fonts\arial.ttf osgdb_tiffd.dll和osgdb_freetype.dll都生成了,不知是什么原因找不到插件。请多指教,谢谢 |