How to keep the "screen size/position" of an object regardless of the camera focal length

Hi everyone,

This is a little tricky question.
I am working on ad add-on in which the user is able to add text objects that is automatically constrained to the camera using “child of” constraint and positioned correctly. Here is an example with a camera that has 35mm focal length:

Now what I want is to keep that “screen” position and text size the same regardless of what would be the focal length of the camera. If I switch the focal length of the camera, the text would occupy different position (screen space wise) and would appear smaller or bigger (depending on focal length).

Here is an example with focal length changed to 28mm

The text appears to be smaller and moved up in the screen space.

All of that is obviously caused by how optics work and is the correct behavior.

So my question is this:
What would be the formula to calculate text object position and text font size, so regardless of the focal length the text would always appear to have similar size and position in screen space (camera frame)?

How would you guys approach it?

Thank you so much in advance!!!


Rather than doing this, why not just draw directly on the view with BGL? Since this is 2D, it won’t move or scale at all

My thinking here was mostly based on the idea that it is really easy for user to edit Blender Text object, just by switching to edit mode.
I also need this functionality for video reference that animators might want to use and have it attached to their shot cams.

BUT that being said, I definitely would like to find/learn the best way to display any kind of information inside of the camera or 3dview that would just stick and not change size/position.

I don’t have any experience with BGL, what would be the best place to learn about it?

Thanks so much!

right here:
FYI- blf is the module you want, bgl is more of a general purpose GL drawing module

1 Like

Oh, that is great! Thanks!

Quick question though…what would be the easy way to attach a text created like this to the camera frame? I looked at the example in the provided link, but can’t quite figure this out.