#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 贴纹理的更多相关文章

  1. osg gdal加载tif数据文件

    osg加载.tif地形数据文件 #ifdef _WIN32 #include <Windows.h> #endif // _WIN32 #include <iostream> ...

  2. osg模型部分节点旋转

    osg::ref_ptr<osg::Geode> CreateBox() { osg::ref_ptr<osg::Geode> geode = new osg::Geode; ...

  3. osg添加纹理示例

    转自http://www.cnblogs.com/ylwn817/articles/1976851.html #include <osgDB/ReadFile>#include <o ...

  4. osg使用shader动态修改纹理坐标

    #include <osg/Node> #include <osg/Geometry> #include <osg/Notify> #include <osg ...

  5. OSG学习:计算纹理坐标

    在很多时候,直接指定纹理坐标是非常不方便的,如曲面纹理坐标,只有少数的曲面(如圆锥.圆柱等)可以在不产生扭曲的情况下映射到平面上,其他的曲面在映射到表面时都会产生一定程度的扭曲.一般而言,曲面表面的曲 ...

  6. OSG绘制金字塔geode+动态纹理坐标

    osg::Node* createPyramidModel() { // create the root node which will hold the model. osg::Group* roo ...

  7. 基于osg的python三维程序开发(三)------几何形体及纹理

    def createScene(): geode = osg.Geode() pointsGeom = osg.Geometry() vertices = osg.Vec3Array() vertic ...

  8. osg纯手工画球+贴纹理

    手动计算球面顶点的坐标,纹理坐标,来画球并贴纹理 其中createSphereGeom()函数的的二个参数为18,意思是在经纬度上每10度设一个点,因为经度一共是180度,180/18=10,相当于横 ...

  9. OSG快速生成一个带有纹理的四边形Geometry

    可以使用Geometry头文件中的 Geometry* createTexturedQuadGeometry osg::ref_ptr<osg::Texture2D> texture = ...

随机推荐

  1. CentOS7下Yum安装Redis并配置主从

    原文 :https://blog.51cto.com/11134648/2158209 Redis简介: Redis 是完全开源免费的,遵守BSD协议,是一个高性能的key-value数据库.它通常被 ...

  2. unittest(二)框架中的概念与断言

    test case一个 TestCase 的实例就是一个测试用例.什么是测试用例呢?就是一个完整的测试流程,包括测试前准备环境的搭建(setUp),实现测试过程的代码(run),以及测试后环境的还原( ...

  3. Robot Framework--接口测试环境搭建

    1.安装requests库 (robotframework-requests依赖这个request http client) 执行pip install requests 2. 安装requestLi ...

  4. DTcmsV4.0分析学习——(2)系统框架

    2.1物理结构 共8个项目,Web为启动项 项目间相互依赖关系图: 2.2逻辑结构 DTcms V4.0轻量级CMS系统框架采用的是典型的三层架构(项目与三层架构并非直接对应关系,至于什么是三层架构这 ...

  5. Maven dependencies說明

    一.今天搭建了一个maven项目,在pom.xml文件引入依赖后,发现项目结构中没有Maven Dependencies文件(下图),但是在java Build Path中又可以找到Maven Dep ...

  6. java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Workbook] with root cause

    一.问题描述 使用POI上传excel,本地可正常运行,开发服务器上报错. 二.异常信息如下: 2019-05-05 17:00:22,349 ERROR [http-nio-8080-exec-7] ...

  7. PHP 根据域名和IP返回不同的内容

    遇到一个好玩的事情,访问别人的IP和别人的域名返回的内容竟然不一样.突然觉得很好玩,也很好奇.自己研究了一下下,就简单写一下吧~ 一个IP和一个域名, 先讲一下公网IP没有绑定域名,但是可以通过一个没 ...

  8. Codeforces Round #438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined) A,B,C【真的菜·】

    8说了 #include<bits/stdc++.h> using namespace std; #define int long long signed main(){ string s ...

  9. SpringMVC使用ResponseEntity实现文件下载,及图片base64的字节数组上传于下载

    本文主要通过ResponseEntity<byte[]>实现文件下 该类实现响应头.文件数据(以字节存储).状态封装在一起交给浏览器处理以实现浏览器的文件下载. ResponseEntit ...

  10. 洛谷 P2615 神奇的幻方 题解

    每日一题系列day1 打卡 Analysis 水货模拟,不多说了 #include<iostream> #include<cstdio> #include<cstring ...