查看: 938|回复: 2

RTT学习遇到的问题?

[复制链接]

该用户从未签到

发表于 2013-8-25 00:07:28 | 显示全部楼层 |阅读模式

这是什么问题照着视频讲解的一样代码结果偏差太大

这是什么问题照着视频讲解的一样代码结果偏差太大

请问这是环境配置的有恩题吗,运行源代码如下:#include"../Common/Common.h"
#include<osgViewer\Viewer>
#include<osgDB\ReadFile>
#include<osgDB\Registry>       
#include<osg\Geode>
#include<osg\Geometry>
#include<osg\Camera>
#include<osg\Texture2D>
#include<iostream>
#include<osg\Image>


void CreateTexture(osgViewer::Viewer *viewer)
{
        if(!viewer)
        {
                std::cout <<"Viewer is NULL"<<std::endl;
                return ;
        }
        //
        /*osg::GraphicsContext ::WindowingSystemInterface *wsi=osg::GraphicsContext ::getWindowingSystemInterface ();
        if(!wsi)
        {
                std::cout <<"windowing error"<<std::endl;
                return ;
        }
        unsigned int width,height;
        wsi->getScreenResolution (osg::GraphicsContext ::ScreenIdentifier (0),width,height);*/
        osg::ref_ptr<osg::GraphicsContext::Traits>traits=new osg::GraphicsContext ::Traits ;
        traits->x=0;
        traits->y=0;
        traits->width=800;
        traits->height =600;
        traits->windowDecoration=false;
        traits->doubleBuffer =true;
        traits->sharedContext =0;

        osg::ref_ptr<osg::GraphicsContext >gc=osg::GraphicsContext ::createGraphicsContext (traits);
        if(!gc.valid())
        {
                std::cout<<"error"<<std::endl;
                return ;


        }
        osg::ref_ptr<osg::Camera>master=new osg::Camera;
        master->setGraphicsContext (gc);
        master->setViewport (0,0,800,600);
        viewer->addSlave(master.get());

        osg::ref_ptr <osg::Camera>rttCamera=new osg::Camera;
        rttCamera->setRenderOrder (osg::Camera :RE_RENDER);
        rttCamera->setGraphicsContext (gc);
        rttCamera->setViewport (0,0,800,600);
        rttCamera->addChild (osgDB::readNodeFile ("ceep.ive"));
        viewer->addSlave (rttCamera,false);



        osg::ref_ptr<osg::Group>gp=new osg::Group;
        osg::ref_ptr <osg::Geode>gnode=new osg::Geode;
        gp->addChild (gnode);

        osg::ref_ptr<osg::Geometry >gm=new osg::Geometry ;
        gnode->addDrawable (gm);//加入几何体


        //压入顶点
        osg::ref_ptr<osg::Vec3Array >vertex=new osg::Vec3Array ;
        vertex->push_back (osg::Vec3(-400,100,-300));
        vertex->push_back (osg::Vec3(400,100,-300));
        vertex->push_back (osg::Vec3(400,100,300));
        vertex->push_back (osg::Vec3(-400,100,300));
        gm->setVertexArray (vertex);

        //压入法线
        osg::ref_ptr<osg::Vec3Array >norm1=new osg::Vec3Array ;
        norm1->push_back (osg::Vec3(0,-1.0,0));
        gm->setNormalArray (norm1);
        gm->setNormalBinding (osg::Geometry ::BIND_OVERALL );//设置法线的绑定方式

        //纹理坐标
        osg::ref_ptr<osg::Vec2Array >coord=new osg::Vec2Array ;
        coord->push_back (osg::Vec2(0.0,0.0));
        coord->push_back (osg::Vec2(1.0,0.0));
        coord->push_back (osg::Vec2(1.0,1.0));
        coord->push_back (osg::Vec2(0.0,1.0));
        gm->setTexCoordArray (0,coord);
        gm->addPrimitiveSet (new osg:rawArrays (osg::PrimitiveSet :UADS,0,4));
        gm->getOrCreateStateSet ()->setMode (GL_LIGHTING,osg::StateAttribute ::OFF );//灯光关掉
        //gm->getOrCreateStateSet ()->setMode (GL_BLEND,osg::StateAttribute ::ON );//打开透明
               

        //创建一个2D的纹理
        osg::ref_ptr<osg::Texture2D >t2d=new osg::Texture2D ;
        t2d->setInternalFormat (GL_RGBA);
        //viewer->getCamera ()->attach (osg::Camera::COLOR_BUFFER,t2d);
        rttCamera->attach (osg::Camera::COLOR_BUFFER ,t2d);
        //读取纹理
        /*osg::ref_ptr<osg::Image>image=osgDB::readImageFile ("Images/lz.rgb");
        if(!image)
        {
                std::cout <<"Could not read this image"<<std::endl;
                return ;
        }
        t2d->setImage (0,image);*/
        gm->getOrCreateStateSet ()->setTextureAttributeAndModes (0,t2d,osg::StateAttribute ::ON);
        gp->addChild (osgDB::readNodeFile ("ceep.ive"));
        viewer->setSceneData (gp);
        return ;
       

}

int main()
{
        osg::ref_ptr<osgViewer::Viewer>viewer=new osgViewer::Viewer;
       
       
        CreateTexture(viewer);
        viewer->run();
        return viewer->run();
}

该用户从未签到

 楼主| 发表于 2013-8-25 22:40:05 | 显示全部楼层
怎么没人解答呢

该用户从未签到

发表于 2013-8-28 09:30:29 | 显示全部楼层
请不要使用Slave Camera来做RTT
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表