views:

633

answers:

3

How can a program draw text on a frame buffer mapped in as an array? What is needed is both a means of representing the individual characters, and of drawing the characters pixel by pixel in a manner that is not too inefficient. The representation of the characters should ideally be defined solely in code, and no third party libraries would be required.

Does anyone know of code to do this available under a liberal license? Or a tool to generate data definitions for the font for use in program code e.g. the array of bitmap glyph/character values?

A: 

To draw a line on a 2D array, use the Besengam's algorithm.

To draw the characters using straight lines , build your alphabet using a series of moveTo, lineTo. E.g. for a simple 'L':

image.moveTo(0,-fontHeight);
image.lineTo(0, 0);
image.lineTo(fontWidth,0);
Pierre
+1  A: 

I think the best way to do it is using bitmap fonts: http://www.iua.upf.es/~ggeiger/redbookhtml/ch09.html. This tutorial is for OpenGL but you probably find a lot of useful info.

Maciek Sawicki
+2  A: 

I don't have any information specific to frame buffers, but I do have an interesting way of encoding a font.

If you have an application that can write to the XBM format, you can encode a font just by creating an image containing all the characters. The XBM file can be included as a C or C++ file, and by using the proper offsets you can easily access a single character. Make sure each character starts at an X-coordinate divisible by 8, because the image is coded as one bit per pixel; anything that doesn't line up on an 8-bit boundary will need masking and shifting.

Mark Ransom