How to draw 2D text on top of a 3D figure with Makie

I have the following code:

using GeometryBasics, GLMakie

const SCALE = 1.2
const SEGMENTS = 7                    # number of tether segments

function create_coordinate_system(scene, points = 10, length = 10)
    # create y-axis in green
    points -= 3
    mesh!(scene, Cylinder(Point3f0(0, -(points+1) * SCALE, 0), Point3f0(0, (points+1) * SCALE , 0), Float32(0.05 * SCALE)), color=:green)
    for i in range(0, length=10)
        start = Point3f0(0, (points+1 + 0.07 * (i-0.5)) * SCALE, 0)
        stop = Point3f0(0, (points+1 + 0.07 * (i+0.5)) * SCALE, 0)
        mesh!(scene, Cylinder(start, stop, Float32(0.018 * (10 - i) * SCALE)), color=:green)
    end
end

function main()
    scene, layout = layoutscene(resolution = (840, 900), backgroundcolor = RGBf0(0.7, 0.8, 1))
    scene3D = LScene(scene, scenekw = (show_axis=false, limits = Rect(-7,-10.0,0, 11,10,11), resolution = (800, 800)), raw=false)
    create_coordinate_system(scene3D)

    cam = cameracontrols(scene3D.scene)
    cam.lookat[] = [0,0,5]
    cam.eyeposition[] = [-15,-15,5]
    update_cam!(scene3D.scene)

    layout[1, 1] = scene3D
    layout[2, 1] = buttongrid = GridLayout(tellwidth = false)
    buttongrid[1, 1:1] = [Button(scene, label = "RESET")]

    text!(scene3D, "12345", position = Point2f0(0, 0), textsize = 30, align = (:left, :bottom), show_axis = false, space = :screen)
    text!(scene, "54321", position = Point2f0(0, 200), textsize = 30, align = (:left, :bottom), show_axis = false, space = :screen)

    display(scene)
  
    return nothing
end

It creates the attached graph. I tried two ways to display text, first to plot it on scene3D and in the second line to plot it on scene. If I plot it on scene3D it gets distorted, and if I plot it on scene the 3D scene hides the text that is behind it.

How can I draw undistorted text that is not hidden?

That should work. Are you up to date on GLMakie and AbstractPlotting?

(KiteViewer) pkg> st
      Status `~/repos/KiteViewer/Project.toml`
  [537997a7] AbstractPlotting v0.15.27
  [69666777] Arrow v1.4.1
  [5789e2e9] FileIO v1.7.0
  [e9467ef8] GLMakie v0.1.30
  [5c1252a2] GeometryBasics v0.3.12
  [ee78f7c6] Makie v0.12.0
  [7269a6da] MeshIO v0.4.6
  [9b87118b] PackageCompiler v1.2.5
  [731186ca] RecursiveArrayTools v2.11.3
  [295af30f] Revise v3.1.15
  [6038ab10] Rotations v1.0.2
  [90137ffa] StaticArrays v1.1.1
  [09ab397b] StructArrays v0.5.1
  [9ff05d80] TickTock v1.1.0
  [ddb6d928] YAML v0.4.6

It was working about 4 months ago. I think it also works on Windows. But not any longer on Linux.

To be clear: I want to see “54321” instead of “54”.

screen space text is AbstractPlotting v0.16+ and GLMakie v0.2+

Thank you! I had to remove Makie from my project to be able to upgrade GLMakie and AbstractPlotting, but now it seams to work fine! :smiley:

1 Like