[osg-users] Using multiples texture for a geometry

Florian GOLESTIN florian.golestin at gmail.com
Sun May 1 22:13:11 PDT 2016


Hi everyone,

I've a Geometry (which is a wall) and I want to put two textures on it. A part with a first texture and a second part with a  second texture. 

I wrote the code above :

Code:

    //Texture 1
    geom->setTexCoordArray(0, level->texcoords.get());
    {
      osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
      osg::ref_ptr<osg::Image> image = osgDB::readImageFile("media/textures/stone_3_2048x2048.jpg");
      texture->setImage(image);
      texture->setUnRefImageDataAfterApply(true);
      level->getOrCreateStateSet()->setTextureAttributeAndModes(0, texture);
    }
    //Texture 2
    geom->setTexCoordArray(1, level->texcoords2.get());
    {
      osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
      osg::ref_ptr<osg::Image> image = osgDB::readImageFile("media/textures/Metal_seamless2_ch16.jpg");
      texture->setImage(image);
      texture->setUnRefImageDataAfterApply(true);
      level->getOrCreateStateSet()->setTextureAttributeAndModes(1, texture);
    }




However the wall appears completely black (no textures).

If I comment the "Texture 2" block, the part of the wall with the first texture is displayed correctly. And if I comment the "Texture 1" block the part of the wall with the second texture is displayed correctly.

I am missing something?

Thank you,
Florian

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=67039#67039








More information about the osg-users mailing list