|
本帖最后由 就是那个胖子 于 2013-12-12 13:28 编辑
想在窗口右上角抬头显示图片,借鉴了wontor的帖子:http://bbs.osgchina.org/forum.ph ... amp;extra=#pid60599
代码如下:
osg::ref_ptr<osg::Group> rootNode = new osg::Group();
rootNode = m_pCustomOSGWnd->m_pMapNode;
rootNode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
CRect rect;
GetClientRect(&rect);
//GetWindowRect(&rect);
double x = rect.Width();//宽度
double y = rect.Height();//高度
//创建Hud相机
osg::Camera* hudCamera = new osg::Camera;
hudCamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
hudCamera->setProjectionMatrixAsOrtho2D(0,x,0,y);
hudCamera->setViewMatrix(osg::Matrix::identity());
hudCamera->setRenderOrder(osg::Camera:OST_RENDER);
hudCamera->setClearMask(GL_DEPTH_BUFFER_BIT);
hudCamera-> setAllowEventFocus(false );
osg::Geode* geode = new osg::Geode;
osg::Image* image = osgDB::readImageFile("F:\\DaoHang-png\\move_panel.png");
double m_dWidth = 200;
double m_dHeight = 200;
if (image)
{
osg::Vec3 _origin= osg::Vec3(-1.0f,-1.0f,0.0f);
osg::Vec3 _width;
osg::Vec3 _height;
_width.set(m_dWidth,0.0f,0.0f);
_height.set(0.0f,m_dHeight,0.0f);
osg::Geometry* geometry = osg::createTexturedQuadGeometry(_origin,_width,_height);
osg::StateSet* stateset = geometry->getOrCreateStateSet();
stateset->setTextureAttributeAndModes(0,new osg::Texture2D(image),osg::StateAttribute::ON);
stateset->setMode(GL_BLEND,osg::StateAttribute::OFF);
stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
geode->addDrawable(geometry);
}
osg::PositionAttitudeTransform* transform = new osg::PositionAttitudeTransform;
transform->setPosition(osg::Vec3(x-m_dWidth,y-m_dHeight,0.0));
transform->addChild(geode);
hudCamera->addChild(transform);
rootNode->addChild(hudCamera); |
|