Graphics, audio, GUI and retro-computing library for the ESP32, as a native ESP-IDF component
Documentation · Tutorial (PDF) · Screenshots · Examples · Quick start · Migrating from FabGL 1.x
FabGL2 turns an ESP32 into a complete retro-computing and embedded-UI platform: VGA and PAL/NTSC composite video output, PS/2 keyboard and mouse input, a multi-channel sound engine with a polyphonic synthesizer and a drum machine, a windowed graphical user interface, a sprite and game engine, an ANSI/VT terminal and CPU emulators (8080, Z80, 6502, 8086).
FabGL2 is the successor of FabGL 1.x. It is a pure ESP-IDF component, requires ESP-IDF v6.1 or newer and no longer depends on Arduino.
- API documentation and user guide: www.fabglib.org (sources of the guide in docs/guide)
- Tutorial (PDF): FabGL2 Tutorial: installation on macOS, Windows and Linux, a tour of the library and of the examples, complete applications step by step (sources in docs/tutorial, built by
tools/build_tutorial.py) - Migrating from FabGL 1.x: docs/MIGRATION.md
You can support the development by purchasing the ESP32-SBC-FabGL board from Olimex.
All the pictures are taken from the examples included in this repository, running on a TTGO VGA32 board (click a picture to open its example).
![]() FabGL Synth: 8-voice polyphonic synthesizer with resonant filter, arpeggiator and BLE-MIDI |
![]() FabGL Drum: drum machine with 32 step sequencer, song mode and 8 kits |
- Video output
- VGA, with 2, 4, 8, 16 or 64 colors and resolutions up to 1280x768, configurable through Linux-style modelines
- VGA text-only mode (80 columns, 16 colors) with a very small memory footprint
- Direct scanline rendering (VGADirectController) for demanding real-time graphics
- PAL/NTSC color composite video, generated by the internal DAC
- Graphics: lines, rectangles, ellipses, paths, bitmaps, fixed and variable-width fonts, scrolling, double buffering and an unlimited number of sprites with collision detection
- Input: PS/2 keyboard (with international layouts) and PS/2 mouse, handled by the ULP coprocessor
- Audio: multi-channel sound engine with sine, square, triangle, sawtooth and noise generators and sampled sounds, mixed to a mono output through the DAC or sigma-delta modulation, plus a polyphonic synthesizer (ADSR envelope and resonant low-pass filter per voice)
- Graphical user interface: overlapping windows, mouse support and a rich set of controls (buttons, text edits, check boxes, combo boxes, list boxes, sliders, progress bars, knobs, toggle switches, level and led bars, graphs, an on-screen piano keyboard, etc.), plus ready-made InputBox dialogs and a dark theme (
uiDarkTheme) - Terminal: ANSI/VT100 compatible terminal with VT52, ADM-3A, ADM-31, Hazeltine 1500, Osborne I and Kaypro emulations, plus FabGL-specific sequences for graphics, sound and GPIO
- Emulation: Intel 8080, Zilog Z80, MOS 6502 and Intel 8086 CPU cores and several peripheral chips, used by the Altair 8800, VIC-20 and IBM PC examples
- Utilities: serial port, UART stream, I2C, DS3231 real-time clock, MCP23S17 GPIO expander, file browser (SPIFFS and SD card), NVS preferences, WiFi, HTTP, TCP and ICMP helpers
Drawing primitives are queued and executed during the vertical retrace, so no flickering is visible (except when double buffering is used or background drawing is explicitly disabled). If the queue cannot be emptied within one retrace, processing continues at the next one.
FabGL2 runs on ESP32 revision 1 or later (target esp32). See Compatible Boards.
- VGA requires a simple resistor DAC: three 270 Ohm resistors for 8 colors, or six resistors for 64 colors.
- Composite video requires no external components (a 5 MHz low-pass filter may improve the picture).
- PS/2 keyboard and mouse connect to the ESP32 GPIOs; see the schematics of the compatible boards for the interface circuit.
Default pins (as on the TTGO VGA32 board), used by all the examples:
| Signal | GPIO |
|---|---|
| VGA Red (MSB, LSB) | 22, 21 |
| VGA Green (MSB, LSB) | 19, 18 |
| VGA Blue (MSB, LSB) | 5, 4 |
| VGA HSync, VSync | 23, 15 |
| PS/2 port 0 (keyboard) CLK, DATA | 33, 32 |
| PS/2 port 1 (mouse) CLK, DATA | 26, 27 |
| Audio output (DAC) | 25 (23 with composite video, sigma-delta) |
| Composite video output | 25 |
- ESP-IDF v6.1 or newer (tested with v6.1.1)
- ESP32 target
FabGL2 uses only components included in ESP-IDF: no third-party library is required.
components/fabgl/ the FabGL2 ESP-IDF component (CMakeLists.txt, Kconfig, idf_component.yml, src/)
examples/ ESP-IDF example projects (one project per folder)
docs/ Doxygen configuration, migration guide and generated documentation
tools/ font, image and WAV converters, build_examples.sh, clean_examples.sh
Extras/ BASIC programs for the terminal and PC emulator examples
Add the component to your project, for example by cloning this repository and pointing EXTRA_COMPONENT_DIRS to it:
# project CMakeLists.txt
cmake_minimum_required(VERSION 3.22)
set(EXTRA_COMPONENT_DIRS "/path/to/FabGL/components/fabgl")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(myapp)# main/CMakeLists.txt
idf_component_register(SRCS "main.cpp" REQUIRES fabgl)// main/main.cpp
#include "fabgl.h"
fabgl::VGA16Controller DisplayController; // 16 colors, about 153 KB of frame buffer at 640x480
extern "C" void app_main()
{
DisplayController.begin();
DisplayController.setResolution(VGA_640x480_60Hz);
fabgl::Canvas cv(&DisplayController);
cv.clear();
cv.drawText(10, 10, "Hello from FabGL2!");
}Recommended sdkconfig.defaults (every example includes one):
CONFIG_IDF_TARGET="esp32"
CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y
CONFIG_COMPILER_OPTIMIZATION_PERF=y
CONFIG_FREERTOS_HZ=1000
CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192
CONFIG_ESP_MAIN_TASK_AFFINITY_CPU1=y
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1=n
# required by the PS/2 controller (ULP FSM program)
CONFIG_ULP_COPROC_ENABLED=y
CONFIG_ULP_COPROC_TYPE_FSM=y
CONFIG_ULP_COPROC_RESERVE_MEM=4096
The PS/2 controller runs a program on the ULP FSM coprocessor, so CONFIG_ULP_COPROC_RESERVE_MEM must be at least 2112 bytes. The build stops with an explicit error message if it is smaller.
Every folder under examples/ that contains an sdkconfig.defaults file is a standalone ESP-IDF project:
. $IDF_PATH/export.sh
cd examples/VGA/SpaceInvaders
idf.py build flash monitor
To build an example copied outside this repository, set the FABGL_PATH environment variable to the root of the repository.
To build several examples at once:
tools/build_examples.sh # all examples
tools/build_examples.sh VGA/ # VGA examples only
To remove all the files generated by the builds (build/, sdkconfig, ...), for example after changing an
sdkconfig.defaults file:
tools/clean_examples.sh # all examples (-k keeps sdkconfig, -n shows what would be removed)
tools/clean_examples.sh VGA/ # VGA examples only
Every example has its own README with the purpose of the demo, what it demonstrates, the required hardware and how to use it (commands, keys, disk images...):
| Example | Description |
|---|---|
| Altair8800 | Altair 8800 emulator (i8080/Z80) running CP/M 1.4, 2.2, 3, Altair BASIC and DOS from the included disk images |
| AnsiTerminal | Serial VT/ANSI terminal with on-screen configuration (emulations, fonts, resolutions, serial parameters) |
| Audio | Multi-channel sound mixer GUI (dark theme): waveform generators and sampled sounds |
| ClassicRacer | Two-player retro racing game (keyboard, mouse or joystick) |
| CollisionDetection | Sprites and pixel-precise collision detection with Scene |
| DirectVGA | Minimal direct scanline rendering with VGADirectController |
| DirectVGA_ElMuro | Brick-breaker game rendered line by line with VGADirectController |
| DoubleBuffer | Double-buffered animation benchmark (balls, polygons, sprites, FPS) |
| DrumMachine | Sample based drum machine in the LinnDrum / LM Drum style: 16 instruments, faders, 32 step sequencer, song mode, 32 patterns, 8 kits (acoustic, TR-808, TR-909, CR-78, LM-1, LM-2, DMX style), user WAV sounds from SD card |
| FileBrowser | File manager for SPIFFS and SD card (dark theme), with WiFi setup and HTTP/HTTPS downloads |
| GraphicalUserInterface | Tour of the GUI with a modern dark flat theme: windows, all the controls (knobs, switches, graph, piano...), dialogs, timers |
| HardwareTest | Board test (dark theme): colors, keyboard, sound, SD card, GPIOs, MCP23S17, WiFi |
| InputBox | Ready-made dialogs: messages, menus, text input, progress bars, file selector, WiFi wizard |
| LoopbackTerminal | Terminal connected to itself, to try the escape sequences from the keyboard |
| ModelineStudio | Find and tune VGA modelines from the serial console |
| MouseOnScreen | Mouse pointer, cursor shapes and drawing with the mouse |
| MultitaskingCPM | Up to 12 concurrent CP/M 3 compatible Z80 sessions, with WiFi, telnet and ping |
| NetworkTerminal | WiFi command shell with telnet client, ping and network scan |
| PCEmulator | IBM PC/XT emulator (8086, CGA/Hercules) running DOS, Windows 3.0, ELKS, GEM... (requires PSRAM and SD card) |
| SimpleTerminalOut | Terminal output showcase: colors, styles, graphics, animations |
| SimpleTextTerminalOut | The same showcase with the text-only VGA controller |
| Songs | Songs written as text strings, played with a software ADSR sound chip |
| SoundChipSimulator | Catalog of retro sound effects (ADSR envelope + frequency sweep) |
| SpaceInvaders | Arcade shoot-'em-up game with sprites and sampled sounds |
| Sprites | The simplest sprite example, with the supported bitmap formats |
| Synth | 8-voice polyphonic synthesizer with ADSR, resonant ladder filter (with envelope), LFO, arpeggiator with latch and 64 presets, played from the PS/2 keyboard or a Bluetooth MIDI keyboard |
| TerminalCharSet | Shows the terminal character set with codes |
| VIC20 | Commodore VIC-20 emulator with included games, cartridges and Internet downloads |
| Example | Description |
|---|---|
| BaseExample | PAL/NTSC composite video test screen with mode selection |
| Example | Description |
|---|---|
| KeyboardScanCodes | Shows the raw PS/2 keyboard scancodes |
| KeyboardVirtualKeys | Shows the virtual keys and ASCII codes generated by the keyboard, for each layout |
| MouseStudio | PS/2 mouse diagnostics on the serial console |
The documentation (API reference, User Guide and one page per example) is generated with
Doxygen, Graphviz and Python 3 (on macOS: brew install doxygen graphviz):
tools/build_docs.sh # regenerate docs/html (fails on Doxygen warnings)
tools/build_docs.sh -z # also create build_docs/fabgl-docs-<version>.zip
tools/build_docs.sh -s # then preview it on http://localhost:8000
The content of docs/html is the www.fabglib.org site.
The tutorial PDF (docs/tutorial/FabGL2_Tutorial.pdf, copied into the site by Doxygen) is generated from the HTML
chapters in docs/tutorial/src with Google Chrome and poppler (on macOS: brew install poppler imagemagick):
tools/build_tutorial.py # run it before tools/build_docs.sh
Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - http://www.fabgl.com
Copyright (c) 2019-2026 Fabrizio Di Vittorio. All rights reserved.
FabGL2 is released under the GNU General Public License v3 (GPL v3). For a commercial license, please contact fdivitto2013@gmail.com.
Please do not remove the copyright notice or the name of the original author from the FabGL examples (e.g. from screens and dialogs), including in derived works based on the examples.













