Raylib is an open-source game development library written in c that allows you to create 2D and 3D games and any kind of application.
This guide will help you setup and compile your first project in Raylib.
To get started, install the latest version of Raylib locally by cloning the repository:
git clone --depth=1 https://github.com/raysan5/raylib
Ensure you also have Make
installed.
-
Create a new directory for your project.
-
Inside your project directory, create two folders:
include
andlib
. -
Go to where you previously installed Raylib and navigate to the
raylib/src/
folder. -
Copy the
raylib.h
file to your project'sinclude
folder. -
Compile the library:
mingw32-make PLATFORM=PLATFORM_DESKTOP
Note: Specify the target platform accordingly.
-
The previous command generated a
libraylib.a
file. Copy it to thelib
folder in your project. -
Create a
main.c
file where you can include Raylib and start developing your game:#include "raylib.h" int main() { const int screenWidth = 800; const int screenHeight = 600; InitWindow(screenWidth, screenHeight, "Raylib basic window"); SetTargetFPS(60); while (!WindowShouldClose()) { BeginDrawing(); ClearBackground(RAYWHITE); DrawText("It works!", 20, 20, 20, BLACK); EndDrawing(); } CloseWindow(); return 0; }
At the end, your project should look something like this:
your-raylib-project
│
├─── include
│ └─── raylib.h
│
├─── lib
│ └─── libraylib.a
│
└─── main.c
To compile your project and generate an executable file, all you need to do is run this command:
gcc main.c -o app.exe -O1 -Wall -std=c99 -Wno-missing-braces -I ./include/ -L ./lib/ -lraylib -lopengl32 -lgdi32 -lwinmm
Note: Adjust the executable name as desired with the -o
option.
And that's it. You have successfully created and compiled your first Raylib project!