Re: [osg-users] how to use several texture one time?

2012-11-13 Thread Robert Osfield
H Shawl,

The OSG supports multi-texturing, simply assign each texture to its own
texture unit.  See the osgmultitexture example and osggeometry examples to
see how to assign multiple textures and set up text coords.

Robert.


On 13 November 2012 07:38, wh_xiexing  wrote:

> **
>
> i have a mesh and want to project several photo on the mesh .   code is
> here:
>
>  osg::Switch *layer = new osg::Switch;
> osg::Geode* leaf = 0;
> if (!hasTexture){
> leaf = createLeaf(points, numOfVert, tris,header.np);
> layer->addChild(leaf);
> }else{
> osg::Group *group = new osg::Group;
> for (unsigned int gr = 0; gr < header.ngr; gr++){
> /*for every group , load the different texture*/
> osg::Texture2D* texture = 0L;
> osg::ref_ptr image;
> if(osgDB::isAbsolutePath(groups[gr].texmap)){
> image = osgDB::readImageFile(std::string(groups[gr].texmap));
> }else{
> std::string absoluteFile = osgDB::getFilePath(fileName)
> + std::string("/")
> + std::string(groups[gr].texmap);
> image = osgDB::readImageFile(absoluteFile);
> }
> texture = new osg::Texture2D;
> texture->setImage( image.get() );
> if (texture->getImage()!=0L){
> group->getOrCreateStateSet()->setTextureAttributeAndModes(gr,texture );
> //set texture units
>
> group->getOrCreateStateSet()->setTextureAttribute(gr, new 
> osg::TexEnv(osg::TexEnv::DECAL));
> }
> /*create group leaf*/
>
> leaf = createLeaf(points, tris_t, groups[gr].poly_begin, groups[gr].poly_end, 
> gr);
> group->addChild(leaf);
> }
> layer->addChild(group);
> }
>
> the problem is that just one texture unit works .
> in case :
>  for (unsigned int gr = 0; gr < header.ngr; gr++){  unit 0
> works
>  for (unsigned int gr = 1; gr < 2; gr++){
> unit 1 works
>
>
> then , how can i show the whole mesh with texture?
>
>
> thanks in advance
> --
> Shawl
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] how to use several texture one time?

2012-11-12 Thread wh_xiexing

i have a mesh and want to project several photo on the mesh .   code is here:

osg::Switch *layer = new osg::Switch;
osg::Geode* leaf = 0;
if (!hasTexture){
leaf = createLeaf(points, numOfVert, tris,header.np);
layer->addChild(leaf); 
}else{ 
osg::Group *group = new osg::Group; 
for (unsigned int gr = 0; gr < header.ngr; gr++){ 
/*for every group , load the different texture*/
osg::Texture2D* texture = 0L;
osg::ref_ptr image;
if(osgDB::isAbsolutePath(groups[gr].texmap)){
image = osgDB::readImageFile(std::string(groups[gr].texmap));
}else{
std::string absoluteFile = osgDB::getFilePath(fileName) 
+ std::string("/") 
+ std::string(groups[gr].texmap);
image = osgDB::readImageFile(absoluteFile);
} 
texture = new osg::Texture2D;
texture->setImage( image.get() );
if (texture->getImage()!=0L){
group->getOrCreateStateSet()->setTextureAttributeAndModes(gr,texture );
//set texture units
group->getOrCreateStateSet()->setTextureAttribute(gr, new 
osg::TexEnv(osg::TexEnv::DECAL));
} 
/*create group leaf*/
leaf = createLeaf(points, tris_t, groups[gr].poly_begin, groups[gr].poly_end, 
gr);
group->addChild(leaf);
}
layer->addChild(group); 
}

the problem is that just one texture unit works .   
in case :
 for (unsigned int gr = 0; gr < header.ngr; gr++){  unit 0 works 
 for (unsigned int gr = 1; gr < 2; gr++){   unit 1 
works


then , how can i show the whole mesh with texture?


thanks in advance



Shawl___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org