Jacek_Assalin
Posts: 21
Joined: Tue Jun 16, 2020 8:09 am

Changing the font used for OpenGL|ES

Tue Jun 16, 2020 4:18 pm

Good day,

I was snooping through some of the files used in the hello_pi directory to learn OpenGL for visual purposes on my Pi.
I did this to see if I could change the standard Vera.ttf font into my much preferred Exo 2 font.

The code in file "font.c" states:

Code: Select all

/** The one and only (default) font we support for now.
  */
static struct
{
	const char *file;
	void *mem;
	size_t len
} default_font = { "Vera.ttf" };
Which seems waaaaaaaaaay to changeable!
Does anyone here know if it's possible too change this font?

Thank you for your time!
An answer to my question is great.
An unrelated reference to a place to learn more about how to write (C++) code for the Pi is even better!

User avatar
Paeryn
Posts: 2952
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Changing the font used for OpenGL|ES

Tue Jun 16, 2020 11:22 pm

The only font.c file in the hello_pi directories is the one in /opt/vc/hello_pi/libs/vgfont (I think) and that uses OpenVG to render the fonts, not OpenGL. The code should work for virtually any font, it will only take you a minute to edit the file, recompile and run the example code to find out if your chosen font works.

The way that that file draws the fonts is different than it would be for OpenGL as it relies on OpenVG's concept of paths where each segment isn't necessarily a straight line, they can be arcs, quadratic/cubic curves etc. and the paths are typically filled to get the end result.

OpenGL doesn't provide any of that, instead fonts are usually handled as textures where you draw each glyph onto a texture map and the relevant area for each character is mapped onto a pair of triangles and drawn. Luckily freetype2 will render glyphs for you that you can use to make your texture maps.
She who travels light — forgot something.

Return to “OpenGLES”