Search code examples
vtk

Why does VTK give an error "Could not locate vtkTextRenderer object" for the balloon widget example code?


I am learning to use VTK widgets.

I am using the exact same code provided in the example code below for the balloon widget: https://vtk.org/Wiki/VTK/Examples/Cxx/Widgets/BalloonWidget

I am using Opengl2 rendering using the below macro:

#include "vtk-8.2/vtkAutoInit.h"
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);

I can see the sphere and the polygon rendered in the render window, and I can also interact with these objects.

However, when I hover the mouse pointer on the objects, there is no balloon widget popup and instead I get the below error in the output window:

ERROR: In C:\vtk\src\Rendering\Core\vtkTextMapper.cxx, line 550 vtkOpenGLTextMapper (00068BD8): Could not locate vtkTextRenderer object.

Google search did not yield any fix for this issue, I hope someone can help me out on this!


Solution

  • Upon further investigation, I have found the fix for this error. The solution is to add VTK_MODULE_INIT(vtkRenderingFreeType); after #include "vtk-8.2/vtkAutoInit.h". The top of the file now looks as below:

    #include "vtk-8.2/vtkAutoInit.h"
    VTK_MODULE_INIT(vtkRenderingOpenGL2);
    VTK_MODULE_INIT(vtkInteractionStyle);
    VTK_MODULE_INIT(vtkRenderingFreeType);