|
#include "stdafx.h"
#include <osgUtil/Optimizer>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgDB/Registry>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osg/Geode>
#include <osg/Camera>
#include <osg/ShapeDrawable>
#include <osg/Sequence>
#include <osg/PolygonMode>
#include <osg/io_utils>
#include <osgText/Font>
#include <osgText/Text>
osg::Group* createHUDText()
{
osg::Geode* geode = new osg::Geode;
////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Examples of how to set up axis/orientation alignments
//
osg::Vec3 pos(10,10,10);
osg::Vec4 color(1,1,1,1);
osgText::Text* text7 = new osgText::Text;
text7->setColor(color);
text7->setFont("fonts/times.ttf");
text7->setCharacterSize(30);
text7->setPosition(pos);
text7->setAxisAlignment(osgText::Text::SCREEN);
text7->setCharacterSizeMode(osgText::Text::OBJECT_COORDS_WITH_MAXIMUM_SCREEN_SIZE_CAPPED_BY_FONT_HEIGHT);
text7->setText("CharacterSizeMode OBJECT_COORDS (default)");
geode->addDrawable(text7);
//一下应该是创建一个球
osg::ShapeDrawable* shape = new osg::ShapeDrawable(new osg::Sphere(pos,100));
shape->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::ON);
geode->addDrawable(shape);
//geode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
//geode->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
osg::Group* rootNode = new osg::Group;
rootNode->addChild(geode);
return rootNode;
}
int main(int argc, char** argv)
{
osgViewer::Viewer *viewer = new osgViewer::Viewer ;
osg::Group* group = new osg::Group;
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(createHUDText());
camera->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
group->addChild(camera);
group->addChild(osgDB::readNodeFile("D:\\3Ddata\\moxigd.ive"));
viewer->setSceneData(group);
viewer->run();
}
那位大哥帮我看看上面的代码有什么问题??为什么我看不见我的文字呢?但是我把mian函数中的
group->addChild(camera);改成group->addChild(createHUDText());就能看见文字
把createHUDText()函数中的osg::Vec3 pos(10,10,10)改成osg::Vec3 pos(0,0,0);也能看见文字
但是这样文字就不能放大或缩小?这是为什么啊 ??是我的相机设置问题??
高手帮忙啊!!!先谢过了。 |
|