HUD
2021/9/2 23:11:24
本文主要是介绍HUD,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
- 显示文本;
- 显示纹理;
#include <Windows.h> #include <osg/Node> #include <osg/Group> #include <osg/Geode> #include <osg/Camera> #include <osg/Texture2D> #include <osgViewer/Viewer> #include <osgDB/ReadFile> #include <osgText/Text> osg::Camera* createHUDCamera(double left, double right, double bottom, double top) { osg::ref_ptr<osg::Camera> camera = new osg::Camera(); camera->setProjectionMatrix(osg::Matrix::ortho2D(left, right, bottom, top)); camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); camera->setViewMatrix(osg::Matrix::identity()); camera->setClearMask(GL_DEPTH_BUFFER_BIT); camera->setRenderOrder(osg::Camera::POST_RENDER); camera->setAllowEventFocus(false); camera->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); return camera.release(); } osgText::Text* createText(const std::string& str) { osg::ref_ptr<osgText::Text> text = new osgText::Text(); text->getOrCreateStateSet()->setRenderBinDetails(0, "DepthSortedBin"); text->setPosition(osg::Vec3(10.0, 10.0, 0.0)); text->setCharacterSize(32); text->setText(str); return text.release(); } osg::Geode* createTexture(const std::string& path) { osg::ref_ptr<osg::Geode> geode = new osg::Geode(); geode->getOrCreateStateSet()->setRenderBinDetails(1, "DepthSortedBin"); osg::ref_ptr<osg::Geometry> geometry = osg::createTexturedQuadGeometry(osg::Vec3(), osg::Vec3(200.0f, 0.0f, 0.0f), osg::Vec3(0.0f, 200.0f, 0.0f)); osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D(); texture->setImage(osgDB::readImageFile(path)); geometry->getOrCreateStateSet()->setTextureAttributeAndModes(0, texture); geode->addDrawable(geometry); return geode.release(); } int main() { osgViewer::Viewer viewer; osg::ref_ptr<osg::Group> group = new osg::Group(); group->addChild(osgDB::readNodeFile("glider.osg")); osg::ref_ptr<osg::Camera> camera = createHUDCamera(0, 800, 0, 600); camera->addChild(createText("glider")); camera->addChild(createTexture("Images/blueFlowers.png")); group->addChild(camera); viewer.setSceneData(group); viewer.setUpViewInWindow(100, 100, 500, 400); return viewer.run(); }
这篇关于HUD的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23Springboot应用的多环境打包入门
- 2024-11-23Springboot应用的生产发布入门教程
- 2024-11-23Python编程入门指南
- 2024-11-23Java创业入门:从零开始的编程之旅
- 2024-11-23Java创业入门:新手必读的Java编程与创业指南
- 2024-11-23Java对接阿里云智能语音服务入门详解
- 2024-11-23Java对接阿里云智能语音服务入门教程
- 2024-11-23JAVA对接阿里云智能语音服务入门教程
- 2024-11-23Java副业入门:初学者的简单教程
- 2024-11-23JAVA副业入门:初学者的实战指南