TEXT AS TEXTURE IN GODOT

When creating my game Kanji Memory I needed an efficient way to get images of the Kanji text unto the cards. I did not want to manually draw them. The solution I came out with was using viewports which contained the text and apply the viewport as the texture for the card. I am going to show an example on applying text as a a texture in Godot 3.5.1.

Make content for the Texture

Create a scene with a Label node. Style it how ever you like and save it.

Apply texture to Mesh texture

  • Add a Viewport node to the Spatial scene. Set the viewport dimensions to the dimensions of the Label node. Set the V flip option to checked.

  • Add a Mesh Instance node to the Spatial scene. Change the Mesh to a Plane Mesh.

  • Add a Material to Plane Mesh. Set the Resource to ’Local to Scene’.

  • Set the Albedo texture in the Material to Viewport texture. Set it to the Viewport that contains the Label.

  • The Text will be a texture on the Mesh.

    There are some optimizations that can be done like setting the Viewport to only update once . Also the texture can be stored using code for use in other parthsof the project.

Technique used for car’s number plate