[vtkusers] vtkOpenGLSkybox and cubic texture map orientation

BBerco bebe0705 at colorado.edu
Sat Jan 27 15:11:36 EST 2018


I am trying to display a skybox environment using the vtkOpenGLSkybox class.

The documentation of vtkSkybox says that a texture cube must be provided. I
used  this one
<https://www.google.com/search?q=cubic+texture+file&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjiw7q09PjYAhVSyGMKHYKVAq8Q_AUICigB&biw=1280&bih=703#imgrc=-t5W2ikSKVWtQM:>  

I'm providing the skybox actor with a cube source. But s you can see below,
the texture is not properly mapped. 

Any advice?

<http://vtk.1045678.n5.nabble.com/file/t341520/Screen_Shot_2018-01-27_at_13.png> 


main.cpp:
*
#include <vtkSphereSource.h>
#include <vtkCubeSource.h>
#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkOpenGLSkybox.h>
#include <vtkImageReader2Factory.h>
#include <vtkTexture.h>
#include <vtkTransformTextureCoords.h>
#include <vtkImageReader2.h>

int main(int, char *[])
{



   // Read texture file
  vtkSmartPointer<vtkImageReader2Factory> readerFactory =
vtkSmartPointer<vtkImageReader2Factory>::New();
  vtkImageReader2 *imageReader = readerFactory
->CreateImageReader2("../map.png");
  
  imageReader->SetFileName("../map.png");

  // Create texture
  vtkSmartPointer<vtkTexture> texture =vtkSmartPointer<vtkTexture>::New();
  texture->SetInputConnection(imageReader->GetOutputPort());


  // Create a cube
  vtkSmartPointer<vtkCubeSource> skybox_source = 
  vtkSmartPointer<vtkCubeSource>::New();
  

  vtkSmartPointer<vtkPolyDataMapper> skybox_mapper = 
  vtkSmartPointer<vtkPolyDataMapper>::New();
  skybox_mapper->SetInputConnection(skybox_source->GetOutputPort());
  
  // Create the skybox
  vtkSmartPointer<vtkOpenGLSkybox> skybox =
vtkSmartPointer<vtkOpenGLSkybox>::New();

  skybox -> SetTexture(texture);
  skybox -> SetMapper(skybox_mapper);





  // Create a sphere
  vtkSmartPointer<vtkSphereSource> sphereSource = 
  vtkSmartPointer<vtkSphereSource>::New();
  sphereSource->SetCenter(0.0, 0.0, 0.0);
  sphereSource->SetRadius(5.0);

  vtkSmartPointer<vtkPolyDataMapper> mapper = 
  vtkSmartPointer<vtkPolyDataMapper>::New();
  mapper->SetInputConnection(sphereSource->GetOutputPort());
  
  vtkSmartPointer<vtkActor> actor = 
  vtkSmartPointer<vtkActor>::New();
  actor->SetMapper(mapper);

  vtkSmartPointer<vtkRenderer> renderer = 
  vtkSmartPointer<vtkRenderer>::New();
  vtkSmartPointer<vtkRenderWindow> renderWindow = 
  vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = 
  vtkSmartPointer<vtkRenderWindowInteractor>::New();
  renderWindowInteractor->SetRenderWindow(renderWindow);

  // renderer->AddActor(actor);
  renderer->AddActor(skybox);

  // renderer->SetBackground(.3, .6, .3); // Background color green

  renderWindow->Render();  
  renderWindowInteractor->Start();

  return EXIT_SUCCESS;
}
*














--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html


More information about the vtkusers mailing list