[vtkusers] texture

Luis RIVERA luis at sismo.u-strasbg.fr
Sun Mar 9 09:59:22 EST 2003


Hello,

I am trying to put a texture (earth.ppm)
onto a sphere with the Cxx interface. 
The sphere is there, but the texture doesn't 
show up ...

Thanks for any help.

luis

PS: The few lines I added are marked  with   <-------


#####################################"
void main ()
{

  // create sphere geometry
  vtkSphereSource *sphere = vtkSphereSource::New();
  sphere->SetRadius(1.0);
  sphere->SetThetaResolution(36);
  sphere->SetPhiResolution(36);

  // map to graphics library
  vtkPolyDataMapper *map = vtkPolyDataMapper::New();
  map->SetInput(sphere->GetOutput());

  // actor coordinates geometry, properties, transformation
  vtkActor *aSphere = vtkActor::New();
  aSphere->SetMapper(map);

// ############################################################
// Those are the lines I added                    //     <---------
// texture                                        //     <---------
  vtkTexture   *atext     = vtkTexture::New();    //     <---------
  vtkPNMReader *pnmReader = vtkPNMReader::New();  //     <---------
  pnmReader->SetFileName("../Data/earth.ppm");    //     <---------
  atext->SetInput(pnmReader->GetOutput());        //     <---------
  atext->InterpolateOn();                         //     <---------
  aSphere->SetTexture(atext);                     //     <---------
// #############################################################


  // a renderer and render window
  vtkRenderer *ren1 = vtkRenderer::New();
  vtkRenderWindow *renWin = vtkRenderWindow::New();
  renWin->AddRenderer(ren1);

  // an interactor
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(renWin);

  // add the actor to the scene
  ren1->AddActor(aSphere);
  ren1->SetBackground(1,1,1); // Background color white

  // render an image (lights and cameras are created automatically)
  renWin->Render();

  // begin mouse interaction
  iren->Start();
}


________________________________
Luis Rivera
EOST - IPGS
Universite Louis Pasteur
5, rue Rene Descartes
F67084 Strasbourg cedex

Tel. +33 390 240 047
Fax. +33 390 240 125

e-mail: luis at sismo.u-strasbg.fr





More information about the vtkusers mailing list