Initial Raylib Project

This commit is contained in:
2025-08-30 02:19:34 +02:00
parent cfb4efe833
commit 4376426b4f
5 changed files with 274 additions and 1 deletions
+6
View File
@@ -39,3 +39,9 @@
# debug information files # debug information files
*.dwo *.dwo
# Dependency files
docs
src
vendor
include
+17
View File
@@ -0,0 +1,17 @@
Copyright (c) 2020-present Caps Collective & contributors
Originally authored by Jonathan Moallem (@jonjondev) & Aryeh Zinn (@Raelr)
This software is provided "as-is", without any express or implied warranty. In no event
will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you
wrote the original software. If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented
as being the original software.
3. This notice may not be removed or altered from any source distribution.
+101
View File
@@ -0,0 +1,101 @@
# Copyright (c) 2020-present Caps Collective & contributors
# Originally authored by Jonathan Moallem (@jonjondev) & Aryeh Zinn (@Raelr)
#
# This code is released under an unmodified zlib license.
# For conditions of distribution and use, please see:
# https://opensource.org/licenses/Zlib
# Define custom functions
rwildcard = $(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
platformpth = $(subst /,$(PATHSEP),$1)
# Set global macros
buildDir := bin
executable := app
target := $(buildDir)/$(executable)
sources := $(call rwildcard,src/,*.cpp)
objects := $(patsubst src/%, $(buildDir)/%, $(patsubst %.cpp, %.o, $(sources)))
depends := $(patsubst %.o, %.d, $(objects))
compileFlags := -std=c++17 -I include
linkFlags = -L lib/$(platform) -l raylib
# Check for Windows
ifeq ($(OS), Windows_NT)
# Set Windows macros
platform := Windows
CXX ?= g++
linkFlags += -Wl,--allow-multiple-definition -pthread -lopengl32 -lgdi32 -lwinmm -static -static-libgcc -static-libstdc++
THEN := &&
PATHSEP := \$(BLANK)
MKDIR := -mkdir -p
RM := -del /q
COPY = -robocopy "$(call platformpth,$1)" "$(call platformpth,$2)" $3
else
# Check for MacOS/Linux
UNAMEOS := $(shell uname)
ifeq ($(UNAMEOS), Linux)
# Set Linux macros
platform := Linux
CXX ?= g++
linkFlags += -l GL -l m -l pthread -l dl -l rt -l X11
endif
ifeq ($(UNAMEOS), Darwin)
# Set macOS macros
platform := macOS
CXX ?= clang++
linkFlags += -framework CoreVideo -framework IOKit -framework Cocoa -framework GLUT -framework OpenGL
endif
# Set UNIX macros
THEN := ;
PATHSEP := /
MKDIR := mkdir -p
RM := rm -rf
COPY = cp $1$(PATHSEP)$3 $2
endif
# Lists phony targets for Makefile
.PHONY: all setup submodules execute clean
# Default target, compiles, executes and cleans
all: $(target) execute clean
# Sets up the project for compiling, generates includes and libs
setup: include lib
# Pull and update the the build submodules
submodules:
git submodule update --init --recursive --depth 1
# Copy the relevant header files into includes
include: submodules
$(MKDIR) $(call platformpth, ./include)
$(call COPY,vendor/raylib/src,./include,raylib.h)
$(call COPY,vendor/raylib/src,./include,raymath.h)
$(call COPY,vendor/raylib-cpp/include,./include,*.hpp)
# Build the raylib static library file and copy it into lib
lib: submodules
cd vendor/raylib/src $(THEN) "$(MAKE)" PLATFORM=PLATFORM_DESKTOP
$(MKDIR) $(call platformpth, lib/$(platform))
$(call COPY,vendor/raylib/src,lib/$(platform),libraylib.a)
# Link the program and create the executable
$(target): $(objects)
$(CXX) $(objects) -o $(target) $(linkFlags)
# Add all rules from dependency files
-include $(depends)
# Compile objects to the build directory
$(buildDir)/%.o: src/%.cpp Makefile
$(MKDIR) $(call platformpth, $(@D))
$(CXX) -MMD -MP -c $(compileFlags) $< -o $@ $(CXXFLAGS)
# Run the executable
execute:
$(target) $(ARGS)
# Clean up all relevant files
clean:
$(RM) $(call platformpth, $(buildDir)/*)
+3
View File
@@ -0,0 +1,3 @@
### Aufbau des Spiels
Rasterbasierte Welt
Chunkaufteilung (32 tiles pro chunk)
+147 -1
View File
@@ -1 +1,147 @@
# FactoryBuilder # Raylib C++ Starter
The Raylib C++ Starter kit is a template project that provides a simple starter template for the [raylib](https://github.com/raysan5/raylib) game tools library incorporating the [raylib-cpp](https://github.com/robloach/raylib-cpp) C++ bindings and using [Make](https://www.gnu.org/software/make/) for building. The starter kit can automatcially clone down raylib and the bindings, compile them, and setup the project for separate compilation using a static library.
> Why static linking?
One of the most absurdly annoying things about C++ development is finding and linking dynamic libraries. The raylib project prides itself on having **"NO external dependencies"**, and we tend to agree that portability is way cooler than saving that fraction of a second on compile-time.
> Why not just use CMake?
I guess we just don't want the added headache. CMake is complex and sometimes feels like some *arcane magic* that we generally take for granted in build systems. If you look at the raylib library, yes it has CMake support, but it generally encourages the use of Make on all platforms because as the library reads:
> raylib is a programming library to enjoy videogames programming; no fancy interface, no visual helpers, no auto-debugging... just coding in the most pure spartan-programmers way
So that being said, we hope that this repository finds you well and wholeheartedly enjoying the *simple things in life* (i.e. video games programming).
### Current Compatibility
| OS | Default Compiler | Last Manual Build | Compile Status |
| ----------- | ---------------- | ------------------- | ---------------------------------------------------- |
| **macOS** | Clang++ | `Big Sur 11.0.1` | ![macOS Status](../../workflows/macOS/badge.svg) |
| **Linux** | G++ | `Ubuntu 20.04 LTS` | ![Linux Status](../../workflows/Ubuntu/badge.svg) |
| **Windows** | MinGW (G++) | `Windows 10 19041` | ![Windows Status](../../workflows/Windows/badge.svg) |
## Getting Started
### Installing Dependencies
Before building the project, you will need to install all relevant dependencies for your platform so that the project has access to all the tools required, and raylib can compile and link correctly. You can find intructions for installing dependencies on macOS, Linux, and Windows in the [docs file on installing dependencies](docs/InstallingDependencies.md).
### Building the Project
Once you have cloned this repository and installed dependencies, building the project is as simple as running these two commands in its root directory:
#### macOS & Linux
```console
$ make setup
$ make
```
#### Windows
```console
> mingw32-make setup
> mingw32-make
```
The first command will clone in the lastest C++ bindings and targeted version of raylib, copy across any relevant header files into `/includes`, and build a static library file from them, placing it in `/lib`. The second command then compiles, runs and cleans up your project using the source code in `/src/main.cpp`.
*If a window pops up, congratulations, you've successfully built the project and you can now start programming your game!*
## Using This Template
Now that you have the project setup and compiling on your system, it's time to start programming! If you aren't already familliar with [raylib](https://github.com/raysan5/raylib), we recommend looking over [this awesome cheatsheet](https://www.raylib.com/cheatsheet/cheatsheet.html) which lists every function, struct and macro available in the raylib C library. If you want specifics on how to use the C++ bindings, then you should check out the [raylib-cpp](https://github.com/robloach/raylib-cpp) repo, which nicely explains how the bindings work and contains [raylib's examples ported to C++](https://github.com/RobLoach/raylib-cpp/tree/master/examples).
Once you're up and running, we first of all recommend that all your code for the game should go into the `/src` directory, which is automatically included in the compile process when you run Make. The default entry point for the program is `/src/main.cpp` (which is pretty standard). If you wish to change the program entry point, add more libraries, or really anything about your project, all build instructions are specified in the [`Makefile`](Makefile) - no smoke and mirrors!
### Making Use of Separate Compilation
When building compiled applications from scratch, *each* source file needs to be compiled into an object file in order for them all to be linked together as a full program. This can become rather time-consuming and inefficient as your codebase expands to use tens or even hundreds of files that recompile each time you build. Fortunately, with a few clever rules in our [`Makefile`](Makefile), we can be sure to only have to recompile files affected by our changes.
By using the following Make commands instead of the default target, we can skip the cleanup step, and only recompile files that changed:
#### macOS & Linux
```console
$ make bin/app; make execute
```
#### Windows
```console
> mingw32-make bin/app && mingw32-make execute
```
Using this method can save you a huge amount of time compiling *(in reality, just a few seconds)* each time you make a small change to your code! If you want to know more about how it works, you should have a read through [the docs entry explaining the Makefile](docs/MakefileExplanation.md).
While separate compilation works quite well in most scenarios, it's not magic, and there are a few caveats to take note of here:
1. Changing `.h` files will often result in longer compile times by causing all files that include them to recompile
2. Constant changes to files included by many others in your program (like a base-class) will also cause all of those dependent to recompile
3. Including widely-scoped files (like the whole of `raylib-cpp.hpp`) will add all of its own includes as dependent and increase the build time
4. Placing includes in `.h` files instead of forward-declarations will also increase recursive includes and therefore the build time
### Passing Args to the Executable
For working with some projects, you may want to pass arguments to the program once it's been built. This can be achieved by assigning values to the `ARGS` flag in the Makefile like below:
#### macOS & Linux
```console
$ make ARGS="--somearg"
```
#### Windows
```console
> mingw32-make ARGS="--somearg"
```
### Specifying Custom Macro Definitions
You may also want to pass in your own macro definitions for certain configurations (such as setting log levels). You can pass in your definitions using `CXXFLAGS`:
#### macOS & Linux
```console
$ make CXXFLAGS=-DMY_MACRO=1
```
#### Windows
```console
> mingw32-make CXXFLAGS=-DMY_MACRO=1
```
### Specifying a Non-Default Compiler
If you want to use a compiler for your platform that isn't the default for your system (or potentially you would like to explicitly state it), you can make use of the system-implicit `CXX` variable like so:
#### macOS & Linux
```console
$ make CXX=g++
```
#### Windows
```console
> mingw32-make CXX=g++
```
## Contributing
### How do I contribute?
It's pretty simple actually:
1. Fork it from [here](https://github.com/CapsCollective/raylib-cpp-starter/fork)
2. Create your feature branch (`git checkout -b cool-new-feature`)
3. Commit your changes (`git commit -m "Added some feature"`)
4. Push to the branch (`git push origin cool-new-feature`)
5. Create a new pull request for it!
### Contributors
- [jonjondev](https://github.com/jonjondev) Jonathan Moallem - co-creator, maintainer
- [Raelr](https://github.com/Raelr) Aryeh Zinn - co-creator, maintainer
- [mTvare6](https://github.com/mTvare6) mTvare6 - contributor
- [rafaeldelboni](https://github.com/rafaeldelboni) Rafael Delboni - contributor
- [jason-cannon](https://github.com/jason-cannon) Jason Cannon - contributor
- [return215](https://github.com/return215) Muhammad Hidayat - contributor
- [Samuel Asher Rivello](https://github.com/SamuelAsherRivello) - contributor
## Licence
This project is licenced under an unmodified zlib/libpng licence, which is an OSI-certified, BSD-like licence that allows static linking with closed source software. Check [`LICENCE`](LICENCE) for further details.