|
在写osg文字这一节中显示汉字和osg文件(或ive文件)时,都不能显示
代码如下:
osg::ref_ptr<osg::Geode> createText()
{
osg::ref_ptr<osgText::Text> text = new osgText::Text();
osg::ref_ptr<osg::Geode> geode = new osg::Geode();
text->setFont("font/simhei.ttf");
text->setText(L"显示ive模型");
text->setPosition(osg::Vec3(100, 500, 0));
text->setColor(osg::Vec4(1.0, 0.0, 0.0, 0.0));
text->setCharacterSize(30.0);
text->setLayout(osgText::Text::VERTICAL);
//设置边框对其绘制
text->setDrawMode(osgText::Text::BOUNDINGBOX | osgText::Text::TEXT);
geode->addDrawable(text);
return geode;
}
osg::ref_ptr<osg::Camera> createCamera()
{
osg::ref_ptr<osg::Camera> ca = new osg::Camera();
osg::ref_ptr<osg::Geode> text = createText();
osg::ref_ptr<osg::StateSet> ss = text->getOrCreateStateSet();
ss->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
ss->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
ca->setProjectionMatrix(osg::Matrixd:rtho2D(0, 1024, 0, 800));
//设置视图矩阵,同是保证不被场景中的其他位置变换影响,使用绝对帧引用
ca->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
ca->setViewMatrix(osg::Matrixd::identity());
ca->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
//渲染顺序
ca->setRenderOrder(osg::Camera:OST_RENDER);
ca->addChild(text.get());
return ca;
}
int main()
{
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer();
osg::ref_ptr<osg::Group> root = new osg::Group();
osg::ref_ptr<osg::Node> ceep = osgDB::readNodeFile("ceep.ive");
root->addChild(ceep);
root->addChild(createCamera());
osgUtil::Optimizer op;
op.optimize(root.get());
viewer->setSceneData(root.get());
viewer->realize();
return viewer->run();
} |
|