User avatar
hexelpdkk
Posts: 177
Joined: Fri Feb 24, 2012 4:40 pm

Font handling on OpenGLES

Sun Oct 28, 2012 8:18 pm

I've been a bit unimpressed so far with the font handling routines available to us in gles on the pi. I am about to try to hack freetype-gl to make it work on the pi. This library works by rendering a font into a "font atlas", providing one texture that can then be used to render text from. It uses freetype to create the glyphs, so any true type font (for example) can be used, will only use a single texture to store the glyphs, and supports nice things like "kerning".

Before I lose myself in this, has anyone else got a better alternative?

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5502
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Font handling on OpenGLES

Sun Oct 28, 2012 8:53 pm

Have you looked at the "hello_font" example in /opt/vc/src/hello_pi?
That uses openVG for font rendering.

User avatar
hexelpdkk
Posts: 177
Joined: Fri Feb 24, 2012 4:40 pm

Re: Font handling on OpenGLES

Mon Oct 29, 2012 8:10 pm

Is there any way of mixing openvg and opengles? From what I've seen, I can only use one or the other.

dom
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5502
Joined: Wed Aug 17, 2011 7:41 pm
Location: Cambridge

Re: Font handling on OpenGLES

Mon Oct 29, 2012 8:18 pm

hexelpdkk wrote:Is there any way of mixing openvg and opengles? From what I've seen, I can only use one or the other.
They don't mix (as in share a render buffer). You can add both an opengles render surface to the display and an OpenVG render surface to the display.

You add them both as separate dispmanx layers, and one has to be in front of the other (presumably with alpha).

It's quite an expensive solution, as each render surface is by default triple buffered (e.g. 8MB x 3 for 1080p, or 48M in total).

You may want to look at xbmc source code. That uses openGLES to render fonts (I beleive using texture atlas generated from freetype).
Currently the font rendering in xbmc is quite expensive, so there may be a better solution.

User avatar
ArborealSeer
Posts: 300
Joined: Tue Jan 24, 2012 9:48 am
Location: South West, UK

Re: Font handling on OpenGLES

Mon Feb 25, 2013 2:35 pm

Not been active here much, but i've recently done some OpenGL ES text rendering 'system font' style using the headers output from the pixel font creator tool ( http://www.min.at/prinz/software/pixelfont/ )

being pixel based its chunky, but good enough for some simple things like FPS counters and on screen debug etc

btw. not got my stuff running on a Pi yet, this was on a desktop using AMDs native windows OpenGL ES implementation.
Pi Status > Farnell, Arrived 24/5- RS, Arrived 1/6

User avatar
hexelpdkk
Posts: 177
Joined: Fri Feb 24, 2012 4:40 pm

Re: Font handling on OpenGLES

Tue Mar 12, 2013 7:39 am

I've restarted work on this, using the simpler parts of freetype-gl http://code.google.com/p/freetype-gl/, and also making use of https://github.com/chriscamacho/gles2framework to provide the opengl environment (change the makefile to switch between standard desktop linux, pi under x or pi without x)

Current progress can be seen at https://github.com/PDKK/freetypeGlesRpi. It is basically usable already, but needs a bit of tidying to make it easy to use.

Comments, improvements and pull requests are welcome.

oliver_mpt
Posts: 14
Joined: Tue Dec 06, 2016 2:41 pm

Re: Font handling on OpenGLES

Thu Dec 22, 2016 11:49 am

Hi !

I have dowloaded the project and tried to embed it in a qt openGLES project. The example supplied is way too long and complicated, I can't make use of it. I have a surface in which I can successfully draw using standard openGL commands, like glDrawArrays and so on. Can you enlighten me on two points :

- Is freetypeGlesRpi appropriate to draw and ROTATE fonts in such context ?
- could you just outline the procedure to use it, like

Code: Select all

 
    m_atlas = texture_atlas_new( 512, 512, 1 );
    m_font = texture_font_new( m_atlas, "./arial.ttf", 16 );
    texture_font_load_glyphs( m_font, L" !\"#$%&'()*+,-./0123456789:;<=>?"
                  L"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
                  L"`abcdefghijklmnopqrstuvwxyz{|}~");
    texture_atlas_upload(m_atlas);
Then what ? how to draw a given text at a given position. I'm not making use of any shaders ...

Any help welcome, thanks !

oliver_mpt
Posts: 14
Joined: Tue Dec 06, 2016 2:41 pm

Re: Font handling on OpenGLES

Sat Dec 31, 2016 4:44 pm

OK, I solved my problem :
The trouble I had, in fact was that the "freetypeGlesRpi" is written to be used with "modern" openGL (using shaders) while I knew only "legacy" openGL. OpenGLES is compatible with legacy OpenGL in 1.1, but has to use shaders and modern approach in version 2.0 and above. I made the effort to learn the basics of modern OpenGL, and could rapidly transform my code. Then, the sample (test.c) with "freetypeGlesRpi" allowed me to understand how to use it.

It's perfectly suited to display ttf fonts and rotate them, change colors and do any useful font operation, mixed with the display of models and primitives.
That solves my problem ...

Happy new year !

Return to “OpenGLES”