[vtkusers] vtkOpenGLSkybox and cubic texture map orientation

Ken Martin ken.martin at kitware.com
Sat Jan 27 15:22:10 EST 2018


Here is a rough example (maybe not 100% but close, I just grabbed the key
parts form TestCubeMap2.cxx. It uses 6 square textures and assembles them
into a cube map.

  const char* fpath[] =
    {
    "Data/skybox/posx.jpg",
    "Data/skybox/negx.jpg",
    "Data/skybox/posy.jpg",
    "Data/skybox/negy.jpg",
    "Data/skybox/posz.jpg",
    "Data/skybox/negz.jpg"
    };

  vtkNew<vtkTexture> texture;
  texture->CubeMapOn();
  texture->InterpolateOn();
  texture->RepeatOff();
  texture->EdgeClampOn();

  // mipmapping works on many systems but is not
  // core 3.2 for cube maps. VTK will silently
  // ignore it if it is not supported.
  texture->MipmapOn();

  for (int i = 0; i < 6; i++)
  {
    vtkNew<vtkJPEGReader> imgReader;
    imgReader->SetFileName(
      vtkTestUtilities::ExpandDataFileName(argc, argv, fpath[i]));
    vtkNew<vtkImageFlip> flip;
    flip->SetInputConnection(imgReader->GetOutputPort());
    flip->SetFilteredAxis(1); // flip y axis
    texture->SetInputConnection(i, flip->GetOutputPort(0));
  }

  vtkNew<vtkSkybox> world;
  world->SetTexture(texture);
  renderer->AddActor(world);


On Sat, Jan 27, 2018 at 3:11 PM, BBerco <bebe0705 at colorado.edu> wrote:

> 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=0ahUKEwjiw7q09PjYAhVSyGMKHYKVA
> q8Q_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
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/
> opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://vtk.org/mailman/listinfo/vtkusers
>



-- 
Ken Martin PhD
Distinguished Engineer
Kitware Inc.
28 Corporate Drive
Clifton Park NY 12065

This communication, including all attachments, contains confidential and
legally privileged information, and it is intended only for the use of the
addressee.  Access to this email by anyone else is unauthorized. If you are
not the intended recipient, any disclosure, copying, distribution or any
action taken in reliance on it is prohibited and may be unlawful. If you
received this communication in error please notify us immediately and
destroy the original message.  Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtkusers/attachments/20180127/4f5a31c7/attachment.html>


More information about the vtkusers mailing list