3D font renderer based on QFont, OpenGL and GLU.
Author: Marcel Goldschen-Ohm
Email: marcel.goldschen@gmail.com
This code is based largely on stuff I found online which I merely tweeked, so most of the credit does not belong with me. If you are or know the original author, let me know and I'll be happy to give you/them kudos here.
Everything is in:
QtFont3D.h
QtFont3D.cpp
See CMakeLists.txt
for example build as a static library.
👉 This is most likely what you want: See test/CMakeLists.txt
for example build of an app that uses QtFont3D. This build uses CMake to automatically download QtFont3D files directly from this GitHub repository, builds QtFont3D as a static library and links it to the app executable. This way you can use QtFont3D in your project without downloading or managing the QtFont3D repository manually.
- Qt
- OpenGL
- GLU
#include "QtFont3D.h"
QtFont3D textRenderer;
setFont(...)
.
float glyphWidth = 3;
int numGlyphs = 256;
QFont font = QFont("Sans", 20, QFont::Normal);
textRenderer.setFont(font, glyphWidth, numGlyphs);
Render 3D text in an OpenGL scene using print(...)
. Text color is the current OpenGL color.
textRenderer.print("Hello World!");
Optional position, text alignment and scaling.
QString text = "Hello World!";
// Offset text in y.
QVector3D position(0, 1, 0);
// Center text horizontally and vertically about position.
int align = Qt::AlignHCenter | Qt::AlignVCenter;
// Scale text x2.
float scale = 2;
textRenderer.print(text, position, align, scale);
See test.h/cpp
for an example where 3D text is rendered within a QOpenGLWidget.
- Remove dependence on GLU.