This is a basic template for making SFML games in C++. I made this template because I often find myself writing the same, boring CMake files.
⚪ Optional but recommended
🟩 REQUIRED
🟨 NOT recommended
Item | Required (see legend) |
---|---|
CMake | 🟩 |
Ninja | 🟩 |
Any compiler | 🟩 |
ccache | ⚪ |
CLion IDE | ⚪ |
MinGW | 🟨 |
Click this button on top (or just click the button below)
Or simply download the source code via git clone
or press and download zip.
Unzip your files into a folder. The folder structure should look like this:
game-template-2D
├── .gitignore
├── CMakeLists.txt
├── .idea/* (we dont care about this for now)
├── src
│ ├── main.cpp
│ └── Window.cpp
└── include
└── Window.hpp
Open any shell of your choice.
Note for Windows users (click to expand)
When using WindowsMAKE SURE TO USE DEVELOPER COMMAND PROMPT/DEVELOPER POWERSHELL for this step.
Navigate to the project folder and create a build folder:
mkdir build
cd build
Generate CMake files:
Note for Windows users (click to expand)
If you have MinGW installed, make sure to add:-DCMAKE_IGNORE_PATH=D:\Path\to\mingw
So that it dosent use mingw in the compilation process
cmake -DCMAKE_BUILD_TYPE=Release -G Ninja ..
If you have any issues with until now, then go back and retry If you still have issues, open an issue ticket via github
Finally, we get to the exceiting part
run the build command, in the same directory you generated the cmake files
cmake --build . --config Release
If everything goes well 🤞...
You should have an executable in:
bin/Release
(I am assuming you are in the game-template-2D/build
directory already.)
Run the executable bin/Release
(warning, flashing colors).
It should display a window similar to this:
or (Flashing colors warning)
NVIDIA_Share_lvWIXuQbh6.mp4
Happy Developing
Here is a list of compilers that are recommended by me for the respective OS:
OS | Compiler |
---|---|
Windows | MSVC |
Mac | clang/g++ |
Linux | g++ |
DO NOT, FOR THE LOVE OF GOD, USE MINGW ON WINDOWS.
IT WILL RUN FINE ON YOUR PC/Laptop, BUT IT WILL INTRODUCE MANY MORE PROBLEMS WHEN YOU DISTRIBUTE YOUR PROGRAM.
Use the Visual Studio compiler from Microsoft instead; you will be doing yourself a favor.