Hi all,

here I am again. Now I've got another problem when I try to assaign two
textures to my geometry.

Here the results from my code:

   

the first picture shows the geometry with only 1 texture and blending
disabled; the second with blending, the third two textures with
blending.

Whats wrong with my code?

void MTField::create_plate( osg::Geode* plateGeode, int scale)
{
  osg::Geometry* plateGeometry = new osg::Geometry();
  plateGeode->addDrawable(plateGeometry);
  osg::Vec3Array* plateVertices = new osg::Vec3Array;
        for (unsigned int x=0; x<m_x;x++)
                for (unsigned int y=0; y<m_y;y++)
                        plateVertices->push_back( osg::Vec3(x*scale,y*scale,0));

  plateGeometry->setVertexArray( plateVertices );

  osg::DrawElementsUInt* plateBase =  new
osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, 0);
  
  for (int x=0; x<m_x-1;x++)
        for (int y=0; y<m_y-1;y++)
            {
                plateBase->push_back((y+1)*m_x+x);    
plateBase->push_back((y+1)*m_x+x
+1);    plateBase->push_back(y*m_x+x+1);    plateBase->push_back(y*m_x
+x);
            }

   plateGeometry->addPrimitiveSet(plateBase);

   osg::Vec2Array* texcoords = new osg::Vec2Array(16);
   (*texcoords)[0].set(0.0f,0.0f);
   (*texcoords)[1].set(0.0f,1.0f);
   (*texcoords)[2].set(0.0f,0.0f);
   (*texcoords)[3].set(0.0f,1.0f);
   (*texcoords)[4].set(1.0f,0.0f);
   (*texcoords)[5].set(1.0f,1.0f);
   (*texcoords)[6].set(1.0f,0.0f);
   (*texcoords)[7].set(1.0f,1.0f);
   (*texcoords)[8].set(1.5f,1.5f);
   (*texcoords)[9].set(1.5f,1.5f);
   (*texcoords)[10].set(1.5f,1.5f);
   (*texcoords)[11].set(1.5f,1.5f);
   (*texcoords)[12].set(1.5f,1.5f);
   (*texcoords)[13].set(1.5f,1.5f);
   (*texcoords)[14].set(1.5f,1.5f);
   (*texcoords)[15].set(1.5f,1.5f);

  osg::Vec2Array* texcoords2 = new osg::Vec2Array(16);
   (*texcoords2)[0].set(1.5f,1.5f);
   (*texcoords2)[1].set(1.5f,1.5f);
   (*texcoords2)[2].set(1.5f,1.5f);
   (*texcoords2)[3].set(1.5f,1.5f);
   (*texcoords2)[4].set(1.5f,1.5f);
   (*texcoords2)[5].set(1.5f,1.5f);
   (*texcoords2)[6].set(1.5f,1.5f);
   (*texcoords2)[7].set(1.5f,1.5f);
   (*texcoords2)[8].set(0.0f,0.0f);
   (*texcoords2)[9].set(0.0f,1.0f);
   (*texcoords2)[10].set(0.0f,0.0f);
   (*texcoords2)[11].set(0.0f,1.0f);
   (*texcoords2)[12].set(1.0f,0.0f);
   (*texcoords2)[13].set(1.0f,1.0f);
   (*texcoords2)[14].set(1.0f,0.0f);
   (*texcoords2)[15].set(1.0f,1.0f);
   

   plateGeometry->setTexCoordArray(0,texcoords);
   plateGeometry->setTexCoordArray(1,texcoords2);

   osg::Texture2D* KLN89FaceTexture = new osg::Texture2D;
   KLN89FaceTexture->setDataVariance(osg::Object::DYNAMIC);
   osg::Image* klnFace = osgDB::readImageFile("texture1.png");
   if (!klnFace)
   {
     std::cout << " couldn't find texture, quiting." << std::endl;
   }

   osg::Texture2D* KLN89FaceTexture2 = new osg::Texture2D;
   KLN89FaceTexture2->setDataVariance(osg::Object::DYNAMIC);
   osg::Image* klnFace2 = osgDB::readImageFile("texture2.png");
   if (!klnFace2)
    {
      std::cout << " couldn't find texture, quiting." << std::endl;
    }
        KLN89FaceTexture->setImage(klnFace);
        KLN89FaceTexture2->setImage(klnFace2);

KLN89FaceTexture->setWrap(osg::Texture2D::WRAP_S,osg::Texture2D::CLAMP_TO_BORDER);

KLN89FaceTexture->setWrap(osg::Texture2D::WRAP_T,osg::Texture2D::CLAMP_TO_BORDER);

KLN89FaceTexture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);

KLN89FaceTexture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);

KLN89FaceTexture2->setWrap(osg::Texture2D::WRAP_S,osg::Texture2D::CLAMP_TO_BORDER);

KLN89FaceTexture2->setWrap(osg::Texture2D::WRAP_T,osg::Texture2D::CLAMP_TO_BORDER);

KLN89FaceTexture2->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR);

KLN89FaceTexture2->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
        osg::TexEnv* texenv = new osg::TexEnv;
        texenv->setMode(osg::TexEnv::BLEND);

   osg::StateSet* stateOne = new osg::StateSet();
   stateOne->setTextureAttributeAndModes
(0,KLN89FaceTexture,osg::StateAttribute::ON);
   stateOne->setTextureAttributeAndModes
(0,texenv,osg::StateAttribute::ON);
   stateOne->setTextureAttributeAndModes
(1,KLN89FaceTexture2,osg::StateAttribute::ON);
   stateOne->setTextureAttributeAndModes
(1,texenv,osg::StateAttribute::ON);
   plateGeometry->setStateSet(stateOne);
   
}


Thanks for your help.


Michael 





Am Dienstag, den 13.02.2007, 22:02 +0100 schrieb Rafa Gaitan:

> Hi Michael, 
> 
> Maybe there is not a perfect solution for your request, but if I
> understand your problem, 
> you can also use an osg::TexMat, to transform each texture stage.. so
> you can assign 
> same texture coords to your geometry (or use osg::TexGen), and apply a
> texture matrix 
> to fit the textures.. Of course you also need to play with TexEnv with
> BLEND, 
> or TexEnvCombine for more complex interpolation as Paul says.
> 
> Rafa.
> 


Attachment: 2textures_and_blend.png
Description: PNG image

Attachment: 1texture_blend.png
Description: PNG image

Attachment: 1texture_wo_blend.png
Description: PNG image

_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to