Skip to content

Getting started

Requirements

  • CMake 3.30 or newer and Ninja.
  • A compiler with C++26 support in CMake: Clang 18+, GCC 14+ or Apple Clang 17+.
  • Windows: Visual Studio 2022 or newer with the C++ Clang tools for Windows component (clang-cl 17+) and CMake 4; configure with -T ClangCL. CMake has no C++26 mode for the plain MSVC compiler (cl.exe).
  • Client builds only: Python 3 with Jinja2, used by glad to generate the OpenGL loader.
  • Linux client builds: the X11, OpenGL and audio development packages SDL3 needs.
python3 -m venv .venv && source .venv/bin/activate
pip install -r cmake/requirements.txt

Every library (SDL3, glad, GLM, stb, Asio, nlohmann-json, LZ4, Catch2) is downloaded at configure time by CPM; nothing else has to be installed.

Build and test

cmake --preset client            # or another preset below
cmake --build --preset client
ctest --preset client

On Windows: cmake --preset windows, then cmake --build --preset windows-debug and ctest --preset windows-debug (or windows-release).

Preset Contents
client, client-release Every module and the tests
server, server-release core, ecs, net and the tests, without SDL3 or OpenGL
macos, macos-release Client build generating OpenGL 4.1 (the highest macOS supports)
sanitize Client build with AddressSanitizer and UndefinedBehaviorSanitizer (Debug)
windows Client build with Visual Studio and clang-cl; build and test with the windows-debug or windows-release presets

Presets without a suffix build in Debug; -release presets build in Release.

Tip

If CMake does not find Jinja2, add -DPython_EXECUTABLE=$PWD/.venv/bin/python to the first configure.

Run an example

Client builds also compile the programs in examples/, one scene per feature of the engine. aegis2d_example_window opens a window and clears it with a slowly changing color until it is closed (--frames N closes it after N frames); its title and size come from examples/window/assets/window.json. It also shows the logger and the OpenGL error reports: --log FILE writes the log to FILE as well as to the console, --log-level debug (or info, warn, error) hides the messages below that level, and with debug a message a second gives the frame count. --gl-errors compiles a broken shader, whose compile error is logged, then makes an OpenGL call the driver rejects, which the driver reports through KHR_debug (on macOS, read back at the end of the frame):

./build/client/examples/aegis2d_example_window
./build/client/examples/aegis2d_example_window --gl-errors --log window.log --log-level debug

On macOS, use the macos preset: the default presets ask for OpenGL 4.5, which macOS does not provide.

aegis2d_example_key_bindings shows keyboard actions and their remapping: the arrows and Space color the window, F1 to F5 rebind up, down, left, right and fire to the next key pressed (Escape cancels), F9 restores the defaults. The title bar shows the bindings, which are kept in the player's settings folder (or the file given with --settings) and read back at the next start.

./build/client/examples/aegis2d_example_key_bindings

aegis2d_example_mouse draws a square that follows the mouse on a logical screen of 1280 x 720, which stays under the cursor however the window is resized: the left button leaves a mark, the right button removes them, the wheel makes the square larger or smaller and the middle button resets it. The title bar shows the position in logical pixels.

./build/client/examples/aegis2d_example_mouse

aegis2d_example_menu is a main menu used with the keyboard (Tab, the arrows, Enter), a gamepad (the D-pad, the left stick, A) or the mouse: the focused button is outlined, held buttons look pressed, and the disabled "Continue" is skipped. "Text size" makes the whole menu larger, from 100% to 200%; "Quit" or Escape closes it.

./build/client/examples/aegis2d_example_menu

aegis2d_example_settings is a settings screen built on the same widgets: a scrollable resolution list (Up and Down move the selection, the list scrolls and shows a scrollbar, a click or Enter chooses), two volume sliders (Left and Right move the focused one by 10, the mouse drags the handle) and a Back button. Tab, the arrows, the D-pad or the mouse move the focus between them; every change is logged.

./build/client/examples/aegis2d_example_settings

aegis2d_example_loading is a loading screen: 24 textures are read by a slow loader (80 ms each, as a disk would take) into a ResourceCache by a Preloader on its own thread, while the screen draws a progress bar from progress(), the count of resources dealt with, then READY; Enter or Escape quits.

./build/client/examples/aegis2d_example_loading

aegis2d_example_sound plays a sound each time Space is pressed, and looping music with M. F1 to F6 lower and raise the master, music and effects volumes by steps of 10%; the title bar shows them, and they are kept in the player's settings folder (or the file given with --settings).

./build/client/examples/aegis2d_example_sound

aegis2d_example_effects flashes the screen white and shakes it when Space sets off an explosion; F1 turns flashes and shake off or on again, and the choice is kept in the player's settings folder (or the file given with --settings).

./build/client/examples/aegis2d_example_effects

