osg::Texture2D 贴纹理
#ifdef _WIN32
#include <Windows.h>
#endif // _WIN32
#include<iostream> #include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgViewer/CompositeViewer> #include <osgDB/ReadFile> #include <osg/Geode>
#include <osg/Node>
#include <osg/Geometry>
#include <osg/GraphicsContext>
#include <osg/ShapeDrawable>
#include <osg/Material>
#include <osg/Image>
#include <osg/Texture2D>
#include <osg/TexEnv>
#include <osg/TexGen>
#include <osg/NodeVisitor>
#include <osg/MatrixTransform>
#include <osg/PositionAttitudeTransform>
#include <osg/AnimationPath>
#include <osg/Matrixd>
#include <osg/PagedLOD>
#include <osg/Camera>
#include <osgText/Text> #include <osgGA/TrackballManipulator>
#include <osgGA/GUIEventHandler>
#include <osgGA/CameraManipulator>
#include <osgGA/StandardManipulator>
#include <osgGA/OrbitManipulator>
#include <osgGA/TrackballManipulator> #include <osgUtil/IntersectionVisitor>
#include <osgUtil/LineSegmentIntersector> osg::Camera* createTextHUD()
{
osg::ref_ptr<osg::Geode> geode1 = new osg::Geode;
osg::ref_ptr<osgText::Text> text1 = new osgText::Text;
osg::ref_ptr<osg::Camera> camera1 = new osg::Camera; osg::ref_ptr<osg::Geometry> geometry1 = new osg::Geometry; camera1->setViewMatrix(osg::Matrix::identity());
camera1->setRenderOrder(osg::Camera::POST_RENDER);
camera1->setClearMask(GL_DEPTH_BUFFER_BIT); camera1->setAllowEventFocus(false);
camera1->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
camera1->setProjectionMatrixAsOrtho2D(-, , -, ); text1->setFont("Fonts/simhei.ttf");
text1->setCharacterSize();
text1->setText(L"OSG 中文字体");
text1->setPosition(osg::Vec3(0.0,0.0,0.0)); //压入顶点
osg::Vec3Array *vecArray = new osg::Vec3Array;
vecArray->push_back(osg::Vec3(0.0,0.0,0.0));
vecArray->push_back(osg::Vec3(200.0, 0.0, 0.0));
vecArray->push_back(osg::Vec3(200.0, 100.0, 0.0));
vecArray->push_back(osg::Vec3(0.0, 100.0, 0.0));
geometry1->setVertexArray(vecArray); //法线
osg::Vec3Array *vecNorm = new osg::Vec3Array;
vecNorm->push_back(osg::Vec3(0.0,0.0,1.0));
geometry1->setNormalArray(vecNorm);
geometry1->setNormalBinding(osg::Geometry::BIND_OVERALL); //设置纹理
osg::Vec2Array *vec2Coord = new osg::Vec2Array;
vec2Coord->push_back(osg::Vec2(0.0,0.0));
vec2Coord->push_back(osg::Vec2(1.0, 0.0));
vec2Coord->push_back(osg::Vec2(1.0, 1.0));
vec2Coord->push_back(osg::Vec2(0.0, 1.0));
geometry1->setTexCoordArray(,vec2Coord); osg::DrawArrays *drawArrays1 = new osg::DrawArrays(osg::PrimitiveSet::QUADS, , );
//geometry1->setPrimitiveSet(0,drawArrays1);
geometry1->addPrimitiveSet(drawArrays1); //贴纹理
osg::ref_ptr<osg::Image> image1 = osgDB::readImageFile("D:\\image_1\\20190325092002-save.jpg");
osg::Texture2D *texture2d1 = new osg::Texture2D;
texture2d1->setImage(image1);
geometry1->getOrCreateStateSet()->setTextureAttributeAndModes(, texture2d1, osg::StateAttribute::ON);
//关闭灯光
geometry1->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); geode1->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
geode1->addDrawable(geometry1);
geode1->addDrawable(text1); camera1->addChild(geode1.get());
return camera1.release();
} int main()
{
osg::ref_ptr<osgViewer::Viewer> viewer1 = new osgViewer::Viewer;
osg::ref_ptr<osg::Group> group1 = new osg::Group; //osg::ref_ptr<osg::Node> node1 = osgDB::readNodeFile("D:\\参考手册\\BIM\\osg\\build20190628.osgb");
osg::ref_ptr<osg::Node> node2 = osgDB::readNodeFile("D:\\参考手册\\BIM\\osg\\build1.osgb"); group1->addChild(node2.get());
group1->addChild(createTextHUD()); viewer1->setSceneData(group1.get());
viewer1->setUpViewInWindow(,,,,); viewer1->run();
}


