Writing Characters Straight To The Linux Framebuffer

These days, working with a display in software is fairly easy. Thanks to the convenience of the modern OS, we’re blessed with graphical user interfaces, where things such as buttons and windows and text are all taken care of for us. Of course, once you start to wander off the beaten track, particularly in embedded systems with no GUI, things can get a little more difficult. For these situations, [JSBattista] wrote some code to blast text directly to the Linux framebuffer.

It’s a project borne out of necessity. Working with a Raspberry Pi with no X server, it was found that the console text size made it difficult to display data. By writing directly to the framebuffer, it would be possible to display text of a larger size without having to implement a full GUI, and overheads could be kept to a minimum.

Working in this manner comes with some limitations. Glyphs are taken from an array in bitmap format, rather than font files. In this case, a font akin to that of the Alien sentry gun interface was chosen, for an attractive sci-fi look. Lowercase characters are currently unimplemented. Testing thus far has been on Raspberry Pi and Beaglebone non-GUI systems, with performance varying depending on platform.

It’s a project we suspect might prove useful to the developers of lightweight embedded systems. It’s something that may take some tweaking and experimentation to implement, but the hacker set rarely shy away from a challenge. If you’re eager to get down and dirty with some heavy programming, this tutorial on Linux graphics will help.

15 thoughts on “Writing Characters Straight To The Linux Framebuffer

  1. One can change the console font and size you know. If you’re mostly just displaying text that’s gonna be a way easier way to accomplish this. Did this once to get more readability on an old green phosphor CRT. But then again maybe they want some more specific additional features.

  2. Reminds me a bit of getting images on a 320×200 VGA display in DOS by, defining a 8-bit palette and then writing 64000 bytes to memory starting at 0xA0000000.

    And there was also a neat trick where you could borrow the bit patterns for fonts from the BIOS, using the address pointed to for interrupt vector 0x1F in MSDOS (A pointer to the VGCT (Video Graphics Character Table), which contains the data for ASCII characters 0x80 to 0xFF).

  3. If you aim for performance, keep in mind that the frame buffer is uncached. Sometimes it is faster to compose the image in cached ram and use an optimized memcpy equivalent to copy the final picture.

  4. Those letter glyphs look to be very memory inefficient maybe make it a list of x,y points instead?
    Then you draw a line between them
    [0] = {1,2,1,6,2,7,3,7,4,6,4,2,3,1,2,1,1,2}
    [1] = {3,1,3,7}
    [2] = {1,1,3,1,4,2,4,3,3,4,1,5,1,7,4,7}

    This also makes scaling the x & y trivial — by simple multiplication or even by percentage

  5. Fun fact- the sentry gun scene only actually appears in the Director’s Cut of Aliens, but most of us know it because that’s the version most of us have seen (likely due to the popularity of that VHS/DVD version). It’s my favorite scene in the film, so I’m amazed it was ever cut from any release.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.