Please login or register.

Login with username, password and session length

Author Topic: OpenGL 3.3+ Text Renderer  (Read 3755 times)


  • Newbie
  • *
  • Offline Offline
  • Posts: 16
OpenGL 3.3+ Text Renderer
« on: November 11, 2012, 23:33:39 »

In an other Thread people requested I would post/send the source code for a simple text render class/library for openGL 3.3 core and beyond.
My text renderer is able to load and draw characters from bitmap fonts that were generated with this tool:
I did not make that tool, I only use the fonts it can generate.
See below for more info on generating your own fonts.
So here is text renderer in the form of an svn link.

Since visual svn does not support anonymous login by default, I made an account called anon without a password. It has only read access.

Currently the text renderer is part of a framework I'm building. The framework has a lot of bogus code, but nothing of it can't be seen by the public, and the idea of the framework was to be public anyway.
So here is the full framework, including the classes to load fonts, the classes to draw fonts, the shaders, etc. Everything. If you run the project, you instantly should see some text.
It is a netbeans project, so setting it up in netbeans is easy. Eclipse users might need to convert the project.
WARNING: it contains a copy of lwjgl, since I'm to lazy to keep track of LWJGL on different pc's, and all LWJGL projects I make, inherit this project anyway. This means the full project is several hundreds of MB, AND the LWJGL terms and agreement apply, hence, checking this svn out means you accept those. I also uses an audio library. See http://www.paulscode.com/ for more info. As for my own code: just don't call it your own without making significant changes, but feel free to use and/or learn from it.
If you do not want to checkout the project, you can also browse it in your browser, below is a browser friendly link. (No, I'm not gonna eat your pc, you can accept the https certificate).
See below for more info on how to check svn out in netbeans.

The interesting classes are the following:
Loading bitmaps:
Drawing strings:
Keeping text in a box:

I'm currently trying to separate the FontLoader class, which has almost no LWJGL dependancy from the whole framework. Once this is complete. I will post a new svn link to the project with just this class. This class can then be used to obtain the path to a image file and a set of texture coordinates, given a character.

EDIT: I have seperated the FontLoader class from the whole framework. See the first reply on this topic for the svn link.

I assume you have read the readme on the site and are not retarded. So I will keep it short:
After downloading and starting up the tool, you may notice the tool has various settings. My fontloader requires some of them.
1. The .fnt file MUST be in xml format. Since I use an xml parser to parse it. (Font descriptor)
2. I did not test multiple textures yet. It should work, if not, stick to a single texture.
3. openGL does not like texture with width or heights other than powers of two, my FontLoader class will check this.
4. I did not test padding and spacing, they are best left alone, unless you are willing to dive into the code when it goes wrong.
Basically, make sure to use the xml format.

1. Make sure the svn plugin is enabled. Unless you disabled it (hence know how to enable it), it should be enabled.
2. Go to team (top menu bar) -> svn -> checkout. If svn is not there, the svn plugin is disabled.
3. Fill in: url: https://grootmoeders.trolls4life.com.com/svn/Rax  , user: anon
4. leave password, Client cert, and passphrase field empty and press next.
5. Accept the certificate, I did not buy a certificate so it is not signed.
6. All you have to do in this tab is set the local folder. My advice is to NOT take the default project folder, but create a subfolder in the default folder and use that subfolder.
7. Press finish and behold. If you ticked Scan for Netbeans Projects after Checkout, there should be a popup stating a new project is found.


  • Newbie
  • *
  • Offline Offline
  • Posts: 16
Re: OpenGL 3.3+ Text Renderer
« Reply #1 on: November 12, 2012, 00:07:46 »

Separating the FontLoader was easier than expected. Hence, here it is:
Again: user: anon, leave password field blank:

Easy link for your browser:

One last note:
I might not look at this forum very often, if you want a reply, send me a private message, so I will receive an email.


  • Newbie
  • *
  • Offline Offline
  • Posts: 13
Re: OpenGL 3.3+ Text Renderer
« Reply #2 on: November 12, 2012, 17:04:39 »

Nice!! Thanks a lot Rednax!  :)