# VTK window doesn't show up?!...

**URL:** https://discourse.vtk.org/t/vtk-window-doesnt-show-up/11891
**Category:** Support
**Created:** [July 6, 2023, 4:06pm UTC](https://discourse.vtk.org/t/vtk-window-doesnt-show-up/11891 "2023-07-06T16:06:32Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![fghoussen](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/ecd19e/32.png) [@fghoussen](https://discourse.vtk.org/u/fghoussen)
#### Post date: [July 6, 2023, 4:06pm UTC](https://discourse.vtk.org/t/vtk-window-doesnt-show-up/11891/1 "2023-07-06T16:06:32Z")

</div>

In a very simple case, VTK window doesn’t show up?!.. Any clue why?

Here the sample:

```auto
>> cat vtkTest.cpp 
// STL.
#include <iostream> // cout
#include <stdexcept> // exception

// VTK.
#include <vtkNew.h>
#include <vtkPolyData.h>
#include <vtkPoints.h>
#include <vtkPointData.h>
#include <vtkUnsignedCharArray.h>
#include <vtkVertexGlyphFilter.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleTrackballActor.h>

int run() {
  // Create data to render.
  vtkNew<vtkPolyData> polyData;

  // Create points.
  vtkNew<vtkPoints> points;
  points->InsertNextPoint(0.0, 0.0, 0.0);
  points->InsertNextPoint(1.0, 0.0, 0.0);
  points->InsertNextPoint(0.0, 1.0, 0.0);
  points->InsertNextPoint(0.0, 0.0, 1.0);
  polyData->SetPoints(points);

  // Setup colors.
  vtkNew<vtkUnsignedCharArray> colors;
  colors->SetNumberOfComponents(3);
  colors->SetName("Colors");
  unsigned char black[3] = {0, 0, 0};
  unsigned char red[3] = {255, 0, 0};
  unsigned char green[3] = {0, 255, 0};
  unsigned char blue[3] = {0, 0, 255};
  colors->InsertNextTypedTuple(black);
  colors->InsertNextTypedTuple(red);
  colors->InsertNextTypedTuple(green);
  colors->InsertNextTypedTuple(blue);
  vtkPointData * pointData = polyData->GetPointData();
  if (pointData) {
    pointData->SetScalars(colors);
  }

  // Setup filter.
  vtkNew<vtkVertexGlyphFilter> vertexFilter;
  vertexFilter->SetInputData(polyData);

  // Setup mapper.
  vtkNew<vtkPolyDataMapper> mapper;
  mapper->SetInputConnection(vertexFilter->GetOutputPort());

  // Setup actor.
  vtkNew<vtkActor> actor;
  actor->SetMapper(mapper);
  vtkProperty * prop = actor->GetProperty();
  if (prop) {
    prop->SetPointSize(10);
  }

  // Setup renderer.
  vtkNew<vtkRenderer> renderer;
  renderer->AddActor(actor);
  renderer->SetBackground(1., 1., 1.);

  // Setup window.
  vtkNew<vtkRenderWindow> renderWindow;
  renderWindow->AddRenderer(renderer);
  renderWindow->SetWindowName("vtkTest");

  // Setup interactor.
  vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
  vtkNew<vtkInteractorStyleTrackballActor> style;
  renderWindowInteractor->SetInteractorStyle(style);
  renderWindowInteractor->SetRenderWindow(renderWindow);
  renderWindowInteractor->Initialize();

  // Render scene.
  renderWindow->Render();
  renderWindowInteractor->Start();

  return 0;
}

int main() {
  int rc = 1;

  try {
    rc = run();
  }
  catch(std::exception & e) {
    std::cerr << "Error - " << e.what() << std::endl;
    rc = 1;
  }
  std::cout << "Main thread: exiting..." << std::endl;

  return rc;
}

>> cat CMakeLists.txt 
cmake_minimum_required (VERSION 3.20)

# Define project
project(vtkTest C CXX)

# Get VTK targets to compile / link with.
find_package(VTK
             COMPONENTS
               CommonCore
               CommonDataModel
               FiltersGeneral
               InteractionStyle
               RenderingCore
             REQUIRED)
message(STATUS "VTK VERSION=${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}")

# Define binary
add_executable(vtkTest vtkTest.cpp)
vtk_module_autoinit(TARGETS vtkTest MODULES "${VTK_LIBRARIES}")
target_include_directories(vtkTest PRIVATE "${VTK_INCLUDE_DIRS}")
target_link_libraries(vtkTest PRIVATE "${VTK_LIBRARIES}")

```

Now, build seems OK:

```auto
>> cd build/

>> cmake ..
-- VTK VERSION=9.1
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/vtkTest/build

>> make VERBOSE=1
[50%] Building CXX object CMakeFiles/vtkTest.dir/vtkTest.cpp.o
/usr/bin/c++ -Dkiss_fft_scalar=double -DvtkRenderingCore_AUTOINIT_INCLUDE=\"/tmp/vtkTest/build/CMakeFiles/vtkModuleAutoInit_9b5895f873bcba09752b0c704bf968d6.h\" -I/tmp/vtkTest -isystem /usr/include/vtk-9.1 -MD -MT CMakeFiles/vtkTest.dir/vtkTest.cpp.o -MF CMakeFiles/vtkTest.dir/vtkTest.cpp.o.d -o CMakeFiles/vtkTest.dir/vtkTest.cpp.o -c /tmp/vtkTest/vtkTest.cpp
[100%] Linking CXX executable vtkTest
/usr/bin/cmake -E cmake_link_script CMakeFiles/vtkTest.dir/link.txt --verbose=1
/usr/bin/c++ CMakeFiles/vtkTest.dir/vtkTest.cpp.o -o vtkTest /usr/lib/x86_64-linux-gnu/libvtkInteractionStyle-9.1.so.9.1.0 /usr/lib/x86_64-linux-gnu/libvtkRenderingCore-9.1.so.9.1.0 /usr/lib/x86_64-linux-gnu/libvtkFiltersGeneral-9.1.so.9.1.0 /usr/lib/x86_64-linux-gnu/libvtkFiltersCore-9.1.so.9.1.0 /usr/lib/x86_64-linux-gnu/libvtkCommonExecutionModel-9.1.so.9.1.0 /usr/lib/x86_64-linux-gnu/libvtkCommonDataModel-9.1.so.9.1.0 /usr/lib/x86_64-linux-gnu/libvtkCommonTransforms-9.1.so.9.1.0 /usr/lib/x86_64-linux-gnu/libvtkCommonMisc-9.1.so.9.1.0 /usr/lib/x86_64-linux-gnu/libvtkCommonMath-9.1.so.9.1.0 /usr/lib/x86_64-linux-gnu/libvtkkissfft-9.1.so.9.1.0 /usr/lib/x86_64-linux-gnu/libvtkCommonCore-9.1.so.9.1.0 /usr/lib/x86_64-linux-gnu/libtbb.so.12.8 /usr/lib/x86_64-linux-gnu/libvtksys-9.1.so.9.1.0 -ldl 

```

… But, the application doesn’t open any VTK window and returns?!..

```auto
>> ./vtkTest 
Main thread: exiting...

```

This is happening on debian/testing with apt-install vtk:

```auto

>> cmake --debug-find ..
...
  find_package considered the following locations for VTK's Config module:
  The file was found at
    /usr/lib/x86_64-linux-gnu/cmake/vtk-9.1/vtk-config.cmake

>> apt-file search /usr/lib/x86_64-linux-gnu/cmake/vtk-9.1/vtk-config.cmake
libvtk9-dev: /usr/lib/x86_64-linux-gnu/cmake/vtk-9.1/vtk-config.cmake

>> dpkg -l libvtk9-dev
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-=========================-============-=================================
ii libvtk9-dev 9.1.0+really9.1.0+dfsg2-5 amd64 VTK header files

```

Any clue on why the window doesn’t pop up?!..

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [July 7, 2023, 5:17pm UTC](https://discourse.vtk.org/t/vtk-window-doesnt-show-up/11891/2 "2023-07-07T17:17:51Z")

</div>

From the cmake output, it looks like you aren’t linking all of the necessary libraries.

In CMakeLists.txt, add `RenderingOpenGL2` and `RenderingFreeType` to `COMPONENTS`.

---

<div class="post-metadata">

### Author: ![fghoussen](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/ecd19e/32.png) [@fghoussen](https://discourse.vtk.org/u/fghoussen)
#### Post date: [July 7, 2023, 5:56pm UTC](https://discourse.vtk.org/t/vtk-window-doesnt-show-up/11891/3 "2023-07-07T17:56:02Z")

</div>

Thanks, that works now!.. But if I missed component how could this has succeeded to link?!..

Using `./Utilities/Maintenance/FindNeededModules.py` I just discovered that `RenderingOpenGL2` and `RenderingFreeType` are reported as “suggestions”: that’s why I didn’t add them (as link was OK). Why did it compile/link without these component anyway?

What is the logic to know which component to use for compile / link? How to know which “suggested” component are indeed mandatory: how to choose from the list of suggested component?!

Any explanation on these questions would be helpful

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [July 7, 2023, 7:35pm UTC](https://discourse.vtk.org/t/vtk-window-doesnt-show-up/11891/4 "2023-07-07T19:35:59Z")

</div>

Many rendering classes in VTK are factory classes. To make a long story short, this allows some classes to be substituted by others according to what libraries are linked. The actual substitution occurs at runtime, but it depends on which libraries are loaded by the process.

So if you link to `RenderingOpenGL2`, then any call to `vtkRenderer::New()` will actually return a `vtkOpenGLRenderer` object. Because of VTK’s factory mechanism that’s built into the `New()` method of many VTK classes.

The default `vtkRenderWindow` and `vtkRenderer` don’t actually contain any code for rendering onto the screen. They must be overridden or nothing is rendered.

Which of the many “suggested” components are needed will depend on what classes your program uses. There aren’t any tools in VTK to provide a definite answer. But if all features of your program are working as expected, you know that you’re linking all the necessary libraries.

---

<div class="post-metadata">

### Author: ![fghoussen](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/ecd19e/32.png) [@fghoussen](https://discourse.vtk.org/u/fghoussen)
#### Post date: [July 7, 2023, 8:45pm UTC](https://discourse.vtk.org/t/vtk-window-doesnt-show-up/11891/5 "2023-07-07T20:45:46Z")

</div>

> [@dgobbi](#):
>
> In CMakeLists.txt, add `RenderingOpenGL2` and `RenderingFreeType` to `COMPONENTS`.

I’ve done it: compile / link is OK, running vtkTest trigger a window that shows up… But I realize I can not use the mouse to navigate into the viewer / scene?!.. The scene is frozen.

How to fix this?

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [July 7, 2023, 8:51pm UTC](https://discourse.vtk.org/t/vtk-window-doesnt-show-up/11891/6 "2023-07-07T20:51:22Z")

</div>

Add `RenderingUI` to `COMPONENTS`.  
It’s a new library for VTK 9, it didn’t exist in VTK 8 and I had forgotten about it.

---

<div class="post-metadata">

### Author: ![fghoussen](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/ecd19e/32.png) [@fghoussen](https://discourse.vtk.org/u/fghoussen)
#### Post date: [July 7, 2023, 9:05pm UTC](https://discourse.vtk.org/t/vtk-window-doesnt-show-up/11891/7 "2023-07-07T21:05:44Z")

</div>

I’ve just tried: same thing, window pops-up, no mouse control?!..

```auto
>> ./vtkTest 
X Error of failed request: BadWindow (invalid Window parameter)
  Major opcode of failed request: 38 (X_QueryPointer)
  Resource id in failed request: 0x3000002
  Serial number of failed request: 519
  Current serial number in output stream: 519

```

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [July 8, 2023, 7:03am UTC](https://discourse.vtk.org/t/vtk-window-doesnt-show-up/11891/8 "2023-07-08T07:03:21Z")

</div>

I can confirm this behaviour in Windows with the VTK master.

If you comment out `renderWindowInteractor->SetInteractorStyle(style);` you can interact with the default windows interactor. However "vtkInteractorStyleTrackballActor’ doesn’t seem to work.

I can replicate this behaviour using [ColoredPoints](https://examples.vtk.org/site/Cxx/PolyData/ColoredPoints/) also with [VertexGlyphFilter](https://examples.vtk.org/site/Cxx/Filtering/VertexGlyphFilter/).

Yet it works here[TrackballActor](https://examples.vtk.org/site/Cxx/Interaction/TrackballActor/)

I suspect it is related to something in `vtkVertexGlyphFilter`.

---

<div class="post-metadata">

### Author: ![fghoussen](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/ecd19e/32.png) [@fghoussen](https://discourse.vtk.org/u/fghoussen)
#### Post date: [July 8, 2023, 7:06am UTC](https://discourse.vtk.org/t/vtk-window-doesnt-show-up/11891/9 "2023-07-08T07:06:17Z")

</div>

Does module order matter? If yes, how to know the correct order?

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [July 8, 2023, 7:54am UTC](https://discourse.vtk.org/t/vtk-window-doesnt-show-up/11891/10 "2023-07-08T07:54:11Z")

</div>

It shouldn’t matter.

---

<div class="post-metadata">

### Author: ![fghoussen](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/ecd19e/32.png) [@fghoussen](https://discourse.vtk.org/u/fghoussen)
#### Post date: [July 8, 2023, 8:21am UTC](https://discourse.vtk.org/t/vtk-window-doesnt-show-up/11891/11 "2023-07-08T08:21:03Z")

</div>

> [@amaclean](#):
>
> If you comment out `renderWindowInteractor->SetInteractorStyle(style);`

Before reading your reply, I was just testing this!.. And get the same result as you describe: using `vtkInteractorStyleTrackballActor` creates the problem even if, as far as I have checked in VTK sources / modules, this seems to me to be implemented in the InteractionStyle module which is part of required component.

I need trackball!..

My understanding is that from v9.1 trackball is broken so maybe I’ll use a previous version.

Is there any tests/fix I could try to fix this? Is it worth I open an issue in the vtk gitlab?

> Yet it works here[TrackballActor](https://examples.vtk.org/site/Cxx/Interaction/TrackballActor/)  
> I suspect it is related to something in `vtkVertexGlyphFilter`

I see [TrackballActor](https://examples.vtk.org/site/Cxx/Interaction/TrackballActor/) works but doesn’t use `vtkVertexGlyphFilter`

---

<div class="post-metadata">

### Author: ![fghoussen](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/ecd19e/32.png) [@fghoussen](https://discourse.vtk.org/u/fghoussen)
#### Post date: [July 8, 2023, 8:28am UTC](https://discourse.vtk.org/t/vtk-window-doesnt-show-up/11891/12 "2023-07-08T08:28:43Z")

</div>

> I see [TrackballActor](https://examples.vtk.org/site/Cxx/Interaction/TrackballActor/) works but doesn’t use `vtkVertexGlyphFilter`

Using `vtkInteractorStyleTrackballActor` but removing `vtkVertexGlyphFilter` (setting input data directly to the mapper), I get an empty window! 😉

---

<div class="post-metadata">

### Author: ![fghoussen](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/ecd19e/32.png) [@fghoussen](https://discourse.vtk.org/u/fghoussen)
#### Post date: [July 8, 2023, 8:52am UTC](https://discourse.vtk.org/t/vtk-window-doesnt-show-up/11891/13 "2023-07-08T08:52:19Z")

</div>

> [@fghoussen](#):
>
> Is it worth I open an issue in the vtk gitlab?

Gitlab doesn’t allow me to create an issue?!.. I get “The form contains the following error: Your issue has been recognized as spam. Please, change the content to proceed.” and no way to know why!

If somebody can open an issue would be good I guess

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [July 8, 2023, 9:40am UTC](https://discourse.vtk.org/t/vtk-window-doesnt-show-up/11891/14 "2023-07-08T09:40:23Z")

</div>

I’ll open an issue for you.

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [July 8, 2023, 10:06am UTC](https://discourse.vtk.org/t/vtk-window-doesnt-show-up/11891/15 "2023-07-08T10:06:47Z")

</div>

@fghoussen An issue for this has been opened here [issue 9023](https://gitlab.kitware.com/vtk/vtk/-/issues/19023).

---

<div class="post-metadata">

### Author: ![fghoussen](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/ecd19e/32.png) [@fghoussen](https://discourse.vtk.org/u/fghoussen)
#### Post date: [July 8, 2023, 10:44am UTC](https://discourse.vtk.org/t/vtk-window-doesnt-show-up/11891/16 "2023-07-08T10:44:46Z")

</div>

@amaclean: Thanks!

---

<div class="post-metadata">

### Author: ![fghoussen](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/f/ecd19e/32.png) [@fghoussen](https://discourse.vtk.org/u/fghoussen)
#### Post date: [July 8, 2023, 10:46am UTC](https://discourse.vtk.org/t/vtk-window-doesnt-show-up/11891/17 "2023-07-08T10:46:13Z")

</div>

> [@fghoussen](#):
>
> Using `vtkInteractorStyleTrackballActor` but removing `vtkVertexGlyphFilter` (setting input data directly to the mapper), I get an empty window! 😉

Is there another filter able to render points I could use to replace `vtkVertexGlyphFilter`?

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [July 9, 2023, 8:58am UTC](https://discourse.vtk.org/t/vtk-window-doesnt-show-up/11891/18 "2023-07-09T08:58:40Z")

</div>

I am not sure what you want to do but you could try [vtkGlyph3DMapper](https://vtk.org/doc/nightly/html/classvtkGlyph3DMapper.html). There are about 30 examples in the VTKExamples.
