|
- #include <osg/Shape>
- #include <osgViewer/Viewer>
- #include <osg/Geode>
- #include <osg/Node>
- #include <osg/Geometry>
- #include <osg/ShapeDrawable>
- #include <osgDB/ReadFile>
- #include <osg/Object>
- #include <osg/StateAttribute>
- #include <osg/CullFace>
- #include <osg/Texture>
- #include <osgDB/Registry>
- #include <osgText/Text>
- #include <osg/CameraNode>
- #include <osg/Matrix>
- #include <osgText/Font>
- #include <osg/Depth>
- #include <sstream>
- void main()
- {
- osg::Camera *camera=new osg::CameraNode;
- camera->setClearColor(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
- camera->setProjectionMatrix(osg::Matrix::ortho2D(0,1280,0,1024));
- camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
- camera->setViewMatrix(osg::Matrix::identity());
- camera->setClearMask(GL_DEPTH_BUFFER_BIT);
- camera->setRenderOrder(osg::CameraNode::POST_RENDER);
-
- osg::ref_ptr<osg::Geode> geode=new osg::Geode ;
- osg::ref_ptr<osg::TessellationHints> hits=new osg::TessellationHints;
- hits->setDetailRatio(5.0f);
- osg::ref_ptr<osg::ShapeDrawable> box=new osg::ShapeDrawable(new osg::Box(osg::Vec3(1.0f,1.0f,1.0f),1.0f),hits);
- osg::ref_ptr<osg::ShapeDrawable> sphere=new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(3.0f,3.0f,3.0f),1.0f),hits);
- osg::Vec4f color(1.0f,1.0f,0.0f,1.0f);
- box->setColor(color);
- sphere->setColor(color);
- osg::StateSet *state=box->getOrCreateStateSet();
- //osg::CullFace *cf=new osg::CullFace(osg::CullFace::BACK);
- //state->setAttributeAndModes(cf);
- state->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
- osg::StateSet *ss=sphere->getOrCreateStateSet();
- ss->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
- geode->addDrawable(box);
- geode->addDrawable(sphere);
- camera->addChild(geode);
-
- //osg::ref_ptr<osgText::Font> font=osgText::readFontFile("fonts/times.ttf");
- std::string font("fonts/Vera.ttf");
- osg::ref_ptr<osgText::Text> text=new osgText::Text;
- geode->addDrawable(text);
- text->setFont(font);
- text->setText("This is a simple example");
- text->setText("Hello");
- text->setPosition(osg::Vec3(150.0f,800.0f,0.0f));
- text->setAxisAlignment(osgText::Text::SCREEN);
- text->setAlignment(osgText::Text::CENTER_TOP);
- text->setCharacterSize(30.0f);
- text->setCharacterSizeMode(osgText::Text::SCREEN_COORDS);
- text->setFontResolution(128,128);
- text->setColor(osg::Vec4(1.0f,0.0f,0.0f,1.0f));
- text->setDataVariance(osg::Object::DYNAMIC);
- /*
- osg::StateSet *st=geode->getOrCreateStateSet();
- st->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
- st->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
- camera->addChild(st);
- */
-
- camera->addChild(geode);
- osg::Group *root=new osg::Group();
- //root->addChild(camera);
- root->addChild(camera);
- // bool osgDB::writeNodeFile(root,"start.osg");
- osgViewer::Viewer viewer;
- //viewer.getCamera()->setClearColor(osg::Vec4(0.0f,0.0f,1.0f,1.0f));
- viewer.setSceneData(root);
- viewer.realize();
- viewer.run();
- }
复制代码 现在的情况是编译没问题,运行只有一个背景。。。
请版主帮忙指出问题,怎么改,不要让我直接换成HUD的方式,主要是想通过纠错学习,谢谢!! |
|