Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Working with Multitexturing

The following actions are required for every texture:

1. Create a TextureAttributeItem
2. Bind the item to a specific texture unit
You bind the item via the TextureAttribute object using the bindTextureAttributeItem() method. (A TextureAttribute is a simple StateAttribute such as Material. Refer to the sample viewer sources to see how to set up a simple tree using StateAttributes.)

The following sample code shows how to set up multitexturing:

const TextureAttribute * texAttrib = TextureAttribute::create();
TextureAttribute * ncTexAttrib = beginEdit( texAttrib );
for (size_t i=0; i<numTextures; i++)
{
  const TextureAttributeItem * item = TextureAttributeItem::create();
  TextureAttributeItem * ncItem = beginEdit( item );
  ncItem->setFileName(namelist[i]);
  ncItem->setType(tt);

  // just assume it's a 2D-Texture and rotate around the z-axis
  ncItem->setOrientation(Quatf( Vec3f( 0.0f, 0.0f, 1.0f ), m_IDToTextureRotation[mapID] ));
  ncItem->setScaling(m_IDToTextureScaling[mapID]);
  ncItem->setTranslation(m_IDToTextureTranslation[mapID]);
  endEdit( ncItem );

  // bind the item
  ncTexAttrib->bindTextureAttributeItem(item, i); // put the texture into texture unit i

  // texture environment mode
  ncTexAttrib->setEnvMode(TEM_BLEND);
}
endEdit( ncTexAttrib );

Back to:


Generated on Tue Mar 1 13:20:21 2005 for NVSGSDK by NVIDIA