A small 2D engine written in C++ using Allegro 5. The project contains a simple renderer, input handling and a minimal scene with shapes (line, rectangle, circle).
This README explains how to build and run the project on macOS / Linux and Windows, how to install dependencies, and how to troubleshoot common issues (Allegro main shim, duplicate windows, runtime crashes).
Table of contents
- Description
- Requirements
- Build (macOS / Linux)
- Build (Windows with vcpkg)
- Makefile quick build
- Troubleshooting
- CMake presets example
- License
The engine demonstrates a basic structure for a software renderer and uses Allegro 5 for the display, input and some primitives. Source code is under src/, headers are under include/engine.
- A C++17-capable compiler (clang, gcc or MSVC)
- CMake >= 3.15 (recommended)
- Allegro 5 (primitives, image, font, ttf, audio, acodec)
- pkg-config (on macOS / Linux)
- On Windows: vcpkg is recommended for dependency management
Recommended approach: CMake
- Install dependencies (macOS Homebrew example):
brew install pkg-config
brew install allegroOn Linux (Debian/Ubuntu) you can install development packages if available:
sudo apt update
sudo apt install build-essential cmake pkg-config liballegro5-dev- Configure and build:
cmake -S . -B build
cmake --build build --config Release- Run the binary:
./build/engine2dIf you prefer a fast local workflow, a Makefile is provided which uses pkg-config to obtain Allegro flags.
make
./bin/engine2dRecommended: use vcpkg to install Allegro and let CMake pick it up via the vcpkg toolchain file.
- Install and bootstrap vcpkg:
git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat
.\vcpkg.exe integrate install
.\vcpkg.exe install allegro:x64-windows- Configure and build from the project root:
cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=C:/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake -A x64
cmake --build build --config Release
.-
Duplicate windows (two displays open)
- Cause:
al_create_displayis called more than once. In this projectEnginecreates the display in its constructor (src/engine/engine.cpp). Do not callal_create_displayagain frommain.cppor other modules. Keep a single owner of the display.
- Cause:
-
dyld / symbol not found:
__al_mangled_main(macOS)- Explanation: Allegro provides a shim
allegro_mainthat remapsmainto a different symbol. If the shim isn't linked or the remapping conflicts, macOS can fail with a missing symbol. - Fixes:
-
Define
ALLEGRO_NO_MAGIC_MAINbefore including Allegro headers to disable the magic remapping:#define ALLEGRO_NO_MAGIC_MAIN #include <allegro5/allegro.h>
-
Or ensure you link
allegro_main(pkg-config / CMake may provide it asallegro_main-5). In the cross-platform CMake we added an optionALLEGRO_NO_MAGIC_MAINso you can choose.
-
- Explanation: Allegro provides a shim
-
Program crashes with
trace trapor immediate abort- Collect a backtrace with
lldborgdbto find where the crash happens. On macOS:
lldb -- ./build/engine2d (lldb) run (lldb) bt
- Collect a backtrace with
-
Missing Allegro headers at compile time
- Ensure Allegro is installed and pkg-config can find it. On macOS Homebrew installs Allegro and its pkg-config files to
/opt/homebrewor/usr/local. Confirmpkg-config --cflags allegro-5prints include paths.
- Ensure Allegro is installed and pkg-config can find it. On macOS Homebrew installs Allegro and its pkg-config files to
You can create CMakePresets.json to simplify builds. Minimal example:
{
"version": 3,
"configurePresets": [
{ "name": "mac-clang", "generator": "Unix Makefiles" },
{ "name": "windows-msvc", "generator": "Ninja", "cacheVariables": { "CMAKE_TOOLCHAIN_FILE": "C:/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake" } }
]
}Then configure with cmake --preset mac-clang or cmake --preset windows-msvc.
- Project layout:
src/— sources,include/engine— headers. Keep platform-specific code in conditional blocks inCMakeLists.txtso the single build file works on macOS/Linux and Windows. - For CI: add separate jobs for macOS and Windows and use the appropriate preset/toolchain.