|
不停的调用text->setText(msg),为什么程序会崩溃。调试的时候倒是正常的。
代码如下:
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <iostream>
#include <osgText/Text>
#include <osgGA/TrackballManipulator>
int main( int argc, char **argv )
{
// read the scene from the list of file specified commandline args.
osg::ref_ptr<osg::Group> group = new osg::Group;
osg::ref_ptr<osg::Node> cow = osgDB::readNodeFile("cow.osg");
group->addChild(cow.get());
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
osg::ref_ptr<osgText::Text> text = new osgText::Text;
text->setText(L"HELLO WORLD 你好");
text->setFont("fonts/simkai.ttf");
text->setPosition(osg::Vec3f(100.0,100.0,-0.10));
geode->addDrawable(text.get());
osg::Camera* camera = new osg::Camera;
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
camera->setProjectionMatrixAsOrtho2D(0,1280,0,1024);
camera->setViewMatrix(osg::Matrix::identity());
camera->setClearMask(GL_DEPTH_BUFFER_BIT);
camera->addChild(geode.get());
camera->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
group->addChild(camera);
// construct the viewer.
osgViewer::Viewer viewer;
// set the scene to render
viewer.setSceneData(group.get());
viewer.setCameraManipulator(new osgGA::TrackballManipulator());
viewer.realize();
char msg[256];
while (!viewer.done())
{
viewer.frame();
double time = viewer.elapsedTime();
sprintf(msg,"time = %f",time);
text->setText(msg);
}
return 0;
}
代码的目的是为了显示程序已经运行多少时间。
谢谢。 |
|