Building C++ Games for the Desktop

A C++ game for macOS, Linux or Windows is compiled against the Acron desktop SDK: the engine prebuilt for one platform, with everything a game needs to build, run and ship. You never compile the engine itself, and you do not need its source code.

The web, Android and the Wii have SDKs of their own, built the same way with CMake: see The Web, Building for Android and Building for the Wii.

This page is about games written in C++. A Python game uses the acron wheel and is packaged with build_apps; the asset tools described below come with the wheel as well.

The SDK

There is one SDK per platform, named after it: acron-desktop-sdk-<version>-<platform>.tar.gz, where <platform> is macos-arm64, macos-x64, linux-x64, linux-arm64 or windows-x64 (the SDK’s PLATFORM file says which). Unpacked, it holds:

bin/                 the asset tools: egg2bam, bam2egg, multify, pview, egg-optchar, ...
                     (Windows: also the engine's DLLs)
include/acron/       the engine's headers
lib/                 the engine's shared libraries, and its plugins
                     (libacrongl: OpenGL; libp3openal_audio: audio)
lib/cmake/Acron/     the CMake package
thirdparty/          headers of the libraries the engine's headers include
                     (Bullet, ODE, RmlUi, ...)
etc/acron/           the default configuration (.prc files)
share/acron/         the built-in models
starter/             a first game
examples/rmlui-menu/ an HTML/CSS (RmlUi) menu

The engine’s libraries already contain the libraries it uses (OpenAL Soft, FreeType, HarfBuzz, libpng, libjpeg, zlib, Vorbis, Bullet, ODE, RmlUi, and the glslang/SPIRV shader compilers), so nothing else needs to be installed. The SDK is relocatable: unpack it anywhere.

You need a C++17 compiler (Xcode’s command-line tools on macOS 11 or later; GCC or Clang with the X11 and OpenGL development packages on Linux; Visual Studio 2022 on Windows) and CMake 3.16 or later.

With the Acron launcher

The launcher’s acronmanager gets the SDK for you. In the project’s pyproject.toml:

[tool.acron.cmake]
target = "mygame"                 # the CMake target `acronmanager run` builds and runs

[tool.acron.desktop]
version = "1.11.0.post60"         # the SDK of this engine version (default: the latest)
# sdk = "path/to/acron-desktop-sdk-...-macos-arm64.tar.gz"   # or a local one
data = ["build/desktop-release/game.mf"]  # what `dist` ships beside the program

acronmanager run downloads the SDK once from the Acron archive (with the launcher’s sign-in) into the launcher’s cache, configures the project with it, builds and starts the game; acronmanager build only compiles; acronmanager dist builds the release and packages it (see below).

By hand

cd acron-desktop-sdk-<version>-<platform>/starter
cmake -S . -B build -DAcron_DIR=$PWD/../lib/cmake/Acron
cmake --build build --config Release
build/starter                                  # Escape quits

On Windows, put the SDK’s bin folder on PATH first (that is where the DLLs are) and run build\Release\starter.exe.

A program built this way runs from its build folder: it finds the SDK’s libraries through its build rpath (macOS, Linux), and the libraries find the configuration and the plugins themselves.

Your own CMakeLists.txt

cmake_minimum_required(VERSION 3.16)
project(mygame LANGUAGES CXX)

find_package(Acron REQUIRED COMPONENTS Framework)

add_executable(mygame main.cxx)
target_compile_features(mygame PRIVATE cxx_std_17)
target_link_libraries(mygame PRIVATE Acron::Framework::p3framework)

Configure it with -DAcron_DIR=<sdk>/lib/cmake/Acron (or -DCMAKE_PREFIX_PATH=<sdk>). Other components and their targets: Acron::Core::acron and Acron::Core::acronfx (always there), Acron::Egg::acronegg, Acron::Bullet::p3bullet, Acron::ODE::p3ode, Acron::RmlUi::p3rmlui, Acron::OpenAL::p3openal_audio, Acron::OpenGL::acrongl.

Assets

The tools in the SDK’s bin are the engine’s own, of the same version, so a .bam they write loads in the game:

<sdk>/bin/egg2bam -o models/hero.bam models/hero.egg
<sdk>/bin/multify -c -f game.mf models/*.bam fonts/*.ttf
<sdk>/bin/pview models/hero.bam

acronmanager puts the SDK’s bin first on PATH (and sets ACRON_TOOLS to it) while it builds, so an asset step in your CMakeLists.txt can simply call egg2bam.

Offscreen test runs

For automated tests that should not open a window, render into an offscreen buffer:

load_prc_file_data("", "window-type offscreen\nback-buffers 0\n");

and drive the frames yourself with framework.do_frame(). The starter’s --offscreen --frames N options show how.

Shipping the game

A release ships the SDK’s libraries with the program. acronmanager dist lays this out in dist/:

  • macOS: <Name>.app with the program in Contents/MacOS, the libraries and configuration in Contents/Frameworks, your data in Contents/Resources, the icon of [tool.acron.app], signed ad hoc (sign it with your Developer ID and notarise it before you publish it: see Signing for macOS and Windows), and a .zip of it.

  • Linux: a folder with the program, lib/ (found through the program’s $ORIGIN/lib rpath, which needs patchelf), etc/ and your data, and a .tar.gz of it.

  • Windows: a folder with the program and the DLLs beside it, and a .zip (sign the program before you publish it: see Signing for macOS and Windows).

The folder or bundle can be moved anywhere.