🖥️ C++ Game Development Utility Libraries #
Coming from a Rust background, you might be looking for some C++ game development utility
libraries. We are talking about the C++ equivalents for clap, dbg!
, format!
and log here. With the C++ ecosystem working a little
differently to Rust’s it can be harder for a newcomer to discover libraries offering common
utility functions for your game.
Although we mentioned Rust developers, hopefully the post is also useful to anyone new to C++, with other backgrounds, or coming back to C++ after some time away.
Let me know if you find the post useful, and of course, if you would like to see similar content covering other C++ tooling. If you are looking for game engine and ECS options, see the recent post on C++ Game Dev.
⌨️ C++ Utility Libraries with Rust Equivalents #
CLI11 #
Command line parser for C11++ and later / Rust equivalent: clap crate
CLI11 offers CLI argument parsing in modern C++. This library needs minimal boilerplate code and supports some nice-to-have features, such as input validation and automatic usage and help message generation. It also works well with CMake. Definitely worth adding to your C++ Game Dev tool belt, as even for GUI games, you might want to accept CLI parameters for adjusting screen size, for example.
There’s much more to say; it just works!
Learn more about CLI11 here:
- GitHub repo: CLIUtils/CLI11
- Book: CLI11 book
- Code Examples: CLI11 Examples
dbg(…) #
C++ macro for debugging / Rust equivalent: inbuilt macro: dbg!(x)
The Rust dbg macro offers a quick way to add a printout of a variable in your app to the console. This package, was
inspired by the Rust macro, and brings you similar features. Of course, you could use std::cout
, std::format
or fmt::format
(see
fmtlib, below). Those are better suited to more general use cases, and dbg(…)
adds the source file and line number in the output, making it ideal for quick debugging. The other
advantage of using this library, is that it becomes easier to remove your debug output for release
builds, or when you no longer need it in the code.
Example from the GitHub repo:
The library works well with CMake.
Learn more about dbg(…) here:
- GitHub repo: sharkdp/dbg-macro
fmtlib #
Rust equivalent: inbuilt macro: format!("Some text {x}")
C++20 brings std::format
, improving C++ developer experience for formatting strings. If you have to use older standards,
though, add fmtlib
to your repo. It plays well with CMake and you can
use CPM to add fmtlib to your project . The library supports many Rust format
macro features, and makes
code far cleaner when you need to do string interpolation with variables.
Example from the GitHub repo:
Learn more about fmtlib here:
- GitHub repo: fmtlib/fmt
- Documentation: fmtlib docs
- Cheat Sheets: fmtlib Cheat Sheets
FTXUI #
C++ library for terminal-based user interfaces / Rust equivalent: ratatui crate
Functional Terminal (X) User Interface (FTXUI) is a neat library for creating text user interfaces. You could design your a game using it; in fact, there is a list of existing FTXUI games in the GitHub repo, including a Minesweeper clone. FTXUI generates cross-platform executables and also supports generating WebAssembly (WASM) output, for sharing the app on the Web.
See CMake FetchContent details on the GitHub repo.
Learn more about FTXUI here:
- GitHub repo: ArthurSonzogni/FTXUI
- Documentation: FTXUI docs
- WebAssembly Code Examples: FTXUI Examples
spdlog #
Fast C++ logging library / Rust equivalent: log crate
spdlog provides logging, generating messages with the usual log levels (trace, debug, info etc.). You can format messages using the fmtlib syntax (see fmtlib, above). Its speed makes it is a nice choice to add to your toolkit for building observability into your C++ game , right inside the game loop.
Alternatives are glog from Google is full-featured, like spdlog, while Plog offers a lightweight alternative . Both are worthy upgrades on using C++ built-in std::clog
.
Learn more about spdlog here:
- GitHub repo: gabime/spdlog
- Documentation: spdlog wiki
🗳 Poll #
🙌🏽 C++ Game Utility Libraries: Wrapping Up #
In this C++ game utility libraries, we had a look at some C++ libraries useful for game dev. More specifically, we saw:
- C++ equivalents to poplar Rust libraries;
- considered spdlog for observability in your C++ game; and
- FTXUI for text-based games.
I hope you found this useful. Do let me know if you would like to see more similar content. Also reach out if there is anything I could improve to provide a better experience for you.
🙏🏽 C++ Game Utility Libraries: Feedback #
If you have found this post useful, see links below for further related content on this site. Let me know if there are any ways I can improve on it. I hope you will use the code or starter in your own projects. Be sure to share your work on X, giving me a mention, so I can see what you did. Finally, be sure to let me know ideas for other short videos you would like to see. Read on to find ways to get in touch, further below. If you have found this post useful, even though you can only afford even a tiny contribution, please consider supporting me through Buy me a Coffee.
Just dropped a post listing some handy Modern C++ utility libraries, handy for game development.
— Rodney (@askRodney) February 28, 2024
Includes libraries for CLI command parsing, logging, formatting and even creating text UIs.
Hope you find it useful!
https://t.co/jKCNg5EQP6 #askRodney
Finally, feel free to share the post on your social media accounts for all your followers who will find it useful. As well as leaving a comment below, you can get in touch via @askRodney on X (previously Twitter) and also, join the #rodney Element Matrix room. Also, see further ways to get in touch with Rodney Lab. I post regularly on Game Dev as well as Rust and C++ (among other topics). Also, subscribe to the newsletter to keep up-to-date with our latest projects.