|
libtcod
|
This guide sets up a portable project which will work for all platforms (Windows/Mac/Linux) as long as these instructions are followed closely. If you are unsure about anything then you can refer to the libtcod template project for a known working example. The template project includes Emscripten support which will not be covered by this getting started example.
This guide will show how to setup a Libtcod project with a CMake/Vcpkg build system. You will need Git, CMake, and a compiler. For Windows Visual Studio Community will be used for the compiler.
Here is a simple example of setting up a libtcod context in C++ without using deprecated functions. Put this code at ./src/main.cpp:
This source file assumes that an environment with SDL2 and libtcod is setup correctly. To setup this environment CMake will be used to invoke Vcpkg to include those libraries.
This is done with a ./CMakeLists.txt script:
Since this CMake script is configured to use a Vcpkg submodule we will set that up now.
Open a terminal to the project directory. If the project is opened in an IDE then you should have a "terminal" tab which will be opened to the project root directory. Most platforms will let you open a terminal by right-clicking on the folder from its file explorer. On Windows after you've installed Git for Windows then you should have a "Git Bash Here" as an easy option to open a terminal.
With the terminal run git init to turn the folder into a Git repo, then run git submodule add https://github.com/microsoft/vcpkg.git to add the Vcpkg submodule. You should have a new folder at ./vcpkg with the Vcpkg repo.
While SDL2 and libtcod could be manually installed with Vcpkg, they can also be automatically managed with Vcpkg's Manifest Mode. In Manifest Mode CMake will invoke Vcpkg which will automatically download and compile any libraries listed in the manifest.
Create a ./vcpkg.json manifest:
The build system is fully setup. You can compile and run the program with CMake or any IDE which integrates with CMake. Visual Studio Community is one of those IDE's, you can open the project folder and then pick libtcod-getting-started as the target to run when asked. VScode with the CMake Tools plugin can also build CMake projects, when asked pick the Visual Studio Community toolkit matching the compiler you installed and then pick libtcod-getting-started as the launch target. VSCode works on all platforms and can be told to use whichever compiler is available locally. Most other IDE's should have CMake integration if you look them up.
If you are stuck then try getting the libtcod template project to run since it is a known working example. If you are still stuck then you can open a discussion on GitHub.