----------------------------------------------------------------------------- - ATOFont - Another Textured OpenGL (tm) Font - - written by ville helin in 2003-2004 - ----------------------------------------------------------------------------- this is LGPL software. please read the file LICENSE for further instructions. 0. HISTORY v2.1 (01-sep-2004) * optimized atofont_set_type(). * optimized all text writing functions. v2.0 (08-feb-2004) * ATOFONT header files should now work in C++ projects. * enhanced the example. * added string objects and string buffers. * modularized the api. * renamed atofont_write_string_* to atofont_string_write_*. * string centering is now given via arguments. v1.1 (28-jan-2004) * code cleanups. * small optimizations. * enhanced the example. v1.0 (14-jan-2004) * the first public release. 1. BACKGROUND at some point in time, when working with handheld devices, the font functions GLUT offered proved to be too massive. so i decided to write a very simple 3D vector text system using OpenGL myself. that was VSOFONT. after six months of coding i got bored to those very simple vector fonts, and decided to move to texture fonts. ATOFONT was born. 2. CREATING A NEW FONT ATOFONT doesn't help you here. you'll have to create a texture, which contains all the characters of the ASCII mapping. e.g., check out bitmap font builder: http://www.lmnopc.com/bitmapfontbuilder/ the characters have to be inside tiles of x*x pixels, so make sure every character stays inside its box. for tweaking, i recommend tile driller: http://www.iki.fi/~vhelin/tiledriller.html also note that the texture must be in RGBA format. 3. USING ATOFONT first of all you need to load a texture containing the font. this you'll have to do yourself. check out the example for more help. next you can create a font object: atofont_create(&examplefont, texture_data, GL_RGBA, tx, ty, cx, cy); here tx and ty are the texture dimensions in pixels, and cx and cy are the character dimensions in pixels. all fonts are fixed width fonts by default. but if the one we just created is actually a proportional font, then give: atofont_set_type(examplefont, ATOFONT_TYPE_PROPORTIONAL); or adjust the scaling of the font: atofont_set_scaling(examplefont, 0.1, 0.1); or change the letter spacing: atofont_set_spacing(examplefont, 0.3); or draw strings with it. remember that before drawing any strings vertex arrays and texture coord arrays have to be enabled (see the example directory for an example of the real usage). also remember to enable blending and set the correct blending function... there are three ways to draw strings. first of all, you can plot them one character at a time (saves memory): atofont_string_write_billboard(examplefont, "Hello World!", 10, 20, 30, ATOFONT_CENTERED); atofont_string_write_billboard(examplefont, "Hello World!", 10, 20, 30, 0); atofont_string_write_2D(examplefont, "Hello World!", 10, 20, ATOFONT_CENTERED); atofont_string_write_2D(examplefont, "Hello World!", 10, 20, 0); or you can precompute the string into a 2D object (an array of triangles) using atofont_string_object_create(examplefont, "Precompute me!", &stringobject); and after this draw the object the way you plot strings directly: atofont_string_object_write_billboard(examplefont, stringobject, 10, 20, 30, ATOFONT_CENTERED); atofont_string_object_write_billboard(examplefont, stringobject, 10, 20, 30, 0); atofont_string_object_write_2D(examplefont, stringobject, 10, 20, ATOFONT_CENTERED); atofont_string_object_write_2D(examplefont, stringobject, 10, 20, 0); or you can still plot the strings, but buffering the characters and executing only one glDrawArrays() / string (takes memory and doesn't use triangle strips, but plain triangles, like string object writing): atofont_string_buffer_write_billboard(examplefont, "Hello World!", 10, 20, 30, ATOFONT_CENTERED); atofont_string_buffer_write_billboard(examplefont, "Hello World!", 10, 20, 30, 0); atofont_string_buffer_write_2D(examplefont, "Hello World!", 10, 20, ATOFONT_CENTERED); atofont_string_buffer_write_2D(examplefont, "Hello World!", 10, 20, 0); at the exit you might want to free the fonts: atofont_free(examplefont); and perhaps any stringobjects you've created: atofont_string_object_free(stringobject); note that freeing a font doesn't free the texture. also make sure you don't free the texture before freeing the font. 4. THINGS TO NOTE ATOFONT consists of four files: * atofont_core.c - the core functions * atofont_s.c - string drawing functions (direct drawing) * atofont_sb.c - buffered string drawing * atofont_so.c - string object functions you'll have to include atofont_core.c in your project, but atofont_s.c, atofont_sb.c and atofont_so.c are all optional (better use at least one of them). also note that when you create a string object, the spacing, scaling and the font type are embedded into the string object. use atofont_string_object_recreate(examplefont, "Precompute me!", &stringobject); to update the string object. 5. CONTACT send me email (vhelin#iki.fi) if you want to submit suggestions, bug reports, and cool fonts. ;) ATOFONT's homepage: http://www.iki.fi/~vhelin/atofont.html 6. WARNINGS ATOFONT is constantly evolving so don't be surprised if the latest version isn't compatible with the previous. 7. LEGAL STUFF ATOFONT is under LGPL. you use ATOFONT at your risk. i take no responsibility for anything.