Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tlabaltoh/opengl_sdf_font_rendering

Tiny example of rendering font (.ttf, .otf) as SDF using OpenGL
https://github.com/tlabaltoh/opengl_sdf_font_rendering

fonttools opengl otf python sdf ttf

Last synced: about 1 month ago
JSON representation

Tiny example of rendering font (.ttf, .otf) as SDF using OpenGL

Awesome Lists containing this project

README

        

# opengl_sdf_font_rendering
Tiny example of rendering font (```.ttf```, ```.otf```) as SDF using OpenGL

## Overview
In this example, the approach is to [detect the edge path](https://github.com/fonttools/fonttools/blob/main/Lib/fontTools/ttLib/removeOverlaps.py) of the font and [fill by distance](https://www.shadertoy.com/view/dls3Wr).











BLUR: 100, EXPAND: 50


BLUR: 0, EXPAND: 0

```glsl
// shader code: ./shaders/font.frag

#define BLUR (...)
#define EXPAND (...)

// (get distance from shape ...)

// (render with distance ...)
dist *= winding;
float delta = fwidth(dist) * 0.5;
float alpha = 1-saturate(-delta + EXPAND - BLUR, delta + EXPAND, dist);
out_color = vec4(alpha, alpha, alpha, alpha);
```

## Operating Environment
| | |
| ------ | -------- |
| OS | Windows |
| Python | 3.11 |
| IDE | anaconda |

## Dependencies
- [PyOpenGL](https://pypi.org/project/PyOpenGL/)
- [glfw](https://pypi.org/project/glfw/)
- [matplotlib](https://pypi.org/project/matplotlib/)
- [numpy](https://pypi.org/project/numpy/)
- [fonttools](https://pypi.org/project/fonttools/)
- [skia-pathops](https://pypi.org/project/skia-pathops/)

## Getting started
- Clone the repository with the following command
```cmd
git clone https://github.com/TLabAltoh/opengl_sdf_font_rendering.git
```
- Run ```main.py``` with the following command
```cmd
cd opengl_sdf_font_rendering

python main.py %{FONT_PATH} %{CHAR} %{FONT_SIZE}
@rem ex. python main.py font.ttf A 35
```

## TODO
Use the dictionarized glyph buffer on the shader side to reduce the size of the gl compute buffer.