转自http://www.cnblogs.com/ylwn817/articles/1976851.html

#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osg/Node>
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/Group>
#include <osg/Texture2D>
#include <osg/TexGen>
#include <osg/TexEnv>

void main()
{
    osgViewer::Viewer viewer;
    osg::ref_ptr<osg::Group> root=new osg::Group();
    osg::ref_ptr<osg::Node>  node=osgDB::readNodeFile("cow.osg");

osg::ref_ptr<osg::Image> image=osgDB::readImageFile("Images\\Primitives.gif");

if (image.get())
    {
        osg::ref_ptr<osg::Texture2D> texture=new osg::Texture2D();
        texture->setImage(image.get());

//设置自动生成纹理坐标
        osg::ref_ptr<osg::TexGen> texgen=new osg::TexGen();
        texgen->setMode(osg::TexGen::SPHERE_MAP);

//设置纹理环境,模式为BLEND
        osg::ref_ptr<osg::TexEnv> texenv=new osg::TexEnv;
        texenv->setMode(osg::TexEnv::Mode::ADD);
        texenv->setColor(osg::Vec4(0.6,0.6,0.6,0.0));

//启动单元一自动生成纹理坐标,并使用纹理
        osg::ref_ptr<osg::StateSet> state=new osg::StateSet;
        state->setTextureAttributeAndModes(1,texture.get(),osg::StateAttribute::ON);
        state->setTextureAttributeAndModes(1,texgen.get(),osg::StateAttribute::ON);
        state->setTextureAttribute(1,texenv.get());

node->setStateSet(state.get());

}
    root->addChild(node.get());
    viewer.setSceneData(root.get());
    viewer.realize();
    viewer.run();
}

osg添加纹理示例的更多相关文章

  1. OSG中的示例程序简介

    OSG中的示例程序简介 转自:http://www.cnblogs.com/indif/archive/2011/05/13/2045136.html 1.example_osganimate一)演示 ...

  2. OSG中的示例程序简介(转)

    OSG中的示例程序简介 1.example_osganimate一)演示了路径动画的使用 (AnimationPath.AnimationPathCallback),路径动画回调可以作用在Camera ...

  3. Oracle 添加 scott 示例用户

    学习SQL有一段时间了,但是也忘记的差不多了,今天有赶紧复习复习,然后发现一个问题,为啥之前看的视频教程,马士兵用的Oracle有scott用户和那些表格,而我的没有?难道是Oracle取消了?然后百 ...

  4. cocos2d-x 添加纹理自动回收机制

    转自:http://www.cnblogs.com/lancidie/archive/2013/04/13/3019375.html 1.不是一个完整的模块,所以不提供完整代码,只提供思路和核心代码. ...

  5. osg蝴蝶纹理

    #include <osgViewer/Viewer> #include <osgDB/WriteFile> #include <osg/StateSet> #in ...

  6. cocos2dx JS 图片精灵添加纹理缓存

    添加精灵图片缓存 : cc.spriteFrameCache.addSpriteFrames("res/pic.plist"); 从缓存中获取 : var frame = cc.s ...

  7. pc端 添加购物车示例

    添加到购物车列表及相关商品推荐. <!DOCTYPE html> <html lang="en"> <head> <meta charse ...

  8. OSG添加回调更新

    class CB : public osg::NodeCallback { virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) ...

  9. Linux系统调用接口添加简单示例

    1. Linux体系结构 Linux系统的地址空间分为用户空间和内核空间,通过系统调用和硬件中断能够完成从用户空间到内核空间的转移. 2. 系统调用接口 ① 一般情况下,用户进程不能访问内核空间.Li ...

随机推荐

  1. Css3动态伪类

    通常我们可以用CSS中伪类和js中的鼠标事件来定义. 动态伪类 起作用的元素 描述 :link 只有链接 未访问的链接 :visited 只有链接 访问过的链接 :hover 所有元素 鼠标经过元素 ...

  2. HTTPS 服务器搭建

    利用NGINX搭建HTTPS服务器不是一件困难的事情,过程包括以下几步 第一步:利用OpenSSL制作证书 第二步:安装NGINX,configure中保证加入ngx_http_ssl_module. ...

  3. github 提交时候提示 org.eclipse.jgit.errors.ObjectWritingException: Unable to create new object: /usr/local/apache243/ht

    只需要执行 chmod -R 777 ./*  把 .git文件权限设置为 777便可以实现.

  4. HBase笔记--filter的使用

    HBASE过滤器介绍: 所有的过滤器都在服务端生效,叫做谓语下推(predicate push down),这样可以保证被过滤掉的数据不会被传送到客户端. 注意:        基于字符串的比较器,如 ...

  5. MSP430 中断优先级

    MSP430的中断优先级.打开关闭.中断嵌套 优先级顺序从高到低为:    PORT2_VECTOR (1 * 2u) /* 0xFFE2 Port 2 */    PORT1_VECTOR (4 * ...

  6. Dijkstra优先队列优化

    Dijkstra算法的核心思想就是两步排序,一个是对于一个点而言,他的最小边要经过所有其他点最小边的测试才能确认,也就是说要在这其中找一个最大的边出来:第二个是对于每次循环而言的,每次的更新d数组都是 ...

  7. Hp vPv

  8. 听说每天都要写随笔,word哥~

    今天主要学习了html的基本知识,进制的转换,无序列表,有序列表和表格,都是很基本的东西,然后自己自习了表单. <!DOCTYPE html PUBLIC "-//W3C//DTD X ...

  9. CentOS 6.3下Samba服务器的安装与配置(转)

    CentOS 6.3下Samba服务器的安装与配置   一.简介 Samba是一个能让Linux系统应用Microsoft网络通讯协议的软件,而SMB是Server Message Block的缩写, ...

  10. Highcharts 异步加载数据曲线图表

    导入 data.js 文件 异步加载数据需要引入以下js 文件: <script src="http://code.highcharts.com/modules/data.js&quo ...