|
发表于 2011-11-2 15:27:25
|
显示全部楼层
- //设置渲染顺序为POST
- camera->setRenderOrder(osg::Camera::POST_RENDER);
- //设置为不接收事件,始终不得到焦点
- camera->setAllowEventFocus(false);
- osg::ref_ptr<osg::Geode> geode = new osg::Geode();
- osg::ref_ptr<osg::StateSet> stateset = geode->getOrCreateStateSet();
- //关闭光照
- stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
- //关闭深度测试
- stateset->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
- //设置文字
- osg::ref_ptr<osgText::Text> text = new osgText::Text();
- osg::ref_ptr<osgText::Font> font = new osgText::Font();
- font = osgText::readFontFile("simhei.ttf");
- text->setFont(font.get());
- text->setText(L"测试文字");
- text->setPosition(osg::Vec3(0.0f, 0.0f, 0.0f));
- text->setCharacterSize(24.0f);
- text->setColor(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f));
- //text->setDrawMode(osgText::Text::TEXT|osgText::Text::BOUNDINGBOX);
- text->setDrawMode(osgText::Text::TEXT);
- geode->addDrawable(text.get());
- camera->addChild(geode.get());
- //设置图像
- char UIPictPath[255];
- int StringLen = strlen(ExePath);
- memset(UIPictPath, 0, StringLen+1);//在styncpy之前,进行初始化
- strncpy(UIPictPath, ExePath, StringLen);
- strcat(UIPictPath, " \\UI\\bak.jpg");
- std::cout<<UIPictPath<<std::endl;
- osg::ref_ptr<osg::Image> image = osgDB::readImageFile( UIPictPath );
- ////设置变换矩阵
- //osg::ref_ptr<osg::MatrixTransform> mt_UIBak = new osg::MatrixTransform;
- //mt_UIBak->setMatrix(osg::Matrix::scale(osg::Vec3(1.0,1.0,1.0))*osg::Matrix::translate(osg::Vec3(0,0,0)));
- //mt_UIBak->addChild( createPlane(1.0, 1.0, image.get()) );
- //camera->addChild(mt_UIBak);
- camera->addChild( createPlane(1.0, 1.0, image.get()) );
- return camera.get();
- }
- osg::ref_ptr<osg::Node> createPlane( float length, float width, osg::Image* image )
- {
- // Vertices, normal and texture coordinates of the reference plane
- osg::ref_ptr<osg::Vec3Array> vec = new osg::Vec3Array;
- vec->resize( 4 );
- (*vec)[0] = osg::Vec3f( length, 0, width )*0.5;
- (*vec)[1] = osg::Vec3f( -length, 0, width )*0.5;
- (*vec)[2] = osg::Vec3f( -length, 0,-width )*0.5;
- (*vec)[3] = osg::Vec3f( length, 0,-width )*0.5;
- osg::ref_ptr<osg::Vec3Array> nor = new osg::Vec3Array;
- nor->push_back( osg::Vec3f( 0.0, -1.0, 0.0 ) );
- //此处省略n行代码
- return geode.get();
- }
复制代码 以上代码是帮liushui发的,他说他发不上来 |
|