zoukankan      html  css  js  c++  java
  • 在osg的图形上贴一张纹理图片

    哈哈哈,继今天早上完成的成果,又接着进行了修改完善。

    先上图:

    (在球上贴路费的照片都贴胖了...)

    接着贴代码了

    继续上篇的代码中填上一个createTexture2DState函数:

     1 osg::ref_ptr<osg::StateSet> createTexture2DState(osg::ref_ptr<osg::Image>image)
     2 {
     3     //创建状态集对象
     4     osg::ref_ptr<osg::StateSet>stateset = new osg::StateSet();
     5     //创建二维纹理对象
     6     osg::ref_ptr<osg::Texture2D>texture = new osg::Texture2D();
     7     texture->setDataVariance(osg::Object::DYNAMIC);
     8     //设置贴图
     9     texture->setImage(image.get());
    10     texture->setFilter(osg:: Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR);
    11     texture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
    12     texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
    13     texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
    14 
    15     stateset->setTextureAttributeAndModes(0, texture.get(), osg::StateAttribute::ON);
    16     return stateset.get();
    17 }

    main函数是这样的:

     1 int main(int argc, char **argv)
     2 {
     3     QApplication app(argc, argv);
     4     osg::Camera* camera = createCamera(50, 50, 640, 480);
     5     osg::ref_ptr<osg::Image>image = osgDB::readImageFile("Images/timg.jpg");
     6     osg::ref_ptr<osg::StateSet>stateset = new osg::StateSet();
     7     stateset = createTexture2DState(image.get());
     8     osg::Group * scene = new osg::Group();
     9     scene->setStateSet(stateset.get());
    10     scene->addChild(createShape().get());
    11     ViewerWidget* widget = new ViewerWidget(camera, scene);
    12     widget->setGeometry(100, 100, 800, 600);
    13     widget->show();
    14     return app.exec();
    15 }

    剩下的不用改就ok啦!

    附:关于图片的路径我的路径是(D:osg3.4.0dataImages);

    按照自己的data文件夹设置就可以啦!

  • 相关阅读:
    D. The Fair Nut and the Best Path 树形dp (终于会了)
    (二)网络流之最大流
    网络流(知识点) 一 终究还是躲不掉
    dp 优化 F2. Pictures with Kittens (hard version)
    da shu mo ban
    AtCoder Regular Contest 090 F
    Codeforces 918D MADMAX 图上dp 组合游戏
    Codeforces 918C The Monster
    AtCoder Regular Contest 090 C D E F
    poj 3623 Best Cow Line, Gold 后缀数组 + 贪心
  • 原文地址:https://www.cnblogs.com/masking-timeflows/p/8534021.html
Copyright © 2011-2022 走看看