Simple Raylib Template
Minimal game template using raylib as a git submodule and CMake.
This repository is intended to be used as a starting point for a new raylib project.
I also have a more modular (lib-based) template, 
How to Clone
git clone --recursive to get the raylib submodule local
If you forgot, do:
git submodule update --init --recursive after regular git clone
Project Structure
What your project architecture should ideally look like for the CMakeLists.txt I’ve included (Can change accordingly, otherwise)
‖
‖——.git*
‖——CMakeLists.txt
‖——CMakePresets.json
‖——include/
‖ ‖——*.h or *.hpp → all *your* header files
‖——src/
‖ ‖——main.cpp
‖ ‖——*.cpp → all other source files
‖——raylib/ → your raylib engine (submodule)
Note: if you are using c++, the repository might show C because of the raylib files.
Just add this to .gitattributes
**/*.h linguist-vendored
**/*.c linguist-vendored
Now your repository will show C++
Build
mkdir build
cd build
cmake --preset Debug OR cmake --preset Release – (configuration of cmake)
cmake --build --preset Debug OR cmake --build --preset Release – (compilation + build of your files, only what has changed since last build)
Check out
if you’re confused
Executable will appear in build/ under preset name
Linux Dependencies
Raylib requires a lot of libraries that are built-in on Mac and Windows.
No worries, Linux just requires 1 command to install them all:
sudo apt install \
libx11-dev \
libxcursor-dev \
libxrandr-dev \
libxi-dev \
libxinerama-dev \
libgl1-mesa-dev \
libasound2-dev \
libpulse-dev \
libxkbcommon-dev
Add New Source Files
Put any new .cpp or .c files in src/
Update CMakeLists.txt as needed, example:
add_executable(YourProjectName
src/main.cpp
src/other_file.cpp
)
Updating raylib (the submodule)
cd raylib
git pull
cd ..
git add raylib
git commit -m "Updated raylib submodule"
Requirements
- CMake 3.20+
- C++ compiler: GCC / Clang
- Ninja (not required, but it’s what the presets use)
评论