Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support basic text/glyph rendering #25

Open
einarf opened this issue Aug 5, 2019 · 8 comments
Open

Support basic text/glyph rendering #25

einarf opened this issue Aug 5, 2019 · 8 comments
Labels
core / important enhancement New feature or request

Comments

@einarf
Copy link
Member

einarf commented Aug 5, 2019

It would be nice to support basic text rendering. I already have a very simple version in demosys-py that could be ported over and possibly improved: https://github.com/Contraz/demosys-py/tree/master/demosys/effects/text

Right now it's just using a texture generated with freetype-py loaded as a TextureArray.

This part is pretty interesting:

From PyPI, recommended: pip install freetype-py. This will install the library with a bundled FreeType binary, so you’re ready to go on Windows, macOS and Linux (all with 32 and 64 bit x86 architecture support).

This means we could provide cross platform support for generating text on the fly in moderngl_window. Still it should probably be an optional dependency.

https://github.com/rougier/freetype-py

@einarf einarf added enhancement New feature or request Documentation Issues related to documentation and removed Documentation Issues related to documentation labels Sep 13, 2019
@lordmauve
Copy link

Doing some research previously I found that rendering freetype glyphs is not enough for correct text rendering; you to use Harfbuzz for shaping Unicode code point sequences, which gives positioned glyphs from the font including chains of accents. Harfbuzz is the only complete open source implementation of this and almost everything uses it.

I don't know if freetype-py uses Harfbuzz itself, but there are Python bindings for Harfbuzz available.

@einarf
Copy link
Member Author

einarf commented Mar 4, 2021

Considering adding a simple bitmapped monospaced text rendere using veramono just so we have something for now.

@naveen521kk
Copy link

naveen521kk commented Mar 18, 2021

After ManimCommunity/ManimPango#28 it should be possible to use ManimPango :)

@einarf
Copy link
Member Author

einarf commented Mar 18, 2021

After ManimCommunity/ManimPango#28 it should be possible to use ManimPango :)

Yep! That would be fun to try out. After this is done :)

@matanox
Copy link

matanox commented Feb 28, 2022

If I may join this conversation, does text rendering have to be a feature of moderngl? Would user code be able to alternatively use any particular other (python) library to draw text into a bitmap, then embed it in a texture provided to moderngl for actual rendering? or will that fall short of handling all the concerns inherent to getting clean text on a display?

@einarf
Copy link
Member Author

einarf commented Feb 28, 2022

If I may join this conversation, does text rendering have to be a feature of moderngl? Would user code be able to alternatively use any particular other (python) library to draw text into a bitmap, then embed it in a texture provided to moderngl for actual rendering? or will that fall short of handling all the concerns inherent to getting clean text on a display?

Text rendering will never be a part of moderngl. You can of course use any library you want to implement this yourself. This repository is not moderngl, but moderngl-window. it's a windowing and utility library for moderngl.

Making a good text renderer in moderngl would have the same challenges as any other library or language. I did already make a bitmapped text renderer and the plan was at least to use freetype-py to get something started. It would use the (incomplete) texture atlas in the master branch (or a specific variant for glyphs)

@matanox
Copy link

matanox commented Mar 1, 2022

Thanks for commenting and I guess I had missed the most related thread in moderngl which was probably moderngl/moderngl#203.

I guess you mean that perhaps (or at most) moderngl would go one step in the direction of enabling better text rendering performance by implementing a texture atlas, which would allow user code to choose a font library such as freetype-py and throw its outputs into the atlas. And that one can currently, without such a feature added in moderngl, and at the cost of (especially in dynamic scenes) incurring less than optimal performance, cast fonts rendered with other libraries, into a plain moderngl texture if they are okay with having less optimal performance.

And that this all without something like harfbuzz, would probably work in a visually correct, or in a visually pleasing way, only for orthographically feature-poor languages like English and not for many/most other of the world's languages that have character adjoining rules and/or accents that need to be laid out in specific orders from their unicode representations.

Maybe I'm a bit behind on rendering pipelines and architectures though, so I may well suffice with what I learned from your earlier comment.

@lordmauve
Copy link

Just wanted to comment in this thread that to get towards state of the art font rendering you need harfbuzz, sure, but you should be looking towards something like msdf-atlas-gen to generate the atlases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core / important enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants