使用Openscenegraph加载纹理时出错

时间:2014-02-12 14:54:37

标签: c++ openscenegraph

我正在尝试使用openscenegraph制作动画,但我无法使用此代码加载纹理:

osg::ref_ptr<osg::Node> createSceneGraph(){
    osg::ref_ptr<osg::Group> root = new osg::Group;
    osg::ref_ptr<osg::MatrixTransform> m1 = new osg::MatrixTransform();
    root->addChild(m1.get());

    // creer sphere
    osg::ref_ptr<osg::Geode> terre = new osg::Geode();
    terre->addDrawable( new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0, 0, 4), 2)));
    m1->addChild(terre);

    // ajouter texture
    osg::Image* im = new osgDB::readImageFile("land_shallow_topo_2048.jpg");
    osg::Texture2D* tex = new osg::setImage(im);

    return root;
}

int main( )
{
    osg::ref_ptr<osg::Node> root = createSceneGraph();
    osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;
    viewer->setUpViewInWindow( 32, 32, 1024, 768 );
    viewer->setSceneData(root.get());
    osg::ref_ptr<osg::Camera> camera = new osg::Camera;
    camera->setProjectionMatrix(osg::Matrix::perspective(60.0,1.333,0.01,100000.0));
    camera->setViewMatrix( osg::Matrix::identity() );
    viewer->setCamera(camera);
    return viewer->run();

}

这是错误:

 /home/yoyo/TP_avion_yoyo/main.cpp:39: erreur : cannot convert 'int*' to 'osg::Image*' in initialization

图像被正确放置在我的目录中,我不知道为什么它不起作用,因为我编译了另一个利用纹理的项目。

1 个答案:

答案 0 :(得分:2)

ReadImageFile方法返回指向图像的指针。因此,您可以直接将返回的指针指定给变量:im

osg::Image* im = osgDB::readImageFile("land_shallow_topo_2048.jpg");