Skip to main content

Developer Console

Glitter includes a Valve-style developer console — a scrollable log pane on top with a command line at the bottom, rendered via ImGui.


Opening the console

Toggle with the grave/tilde key (`). While the console is open, keyboard input to the game is suppressed.


Architecture

The ConsoleSink is a spdlog sink that routes every engine log message into the console's scrollable log pane. Log lines are colour-coded by level.


Registering commands

Registering a console command
console.registerCommand("name", "description", [](const CommandArgs& args) {
// handle the command
});

Command names are stored lowercase. Every command automatically supports --help which prints the command's description.


CommandArgs

Parsed command arguments supporting positional args, named --key=value, and --flags.

MethodReturnsDescription
hasFlag(flag)boolCheck if a --flag was present
get(key)optional<string_view>Get a --key=value arg, or nullopt if absent
positionalvector<string>Positional (non-flag) arguments

Thread safety

  • addLine() is safe to call from any thread (spdlog sink thread).
  • All other methods must be called from the main (render) thread.

The console buffers up to 2048 log entries.


Usage in C++

Console usage
// Toggle from a keybind callback
console.toggle();

// Draw every frame inside an active ImGui frame
console.draw();

// Execute a command programmatically
console.execute("debug_channel albedo");