aegis2d_example_auto_fire fires four shots a second while Space is held; F1 turns auto-fire on, so that one press of Space starts firing and the next stops it. The option is kept in the player's settings folder (or the file given with --settings).

./build/client/examples/aegis2d_example_auto_fire

aegis2d_example_ship is the first playable scene: a ship that moves with the arrows, stays on screen and fires with Space (four shots a second) at the enemies coming from the right, all through the ECS, with its controls shown in the corner. A gamepad works too: the D-pad or the left stick moves the ship, A (Cross) or the right trigger fires, and the corner shows the pad's buttons while one is plugged in. The enemies come in waves read from examples/ship/assets/waves.json (copied next to the program; --waves FILE reads another file), looping: drones fly straight, wavers follow a sine wave, and red gunners fire at the ship every 1.6 s while they are on screen. Edit the file and press R: the waves are read again and start over, with no recompilation, and a mistake in the file (such as an unknown type) is logged with its place in the file while the old waves go on. --random SEED replaces the waves with enemies of random types at random times and heights, the same ones for the same seed. Each enemy shot down scores 100 (a gunner 200); an enemy or an enemy missile that hits the ship costs a life, out of three, and Enter (or Start) starts again after the last one. Music loops in the background; shots, explosions and lost lives are heard, played by the audio module from the gameplay events, so the gameplay code never calls audio. M stops or starts the music. F1 (or Back) turns auto-fire on; keys, buttons and auto-fire come from the player's settings folder (or the file given with --settings). The ship and the enemies are pixel art sprite sheets (examples/ship/assets/ship.png and enemy.png), drawn four times larger and kept sharp, and animated: the ship's engine flame flickers and the enemies move their legs. Every kill shows an explosion, made by the client from the gameplay's ecs::Explosion event and gone after its last frame (examples/ship/assets/explosion.png). In a debug build the sprites reload while the game runs: change the copy next to the program (assets/ship.png), or edit examples/ship/assets/ship.png and build again, which copies it, and the new ship shows within a quarter of a second, with no restart (at the same size: another one is refused and logged, the old sprite kept). The window can be resized: the game keeps its 1280 x 720 layout and its proportions, scaled to the window with black bars. Behind it, three layers of stars scroll at their own speed, the far ones slower: a parallax starfield (render::Starfield). Every 5 seconds the log gives the frames and the simulation ticks per second: with --no-vsync the frame rate goes up while the simulation stays at 60 ticks per second, so the game runs at the same speed. F12 shows the frame metrics over the game (render::MetricsOverlay, shown from the start with --metrics): the frames per second, the mean and longest frame times of the last 120 frames, the entities, the sprites and draw calls of the frame before, the memory the program uses, the overlay's own left out, and a bar per frame, a line marking 60 frames per second and the slower frames in orange. Under the counters, the profiler's breakdown of the frame before (core::Profiler): the time of the ticks (update, and its movement, weapons, spawns and collision), of the input and of the drawing. --trace trace.json keeps every one of those timings and writes them at the end in the Chrome trace format: open the file in Perfetto to see each frame and its parts on a timeline. The stress example and the tower defense sample show the overlay with F12 too.

Its gameplay values are console variables: assets/ship.cfg, next to the program, sets player_speed and player_fire_interval at start, and the command line wins over it (+set player_speed 450). Change them and run the game again, with no recompilation; a value that does not read is logged and the default kept.

