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 = ...
随机推荐
- 如何使用Feign构造多参数的请求
原文:http://www.itmuch.com/spring-cloud-sum/feign-multiple-params/ 本节来探讨如何使用Feign构造多参数的请求.笔者以GET及POST请 ...
- 模仿DotnetCore中间件的方式,做一个列表过滤的功能
我们的很多功能当中都会遇到对版本进行过滤的场合,例如你可能需要对列表中的数据的时间进行过滤.版本过滤.渠道以及地区信息进行过滤. 原本的做法:设计很多个过滤方法,通过枚举的方式组合,选择需要过滤哪些方 ...
- 运输层2——用户数据报协议UDP
目录 1. UDP概述 2. UDP首部格式 3. UDP首部检验和计算方法 写在前面:本文章是针对<计算机网络第七版>的学习笔记 运输层1--运输层协议概述 运输层2--用户数据报协议U ...
- ubuntu安装anaconda3+tensorflow(cpu)+pycharm(windows几乎一样)
网上乱七八糟有的都是别人怎么写自己也怎么写,其实很简单. 首先是anaconda3的安装: 直接上官网:https://www.anaconda.com/download/ 下载下来之后进入文件所在目 ...
- Vue界面中关于APP端回调方法问题
在混合开发中,HTML界面经常性的需要调用APP端提供的原生方法,而且在很多时候,APP端需要各种回调,如果将所有的回调方法写在内部,不是很方便,而且有些时候,APP端需要定义一些主动触发HTML界面 ...
- Java中list在循环中删除元素的坑
JAVA中循环遍历list有三种方式for循环.增强for循环(也就是常说的foreach循环).iterator遍历. 1.for循环遍历list for(int i=0;i<list.siz ...
- 多任务4---greenlet完成多任务
同yield一样 ,单线程,来回切换完成多任务,需要安装greenlet插件 pip install greenlet 代码: from greenlet import greenlet import ...
- [TJOI2015]弦论(第k小子串)
题意: 对于一个给定的长度为n的字符串,求出它的第k小子串. 有参数t,t为0则表示不同位置的相同子串算作一个,t为1则表示不同位置的相同子串算作多个. 题解: 首先,因为t的原因,后缀数组较难实现, ...
- git查看commit提交记录详情
相关的命令: git log:查看所有的commit提交记录: git show: 查看提交的详情: 首先,需要通过git log打印所有commit记录,例如: 1.查看最新的commit:git ...
- 采用非常规方法(非gprecoverseg) 恢复greenplum数据库
greenplum数据库中mirror的作用就是作为primary的备份存在.那么恢复down掉的mirror或primary时,是否可以直接复制文件从primary或mirror到对应的mirror ...