# Why changing example to port it to VR doesn't work?

**URL:** https://discourse.vtk.org/t/why-changing-example-to-port-it-to-vr-doesnt-work/5937
**Category:** VR/AR
**Created:** [June 4, 2021, 3:59pm UTC](https://discourse.vtk.org/t/why-changing-example-to-port-it-to-vr-doesnt-work/5937 "2021-06-04T15:59:39Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![myousefi2016](https://discourse.vtk.org/user_avatar/discourse.vtk.org/myousefi2016/32/921_2.png) [@myousefi2016](https://discourse.vtk.org/u/myousefi2016)
#### Post date: [June 4, 2021, 3:59pm UTC](https://discourse.vtk.org/t/why-changing-example-to-port-it-to-vr-doesnt-work/5937/1 "2021-06-04T15:59:40Z")

</div>

I cloned the latest VTK 9.0 version from your Github repo and build it with OpenVR and SDL2 enabled. I’m using Windows 10 and Microsoft Visual Studio 2019. I’m able to build [**RayCastIsosurface**](https://kitware.github.io/vtk-examples/site/Cxx/VolumeRendering/RayCastIsosurface/) example without any problem and run it also without any runtime error. I wanted to port this 3D volume rendering into my HTC Vive VR headset by changing these renderers to OpenVR:

- `vtkRenderWindow` → `vtkOpenVRRenderWindow`
- `vtkRenderWindowInteractor` → `vtkOpenVRRenderWindowInteractor`
- `vtkRenderer` → `vtkOpenVRRenderer`
- `vtkCamera` → `vtkOpenVRCamera`

Again build is successful but when I run the program it doesn’t show anything. Even it doesn’t show any error. It just exits without any information about why the program is terminated.

Any idea why it happens? By the way, I have ParaView 5.9 with OpenVR and I’m able to see 3D renderings in my VR headset without any problem. So, I’m 100% confident that nothing is wrong with my SteamVR.

---

<div class="post-metadata">

### Author: ![ken-martin](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ken-martin/32/884_2.png) [@ken-martin](https://discourse.vtk.org/u/ken-martin)
#### Post date: [June 4, 2021, 5:45pm UTC](https://discourse.vtk.org/t/why-changing-example-to-port-it-to-vr-doesnt-work/5937/2 "2021-06-04T17:45:49Z")

</div>

You might want to give VTK master a try. VTK 9.0 (unfortunately) is pretty old at this point.

Also I don’t think we rely on SDL2 for the VR stuff anymore. So you shouldn’t need it (at least with VTK master)

---

<div class="post-metadata">

### Author: ![myousefi2016](https://discourse.vtk.org/user_avatar/discourse.vtk.org/myousefi2016/32/921_2.png) [@myousefi2016](https://discourse.vtk.org/u/myousefi2016)
#### Post date: [June 4, 2021, 6:43pm UTC](https://discourse.vtk.org/t/why-changing-example-to-port-it-to-vr-doesnt-work/5937/3 "2021-06-04T18:43:09Z")

</div>

I used the current head at the master branch of the VTK. But, still have this problem.

---

<div class="post-metadata">

### Author: ![myousefi2016](https://discourse.vtk.org/user_avatar/discourse.vtk.org/myousefi2016/32/921_2.png) [@myousefi2016](https://discourse.vtk.org/u/myousefi2016)
#### Post date: [June 4, 2021, 6:46pm UTC](https://discourse.vtk.org/t/why-changing-example-to-port-it-to-vr-doesnt-work/5937/4 "2021-06-04T18:46:55Z")

</div>

I created a simple code to reproduce this problem, and still, it doesn’t show anything:

```auto
#include <vtkActor.h>
#include <vtkConeSource.h>
#include <vtkNew.h>
#include <vtkOpenVRCamera.h>
#include <vtkOpenVRInteractorStyle.h>
#include <vtkOpenVRRenderer.h>
#include <vtkOpenVRRenderWindow.h>
#include <vtkOpenVRRenderWindowInteractor.h>
#include <vtkPolyDataMapper.h>

int main(int argc, char* argv[])
{
  // Setup the OpenVR rendering classes
  vtkNew<vtkActor> actor;
  vtkNew<vtkOpenVRRenderer> renderer;
  vtkNew<vtkOpenVRRenderWindow> renderWindow;
  vtkNew<vtkOpenVRRenderWindowInteractor> iren;
  vtkNew<vtkOpenVRInteractorStyle> style;
  vtkNew<vtkOpenVRCamera> cam;

  renderWindow->AddRenderer( renderer.Get() );
  renderer->AddActor( actor.Get() );
  iren->SetRenderWindow( renderWindow.Get() );
  iren->SetInteractorStyle( style.Get() );
  renderer->SetActiveCamera( cam.Get() );

  // Without the next line volume rendering in VR does not work
  renderWindow->SetMultiSamples( 0 );

  // Add a cone to the scene
  vtkNew<vtkConeSource> cone;
  vtkNew<vtkPolyDataMapper> mapper;
  mapper->SetInputConnection( cone->GetOutputPort() );
  actor->SetMapper( mapper.Get() );

  // Render
  renderer->ResetCamera();
  renderWindow->Render();
  iren->Start();

  return EXIT_SUCCESS;
}

```

---

<div class="post-metadata">

### Author: ![ken-martin](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ken-martin/32/884_2.png) [@ken-martin](https://discourse.vtk.org/u/ken-martin)
#### Post date: [June 9, 2021, 1:48pm UTC](https://discourse.vtk.org/t/why-changing-example-to-port-it-to-vr-doesnt-work/5937/5 "2021-06-09T13:48:17Z")

</div>

I just checked the dragon test on my vtk master build and it worked fine. I started steamvr first then I ran it as

C:\Users\ken.martin\Documents\vtk\bin\>bin\vtkRenderingOpenVRCxxTests.exe “TestDragon” “-D” “C:/Users/ken.martin/Documents/vtk/bin/ExternalData/Testing” “-T” “C:/Users/ken.martin/Documents/vtk/bin/Testing/Temporary” -I

Not sure what is off on your example but if you can get the dragon test working maybe that will give you a reference. You might need to copy the controller files into your bin directory. e.g.

```auto
01/29/2021 11:33 AM 1,652 vtk_openvr_actions.json
01/25/2021 12:46 PM 2,303 vtk_openvr_binding_hpmotioncontroller.json
01/29/2021 11:33 AM 1,760 vtk_openvr_binding_oculus_touch.json
01/25/2021 01:14 PM 1,908 vtk_openvr_binding_vive_controller.json

```

---

<div class="post-metadata">

### Author: ![myousefi2016](https://discourse.vtk.org/user_avatar/discourse.vtk.org/myousefi2016/32/921_2.png) [@myousefi2016](https://discourse.vtk.org/u/myousefi2016)
#### Post date: [June 9, 2021, 7:27pm UTC](https://discourse.vtk.org/t/why-changing-example-to-port-it-to-vr-doesnt-work/5937/6 "2021-06-09T19:27:32Z")

</div>

I’m able to run the dragon test without any problem on my computer.

---

<div class="post-metadata">

### Author: ![ken-martin](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ken-martin/32/884_2.png) [@ken-martin](https://discourse.vtk.org/u/ken-martin)
#### Post date: [June 10, 2021, 2:29am UTC](https://discourse.vtk.org/t/why-changing-example-to-port-it-to-vr-doesnt-work/5937/7 "2021-06-10T02:29:09Z")

</div>

If you change your example to use a surface (such as a cone + mapper + actor) instead of a volume does your example work? Just wondering if it is specific to volume rendering.

---

<div class="post-metadata">

### Author: ![myousefi2016](https://discourse.vtk.org/user_avatar/discourse.vtk.org/myousefi2016/32/921_2.png) [@myousefi2016](https://discourse.vtk.org/u/myousefi2016)
#### Post date: [June 10, 2021, 2:53pm UTC](https://discourse.vtk.org/t/why-changing-example-to-port-it-to-vr-doesnt-work/5937/8 "2021-06-10T14:53:26Z")

</div>

No, it doesn’t work if I use a cone instead of volume rendering.

---

<div class="post-metadata">

### Author: ![ken-martin](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ken-martin/32/884_2.png) [@ken-martin](https://discourse.vtk.org/u/ken-martin)
#### Post date: [June 10, 2021, 2:59pm UTC](https://discourse.vtk.org/t/why-changing-example-to-port-it-to-vr-doesnt-work/5937/9 "2021-06-10T14:59:30Z")

</div>

That’s good. Now you’ve got a working example using polydata and a non working example that’s basically the same. Should be able to track down what the issue is by looking at what is different, making them more similar until something changes etc.

---

<div class="post-metadata">

### Author: ![myousefi2016](https://discourse.vtk.org/user_avatar/discourse.vtk.org/myousefi2016/32/921_2.png) [@myousefi2016](https://discourse.vtk.org/u/myousefi2016)
#### Post date: [June 10, 2021, 3:00pm UTC](https://discourse.vtk.org/t/why-changing-example-to-port-it-to-vr-doesnt-work/5937/10 "2021-06-10T15:00:58Z")

</div>

Thank you for your help!

---

<div class="post-metadata">

### Author: ![ken-martin](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ken-martin/32/884_2.png) [@ken-martin](https://discourse.vtk.org/u/ken-martin)
#### Post date: [June 21, 2021, 1:54pm UTC](https://discourse.vtk.org/t/why-changing-example-to-port-it-to-vr-doesnt-work/5937/11 "2021-06-21T13:54:10Z")

</div>

If you are still having issues one thing I thought of was the autoinit code. For vtk tests the autoinit code is added automatically. It handles setting up the object factory for runtime object creation for classes that need it. In your project’s cmakelists file you add something like

```auto
vtk_module_autoinit(
    TARGETS yourexecutable
    MODULES 
            VTK::RenderingOpenGL2
            )

```