The key under Escape (` or ²) opens the console over the game, which then ignores the keyboard: help lists what it runs, the engine's commands (help, clear), the console variables (player_speed shows the speed, player_speed 450 changes it for the next ship) and the game's own (lives 9, quit). Up and Down bring back the lines run before, Tab completes a name (pl gives player_, Tab again lists player_fire_interval and player_speed), Page Up and Page Down scroll it, Escape closes it.

./build/client/examples/aegis2d_example_ship
./build/client/examples/aegis2d_example_ship +set player_speed 450 +set player_fire_interval 0.1
./build/client/examples/aegis2d_example_ship --waves examples/ship/assets/waves.json
./build/client/examples/aegis2d_example_ship --random 42 --no-vsync

The ship example: the ship and its missiles over the stars, the enemies, the score and lives, and the controls.

The ship example with the frame metrics: 120 frames per second, 8.3 ms a frame, 4 entities, 369 sprites in 4 draw calls, and a bar per frame.

aegis2d_example_starfield draws the parallax starfield alone, at the frame rate given with --fps (60 by default), moving the stars by the real time of each frame. Every second, the log gives the frame rate and each layer's speed, measured from where its stars are drawn: 25, 70 and 160 pixels a second at 30 frames a second as at 144. --seconds S stops after S seconds, and --screenshot FILE then saves the last frame.

./build/client/examples/aegis2d_example_starfield --fps 30
./build/client/examples/aegis2d_example_starfield --fps 144 --seconds 5

aegis2d_example_scripted moves a swarm of 60 squares from a Lua script only: the C++ code creates the entities and draws them, and assets/swarm.lua (copied from examples/scripted/assets/) gives them a velocity, moves them, bounces them on the edges and colors them through script::bind_components(). Every 1.5 s the game blows a square up and publishes an ecs::Explosion: the script hears it (script::EventBridge) and creates eight sparks where it was, which it destroys once faded. Edit the copy next to the program and run it again: the swarm changes with no recompilation, and a broken script is logged with its line.

./build/client/examples/aegis2d_example_scripted

aegis2d_example_stress is the sprite stress test: N sprites (10000 by default) of T textures (4) bounce around the screen for F frames (600), drawn batched (one draw call per layer and texture) or, with --mode naive, with one upload, bind and draw call per sprite, as a renderer without batching would; both give the same picture. With --scene particles, eight particle emitters hold a steady total of N particles instead, drawn in the sprite batch with ParticleEmitter::draw() (one draw call a frame); the sprites column of the CSV is then the particles alive at that frame. It then logs the frame rate, the draw calls and the CPU and GPU times (mean, median, 95th percentile, the first 10 frames left out), and with --csv FILE writes every frame's times, one line each. Vsync is off unless --vsync is given. With --metrics (or F12), the frame metrics are drawn over the scene; the log and the CSV leave out their sprites and draw calls.

./build/client/examples/aegis2d_example_stress --sprites 50000 --csv batched.csv
./build/client/examples/aegis2d_example_stress --sprites 50000 --mode naive --csv naive.csv
./build/client/examples/aegis2d_example_stress --scene particles --sprites 10000
frame,mode,sprites,draw_calls,cpu_ms,gpu_ms
0,batched,50000,4,12.410,
1,batched,50000,4,9.832,2.118

cpu_ms is the time to move the sprites, draw them and end the frame, buffer swap included; gpu_ms the GPU time of the drawing (uploads included) from OpenGL timer queries, the latest known at that frame, usually one to three frames old and empty until the first result. The program exits with 77 when it cannot open a window with OpenGL, and the stress_scene test runs it in both modes and checks the CSV.

aegis2d_example_hud draws a HUD over 1000 scrolling stars: the score (Space adds 100 points), the four players with their markers, and the renderer's sprite and draw call counts, with the engine's built-in font. F1 and F2 make the text smaller or larger (100% to 200%, kept in the player's settings folder or the file given with --settings), and the HUD is laid out again so that nothing overlaps. F3 shows the screen as players with a color vision deficiency see it (protanopia, deuteranopia, tritanopia, then no color at all): the four players stay apart by their lightness and their marker. --text-size 150 starts at 150%, --color-vision achromatopsia starts in grayscale, and --screenshot FILE saves a frame as a PNG file.

./build/client/examples/aegis2d_example_hud

The HUD example: score, render statistics and the four players' markers over a
starfield.

aegis2d_example_players shows four players in one game, told apart at a glance: each player slot has its color (render::player_style()), which tints the ship and its missiles, and its marker shape and number, which follow the ship. Player 1 moves with the arrows (or a gamepad) and fires with Space; players 2 to 4 fly and fire on their own, as the other clients would. Enemies come from the right: each one shot down scores 100 for the player whose missile hit it, and an enemy that hits a ship costs that player a life, out of three; every kill shows an explosion. The HUD at the bottom gives each player's score and lives (or OUT), read from the world every frame, and the log tells each lost life with the same values. Once player 1 is out, Enter starts a new game. F3 shows the scene as players with a color vision deficiency see it, down to grayscale, where the four ships and their panels still differ by lightness and marker; --color-vision achromatopsia starts in grayscale.

./build/client/examples/aegis2d_example_players

The players example, with typical vision (top) and in grayscale (bottom): four ships in
blue, red, yellow and cyan, each with its marker and number, the enemies, and the HUD with
each player's lives and score.

aegis2d_example_connect is the screen a player sees before joining: the goal of the game, the player's controls, with their own keys and text size read from their settings folder (or the file given with --settings, in the format the key bindings and HUD examples write), and the server address, a ui::TextField on the platform's text input: the characters follow the keyboard layout, so an address typed on an AZERTY keyboard has its @ and its dots; Backspace erases one character, accents included, Left and Right move the cursor, and a placeholder shows while the field is empty. Enter joins.

./build/client/examples/aegis2d_example_connect

aegis2d_example_sound_cues shows important sounds on screen: E brings an enemy in from the right, B warns of a boss from above, L signals low life. F1 turns the cues on or off (kept in the player's settings), M mutes the sound: with the cues on, the game can be played muted.

./build/client/examples/aegis2d_example_sound_cues

aegis2d_example_udp_echo exchanges UDP datagrams between two processes: run a server in one terminal and send it messages from another.

./build/client/examples/aegis2d_example_udp_echo listen 4242
./build/client/examples/aegis2d_example_udp_echo send 127.0.0.1 4242 "hello"

Run the tower defense sample

samples/tower_defense is a second game, a tower defense, made with the engine's generic modules only (core, ecs, platform, render, audio, ui): no shoot'em up code. Client builds compile it with the examples:

./build/client/samples/tower_defense/tower_defense

It also builds alone against an installed engine, as any game would. Its page, Tower defense sample, tells how to play it, what each engine feature does in it, and how to change its towers and waves without recompiling.

Use the engine in a game

include(FetchContent)
FetchContent_Declare(aegis2d
    GIT_REPOSITORY https://github.com/Aegis2D-Dev/aegis2d.git
    GIT_TAG master
    GIT_SHALLOW TRUE)
FetchContent_MakeAvailable(aegis2d)

add_executable(my_game main.cpp)
target_link_libraries(my_game PRIVATE aegis2d::engine aegis2d::warnings)
aegis2d_stage_runtime(my_game)
aegis2d_copy_assets(my_game assets)   # assets/ -> <binary folder>/assets

aegis2d_copy_assets(<target> <folder>...) copies the folder next to the binary on every build (only changed files), so the game runs from the build tree without copying anything by hand; give several folders to share some assets between games. At run time, aegis2d::core::asset_path("sprites/ship.png") gives the full path, whatever the working directory:

#include <aegis2d/core/config.hpp>
#include <aegis2d/core/paths.hpp>

const auto waves = aegis2d::core::Config::from_file(aegis2d::core::asset_path("waves.json"));

A file deleted from the source folder stays in the build folder until it is cleaned.

A server-only game sets AEGIS2D_BUILD_CLIENT to OFF before FetchContent_MakeAvailable.

From an installed engine

A game can also build against an engine installed once, without its sources. The engine installs its development files, the development component, from its own build:

cmake --preset client-release && cmake --build build/client-release
cmake --install build/client-release --component development --prefix ~/aegis2d

~/aegis2d then holds the modules built (lib/), the headers with GLM's (include/), SDL3 in a client build, and the CMake package (lib/cmake/Aegis2D/). The game finds it with CMAKE_PREFIX_PATH and asks for the modules it uses; each one brings the modules it needs:

find_package(Aegis2D 0.2 REQUIRED COMPONENTS core ecs net)   # or render, audio... or none
add_executable(my_server main.cpp)
target_link_libraries(my_server PRIVATE aegis2d::core aegis2d::ecs aegis2d::net)
cmake -S . -B build -DCMAKE_PREFIX_PATH=~/aegis2d

aegis2d::engine links every module of the installation. The client modules (platform, render, audio) are there only if the engine was built with AEGIS2D_BUILD_CLIENT; asking for a module the installation does not have stops the configure with its name. The version is checked on the minor number while the engine is in 0.x (find_package(Aegis2D 0.2) accepts 0.2.*). The engine's own development install is skipped when it is fetched by a game (AEGIS2D_INSTALL_DEVELOPMENT, on only for the engine's own build). Which modules a game needs is in the Modules reference.

CI checks this path on Linux and Windows (Game against the installed engine jobs): the engine is built without its tests and examples, as a game's dependency, installed, and tests/install/consumer, a tiny game moving an entity with core and ecs, is built against it with find_package, run, and must load those two modules only. The same check runs in ctest as install_find_package.

Install and package a game

aegis2d_install(TARGETS my_game ASSETS assets)   # can be called again for a server
aegis2d_package(NAME my-game VENDOR "My team" DESCRIPTION "My game")  # top-level, once
cmake --install build/client-release --prefix ~/my-game   # or:
cd build/client-release && cpack                          # packages/my-game-<version>-<system>-<cpu>.tar.gz

The installed tree runs from anywhere, without LD_LIBRARY_PATH or system libraries:

bin/my_game               bin/assets/...      (core::asset_dir())
lib/libaegis2d_*.so.0     lib/libSDL3.so.0    (bin/ on Windows, next to the executables)

Executables and engine libraries carry a relative run path ($ORIGIN/../lib, or @executable_path/../lib on macOS). On Windows the package is a .zip with the DLLs and the compiler's C++ runtime next to the executables. The engine's own client build installs and packages all its examples the same way, with their assets (aegis2d-examples-*.tar.gz).

Build this documentation

pip install -r docs/requirements.txt
mkdocs serve          # http://127.0.0.1:8000, reloads on save
mkdocs build --strict # what CI runs

The API reference is generated separately: mkdir -p build && doxygen docs/Doxyfile, then open build/doxygen/html/index.html.