Example: drawing text using texture map

Started by napier, September 15, 2004, 03:20:32

Previous topic - Next topic

napier

I've seen a few posts about drawing text in LWJGL and it seems to cause some confusion or at least reluctance.  For anyone who's interested, I wrapped some of the code from the NeHe 2D Texture Font tutorial to make it easier to get going with text.  

Sample code is here:

   http://potatoland.com/code/gl

The "Drawing Text" demo uses two functions to build a character set and render some text:

       buildFont("images/font_tahoma.png", 12);

	...

        glPrint(10,  740, 0, "Text rendered over 3D scene");

This uses the .9 LWJGL libe.  Tested on Win32 only.  If you find bugs or think of something that should be added, let me know.
penGL/Java/LWJGL demos and code: http://potatoland.org/code/gl

Matzon

Excellent stuff!

hmm, I am |-| this close to adding a cropped version of your font code to the utils package (and a font demo). A lot of people get quite annoyed when they discover the "work" involved in rendering text in opengl.

What say you other forum lurkers?

garazdawi

@napier: Have you thought about updating the code so that it can be used with lwjgl 0.92? and then maybe adding it to the wiki would be a good idea so that people can find it more easily (I can do this for you if you want me to...)
 put the 'laughter' back in 'slaughter'
The LWJGL Wiki Documenation

napier

QuoteMatzon said:
hmm, I am |-| this close to adding a cropped version of your font code to the utils package

I think LWJGL would benefit from a text rendering util and probably a few others as well (ie. image handling). It can't hurt to have some code available for those who don't want to roll their own.  

BUT utils should be loosely coupled to the main libe, to prevent bloat. In the short run size may not matter but if Utils grows to include many convenience functions it could add weight to the otherwise "lightweight" library.  Taking a cue from the gl, glu, glut approach, should Utils be a separate libe that can grow somewhat independently from the main lwjgl.jar?

A side note about tutorials:
Tutorials/demos are helpful, but usually the code is not very useable.  Most tutorial code is written to explain a technique, not to package it for easy reuse.  That's why I wrote GLApp: I packaged the intricacies of ByteBuffers, images, cursors, text, etc. so I don't have to think about it again.  For me, a good util class is worth a dozen tutorials.
penGL/Java/LWJGL demos and code: http://potatoland.org/code/gl

napier

garazdawi said:

QuoteHave you thought about updating the code so that it can be used with lwjgl 0.92?

I just converted it from .8 to .9  :shock:   Makes sense to keep it current, though, so I'll give it a spin in .92 and see what breaks.   If you could put it into the wiki after that I'd appreciate it.
penGL/Java/LWJGL demos and code: http://potatoland.org/code/gl