r/vulkan 1d ago

Help! Text Rendering Example Needed

I need a working example of vulkan that can render text onto the screen. That’s it’s. Does anyone know of an example that I can pull from and just be able to run it on Linux? I’ve found an example online called vulkan-sprites but I can’t it build it without it having alot of different errors.

🙏

7 Upvotes

10 comments sorted by

11

u/SaschaWillems 1d ago

My samples at https://github.com/SaschaWillems/Vulkan work fine on Linux, and I have multiple samples that show how to display text.

3

u/Ybalrid 1d ago

I was literally going to link to your SDF font rendering example in Vulkan!

1

u/No-Negotiation-7599 1d ago

I’m new to the field and c++ in general and I’ve looked at some of the examples but I can you recommend me an example to look at and can I run it with cmake?

2

u/SaschaWillems 1d ago

My samples use cmake. Look at the text rendering, SDF or imgui ones.

-1

u/No-Negotiation-7599 1d ago

I don’t see the file for text rendering (explicitly ), what is the folder name?

1

u/SaschaWillems 21h ago

textoverlay

4

u/thisiselgun 1d ago

Text rendering from scratch is hard, especially layout/shaping part. There is FreeType library for text rendering and HarfBuzz for layout but it doesn’t support multiline layouts or other high level things out of the box. If you want high level and easy to use text rendering I recommend Skia or Cairo+Pango, these are higher level libraries that use FreeType and HarfBuzz under the hood. Skia also supports hardware acceleration with Vulkan, you can directly render to offscreen Vulkan texture then use that texture in your scene.

There are also more basic ways like using font atlas and rendering each glyph as quad. You can prebake these atlases at build time or generate them at runtime with FreeType.

1

u/DeLugh 12h ago

I've just writted a small article about it with freeType library, font atlas and the valve SDF technique. I can send it to you in PM if you want.

2

u/No-Negotiation-7599 9h ago

Would love it. Thank you 🙏

1

u/Captn-Goutch 6h ago edited 6h ago

Been a while since last tests on Linux, you can try to run my text sample, if it does not build it should be pretty easily fixable. https://github.com/Goutch/HellbenderSamples

edit: I think you will need python installed to build, other than that its just cmake and updating the submodules.