How to fix the font actor size, that is, the font size does not change when the camera distance is changed

I need to make the text face the camera, so I tried two methods

  1. vtkVectorText + vtkFollower
    This method cannot have a fixed font size like vtkTextActor
  2. vtkTextActor
    It is a vtkActor2D object, this method can not set the z-axis coordinates, can not fix the font at a certain position (x, y, z)
    So how can I display fixed-size text at a certain point (x, y, z)? When I zoom the camera, its size will not change, and it always faces the camera
2 Likes

You can try vtkCaptionActor2D. I have use it in my 3D scene(rendering in QVTKOpenGLNativeWidget). Here is the relevant code:

vtkSmartPointer<vtkCaptionActor2D> caption = vtkSmartPointer<vtkCaptionActor2D>::New();
caption->SetCaption(txt.toStdString().c_str());
caption->SetAttachmentPoint(centerPt.GetData());
caption->GetTextActor()->SetTextScaleModeToNone(); //key: fix the font size
caption->GetCaptionTextProperty()->SetFontSize(15);
caption->GetCaptionTextProperty()->SetFrame(false);
caption->GetCaptionTextProperty()->SetShadow(false);

I hope it will be useful to you.

2 Likes

It’s perfect,thank you!

That’s great! You are welcome! :grinning: