Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing text on a framebuffer in Linux from C

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?

like image 441
grrussel Avatar asked Dec 08 '09 20:12

grrussel


1 Answers

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.

like image 151
Mark Ransom Avatar answered Nov 08 '22 22:11

Mark Ransom