osg::Texture2D 贴纹理的更多相关文章
- osg gdal加载tif数据文件
osg加载.tif地形数据文件 #ifdef _WIN32 #include <Windows.h> #endif // _WIN32 #include <iostream> ...
- osg模型部分节点旋转
osg::ref_ptr<osg::Geode> CreateBox() { osg::ref_ptr<osg::Geode> geode = new osg::Geode; ...
- osg添加纹理示例
转自http://www.cnblogs.com/ylwn817/articles/1976851.html #include <osgDB/ReadFile>#include <o ...
- osg使用shader动态修改纹理坐标
#include <osg/Node> #include <osg/Geometry> #include <osg/Notify> #include <osg ...
- OSG学习:计算纹理坐标
在很多时候,直接指定纹理坐标是非常不方便的,如曲面纹理坐标,只有少数的曲面(如圆锥.圆柱等)可以在不产生扭曲的情况下映射到平面上,其他的曲面在映射到表面时都会产生一定程度的扭曲.一般而言,曲面表面的曲 ...
- OSG绘制金字塔geode+动态纹理坐标
osg::Node* createPyramidModel() { // create the root node which will hold the model. osg::Group* roo ...
- 基于osg的python三维程序开发(三)------几何形体及纹理
def createScene(): geode = osg.Geode() pointsGeom = osg.Geometry() vertices = osg.Vec3Array() vertic ...
- osg纯手工画球+贴纹理
手动计算球面顶点的坐标,纹理坐标,来画球并贴纹理 其中createSphereGeom()函数的的二个参数为18,意思是在经纬度上每10度设一个点,因为经度一共是180度,180/18=10,相当于横 ...
- OSG快速生成一个带有纹理的四边形Geometry
可以使用Geometry头文件中的 Geometry* createTexturedQuadGeometry osg::ref_ptr<osg::Texture2D> texture = ...
随机推荐
- sqlalchemy.exc.CompileError: (in table 'user', column 'username'): VARCHAR requires a length on dialect mysql
映射数据库时报错:sqlalchemy.exc.CompileError: (in table 'user', column 'username'): VARCHAR requires a lengt ...
- 基于Java8的日期时间工具类DateTimeFormatter
原文:https://blog.csdn.net/qq_36596145/article/details/85331002 import java.time.Instant; import java. ...
- 如何使用Feign构造多参数的请求
原文:http://www.itmuch.com/spring-cloud-sum/feign-multiple-params/ 本节来探讨如何使用Feign构造多参数的请求.笔者以GET及POST请 ...
- webpack多页面打包配置
单页面应用:整个应用里面只有一个html文件.现在主流的框架,vue,react都是单页面应用. 所以webpack绝大部分都是对单页面打包.那么webpack如何对多页面进行打包 index.htm ...
- 使用LPCXpresso开发板调试外部的电路板
MCUXpresso IDE开发环境有一个主要的功能:支持LPC-Link2仿真调试器.通过这种方式,对于基于ARM的电路板,我可以使用这个功能强大的仿真调试器来调试.在NXP的众多LPCXpress ...
- Codeforces Round 585
Codeforces Round 585 浅论如何发现自己是傻子的-- 反正今天是完全蒙的,水了签到题就跑了-- A. Yellow Cards 签到题. 众所周知,CF的签到题一般是一道神神奇奇的数 ...
- Codeforces Round 582
Codeforces Round 582 这次比赛看着是Div.3就打了,没想到还是被虐了,并再次orz各位AK的大神-- A. Chips Moving 签到题.(然而签到题我还调了20min--) ...
- G1混合式GC与三色标记算法详解【纯理论】
继续基于上一次https://www.cnblogs.com/webor2006/p/11146273.html的理论进一步了解G1. G1收集概览: G1算法将堆划分为若干个区域(Region),它 ...
- JAVA API连接HDFS HA集群
使用JAVA API连接HDFS时我们需要使用NameNode的地址,开启HA后,两个NameNode可能会主备切换,如果连接的那台主机NameNode挂掉了,连接就会失败. HDFS提供了names ...
- man与info
Linux系统中在线求助命令:man page 与info page 还有--help . --help没有man的详细,首先我们来看mna 命令.在linux中输入 man + 相关的文件 ,就可以 ...