Language: EN


UnifiedGFX Library

The UnifiedGFX library allows you to develop your projects independently of the hardware used.

There are many types of MCUs and screens, and many very good libraries to manage them. But I don’t want my project to depend on a specific type of hardware, I want it to work on any of them.

Ideally, the goal is for most of my project to work the same on an M5Stick with TFT, on an ESP8266 with an OLED screen, or even on an RGB LED or WS2812b matrix.

However, this portability comes with a (small) performance cost. If you are looking for maximum performance, this library is probably not for you.

Personally, most of the time I don’t mind having 30.48 fps or 29.83, compared to the advantage of being independent of the hardware.

How to use UGFX

UnifiedGFX incorporates abstract classes such as IBitmap, IReadableBitmap, or IGraphic.

On the other hand, the Graphicclass implements almost all the functions of IGraphicusing only the functions of IBitmap, Height(), Width(), and drawPixel().

In this way, in your project, for example, your drawing function would look like this,

void draw(UGFX::IGraphic<uint16_t>& screen, uint16_t background, uint16_t color)

Adapting to your hardware

By design, UnfiedGFX knows nothing about hardware and drivers, it is a higher layer of abstraction. To use it in the specific hardware of your project you can do two things,

  • Use an adapter pattern
  • Modify the graphic libraries of your hardware to implement IGraphic

An example of how to implement in your Graphicclasses is shown in the ‘Generic’ example.

On the other hand, adapters and examples of their use are provided for the AdagruitGFX, eTFT, and LGVX libraries.


The functions in the adapters are decorated with the ‘always_inline’ attribute, so the performance should be similar to using them directly.

Performance will be even better if you modify the libraries of your hardware to implement the abstract classes of UnifiedGFX.

On the other hand, the actual performance obtained will depend on how well the adapter takes advantage of the hardware features.

The minimum necessary for UnifiedGFX to work are the functions of IBitmap, Height(), Width(), and drawPixel(). With this, you would get the minimum possible performance.

If the adapter overrides more functions of Graphic, and maps them to the hardware library, the performance will improve substantially.

This is especially important in functions that perform block operations, which are much faster than performing the operation pixel by pixel. Normally these functions are drawHorizontalLine, drawVerticalLine, or fillRect.

Download the code

All the code is available for download on Github at this link github-full