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

Raspberry 3 opengl programming and fonts

Tue Dec 06, 2016 2:50 pm

Hello !

I have been using Qt to make openGL ES applications on the Pi, but found that I could not easily use scalable/rotatable fonts with opengles. On PCs, I have used freetype fonts which do the trick with standrad OpenGL (not GL-ES). I know there is a "port" of freetype fonts (freetypeGlesRpi), but never could make it work.
Now that Pi 2&3 have a "full" openGL driver, is ti possible to make "standard" openGL programming on the Pi 3, using freetype fonts, and what would be the way to go (cross compilation with Qt ?).
Regarding cross-compilation with QT, there are many good tutorials, but they all deal with OpenGLES.

regards
Oliver

User avatar
topguy
Posts: 5624
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Raspberry 3 opengl programming and fonts

Tue Dec 06, 2016 3:52 pm

Qt5 with OpenGL is already installable in raspbian. ( Qt 5.3 I believe )

- Enable experimental OpenGL X-server
- Copy code over to Pi ( or preferably use some source-code versioning system like git )
- Run "qmake" and "make" to build your app.

It should be a rather large project before it would be beneficial to mess around with cross-compiling.
At least test the short path first.

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

Re: Raspberry 3 opengl programming and fonts

Wed Dec 07, 2016 7:31 am

Hi topguy !

tusen tak for the fast answer !

It is a very good advice to test the short test path first. In the end, it's quite a large software, so cross-compilation would mean some comfort.

Oliver

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

Re: Raspberry 3 opengl programming and fonts

Wed Dec 07, 2016 7:41 am

Hello again,

I have found a tuto to build Qt on the Pi : https://wiki.qt.io/Native_Build_of_Qt_5 ... spberry_Pi
and I'm wondering about the step below :

Code: Select all

./configure -v -opengl es2 -tslib -force-pkg-config -device linux-rasp-pi-g++ -device-option CROSS_COMPILE=/usr/bin/ \
 -opensource -confirm-license -optimized-qmake -reduce-exports -release -qt-pcre -make libs \
 -prefix /usr/local/qt5 2>&1 | tee config.out
It includes "-opengl es2", and I want to use normal, windowed openGL, with the new OpenGL pi driver. Should I change this statement and how ?


best regards

User avatar
topguy
Posts: 5624
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Raspberry 3 opengl programming and fonts

Wed Dec 07, 2016 12:27 pm

But why do you want to build a new Qt5 on the Pi ?
Can't you at least test with the Qt5 version that you can install from the Raspbian repositories ?

User avatar
topguy
Posts: 5624
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Raspberry 3 opengl programming and fonts

Wed Dec 07, 2016 2:43 pm

Lets reverse this discussion a bit.
You said that you had a problem with scaling/rotating fonts under OpenGLES.
I have used QML with Qt5/glesfs a little bit and didn't notice that this was a problem, can we avoid all this extra work by fixing your original problem.

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

Re: Raspberry 3 opengl programming and fonts

Wed Dec 07, 2016 3:32 pm

Hello again !

I understand from your answer that Qt5 is already installed on the pi or at least it is possible to install it from the repo. I didn't catch that previously ...
For sure I have a big bunch of code already working on OpenGLES which I wouldn't love to rewrite, so if I can get the fonts to behave properly (mainly rotate them), I'll be happy. I have done a few searches on glesfs and Qt5/glesfs, and found nothing readable or useful. Also I'm not using qml but plain c++ programming. Can you elaborate a bit on glesfs ?

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

Re: Raspberry 3 opengl programming and fonts

Thu Dec 22, 2016 12:03 pm

So ...
Any hint ?
How could I print some text along with my OpenGL drawing. I have searched for GLESFS, not a single answer, I have tried to compile FTGLES on the pi, but when compiling an app, the linker complains about some function he can't find in the libftgles library. Many efforts, no result ...

ideas welcome ...

raysan5
Posts: 37
Joined: Tue Sep 30, 2014 4:44 pm
Location: Barcelona
Contact: Website

Re: Raspberry 3 opengl programming and fonts

Thu Dec 22, 2016 1:32 pm

Hi oliver_mpt,

To render fonts on OpenGL you have to create a texture containing all the glyphs required (texture atlas) and, at least, the position information of every glyph in the texture (position-size coordinates). When you draw text, actually, you draw multiple quads with the required texture coordinates using the font texture atlas. It requires some code, not only to generate the texture atlas from the TTF font but also to manage and render every required quad for a given text string.

As a simpler solution, you can consider using raylib (www.raylib.com) that already manages all that for you... or just check raylib source code (https://github.com/raysan5/raylib/blob/ ... src/text.c). If you check the examples section in raylib webpage, there are multiple text related code examples: http://www.raylib.com/examples.htm

Hope it works for you! :D

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

Re: Raspberry 3 opengl programming and fonts

Sat Dec 31, 2016 4:39 pm

First, thanks to RaySan5 for his explanations and samples from his nice work. I have found that the principle used by raysan5 was the same as for the "freetypeGlesRpi" library I had mentionned in my first post, making a texture atlas for all the glyphs and display textures with openGL.
The problem 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 ...
Have a happy new year !

Return to “OpenGLES”