For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings


Need to speed up your development?
Have a look at our:

Samples & Tools


Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

Text Height and Visual3d_Layer Text Height

Domagoj Baronica's picture


I'm having problems setting the height of text in my 3D viewer. Here is the code:
TCollection_ExtendedString aTCoText(text);
gp_Pnt aPnt, OrigineDimZT(0,0,0);
BRepBuilderAPI_MakeVertex vert(OrigineDimZT);

Handle(Prs3d_Presentation) aPresentation= new Prs3d_Presentation(m_pAISContext->CurrentViewer()->Viewer(),Standard_True);
Handle(Prs3d_TextAspect) aTextAspect= new Prs3d_TextAspect();
Prs3d_Text::Draw(aPresentation,aTextAspect,aTCoText, OrigineDimZT);

I tried many different values in SetHeight method, but the text height is unchanged in the viewer. It really bothers me because it makes OC text functionality almost unusable.

In addition, the same behavior is seen when I use Visual3d_Layer to display text as an overlay in the viewer. The size of text can't be changed.

Is there any other way to display 2D and 3D text in 3D viewer?


Pawel's picture


I observe a similar behavior using Visual3d_Layer. No matter what font I use I have to set the text size to 12.0 (it's quite small) otherwise it won't be displayed. I use the following code:

myLayer->SetColor (color);
myLayer->SetTextAttributes(Graphic3d_NOF_ASCII_MONO, Aspect_TODT_NORMAL, color);
myLayer->DrawText(myString, 0, 0, 12.0);

Anyone has an idea why?

Paul Jimenez's picture

I had a similar problem where the text would sometimes disappear just because. At the end, it had to do with the order of methods being called. It is also worth noting that the starting point of the text MUST BE inside the canvas.

The order I use here is as follows:

TextSize (you may not need it)

So... just try switching SetColor and SetTextAttributes and see if that works for you.

Pawel's picture

Hi Paul,

thanks for your reply. Well, I tried and I guess something strange is going on here... Switching the order of the calls does not help in my case but... in the meanwhile I implemented redrawing of the layer according to the view rotation/zooming etc. The strange thing is that if I use "12.0" as the text size it gets displayed correctly the first time I draw it. Different values of the text size work after the layer is redrawn (e.g. after zooming in my case).

I keep on investigating. Displaying of the ColorScale with different text sizes works so it should also work for the layer.

By the way, is this possible to display both the ColorScale and a user-drawn layer at the same time? One seems to erase the other in my case.


P.S. Thanks for the post: - really helpful.

Paul Jimenez's picture

I have no idea what you mean by ColorScale.

What I highly recommend you is that you search the forums for OCCPATCH. There is a post that deals with font size in the layer and another one with the layer not being re-drawn in a few cases.

After applying those patches, the over-layer I use works just fine. I only use a single font size, though.

Pawel's picture

By ColorScale I meant a call to


I have a version with some OCCPATCHes applied. I'll see if I have the corresponding patches and experiment with that.


Pawel's picture

Hi Paul,

I found a workaround for displaying texts on a layer which looks like this:

//dummy call to set text attributes
myLayer->SetColor (color);
myLayer->SetTextAttributes(Graphic3d_NOF_ASCII_MONO, Aspect_TODT_NORMAL, scaleTextColor);
myLayer->DrawText("test", 0, 0, textSize);

//the desired functionality
myLayer->SetViewport(w ? w : 1, h ? h : 1);
myLayer->SetOrtho(0., extremumValue, 0., extremumValue, Aspect_TOC_TOP_LEFT);
myLayer->SetColor (color);
myLayer->SetTextAttributes(Graphic3d_NOF_ASCII_MONO, Aspect_TODT_NORMAL, color);
myLayer->DrawText(myString, 0, 0, textSize);

However, I already noticed two problems: (1)Unfortunately, I don't think it works for line width. (2) Besides it affects the font of the color scale.

So I'm going to test your patch: tomorrow or Monday.


Pawel's picture

Hi Paul,

after some testing I guess I'm again more confused than before. I've tested three applications: one had no problem with setting the font size, one used the workaround I posted before, the last one could only work with the font size = 12.0 ...

So I applied two patches:
- one ( from François Lauzon) dealing with the layer not being redrawn under some conditions (I can confirm it works)
- the one from you ( dealing with line width and text size. To restrict the number of test cases I tested only the text size. Unfortunately, the patch didn't work for me... Again, I saw an interference with the font used by the ColorScale so there are a couple of things which I hope I will review soon to get it work.


Paul Jimenez's picture

Does the application that has no problems show the ColorScale? It may be an issue with that.

Anyway, I have had plenty of weird issues with OpenCASCADE's Visualization. Many of those issues have been solved with some patches, but others require trying different methods to work around them.

It is nice the team is working now in a new set of Visualization classes (NIS), but it is still far from complete. It also has problems (with the PC I use here with Intel graphics shapes are not drawn, yet they can be highlighted).

As usual, if you find a patch or workaround, do not forget to mention it.

Contact us

Attention: DO NOT use this form for all kind of request for the removal of your personal data. Please follow this link for such cases.