Skip to content

marcel-goldschen-ohm/QtFont3D

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QtFont3D

3D font renderer based on QFont, OpenGL and GLU.

Author: Marcel Goldschen-Ohm
Email: marcel.goldschen@gmail.com

Disclaimer

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.

INSTALL

Everything is in:

  • QtFont3D.h
  • QtFont3D.cpp

CMake:

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.

Requires:

  • Qt
  • OpenGL
    • GLU

Usage

#include "QtFont3D.h"
QtFont3D textRenderer;

⚠️ Make sure you have a valid OpenGL context before building the font display list using 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);

Example

See test.h/cpp for an example where 3D text is rendered within a QOpenGLWidget.

TODO

  • Remove dependence on GLU.

About

3D font renderer based on QFont, OpenGL and GLU.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages