Create Games for Windows, Linux and Web with Raylib C/C++
Despite having native support for C/C++, it is possible to use it in other programming languages such as: Lua, Golang, C#, Python, PHP, Java and among others.
🔊 Raylib is a library used for game development, however, there are other areas of application. Despite having native support for C/C++, it is possible to use it in other programming languages such as: Lua, Golang, C#, Python, PHP , Java and among others.
Some features of Raylib are:
- It does not have a clickable interface, it is a library for programmers who like to write code;
- Multiplatform available for: Windows, GNU/Linux, macOS, Android, HTML5 and among others;
- Written in C99 ;
- Supports 2D and 3D graphics;
- It’s easy, simple and differentiated!
Installation
Windows
- Open your browser
- Access the address: https://github.com/raysan5/raylib
- Select and click on
Releases
on the right side of the screen - Scroll down the course and download the version: raylib_installer_v4.2.mingw.exe
- After the download is finished, double-click on the file, click on Allow
- Install and Finish
- Open the shortcut: [Notepad++ for Raylib]
- As the example will already be opened, press
F6
and then press [OK] to compile
GNU/Linux
Dependencies:
# ubuntu
sudo apt install libasound2-dev mesa-common-dev libx11-dev libxrandr-dev libxi-dev xorg-dev libgl1-mesa-dev libglu1-mesa-dev
# fedora
sudo dnf install alsa-lib-devel mesa-libGL-devel libX11-devel libXrandr-devel libXi-devel libXcursor-devel libXinerama-devel libatomic
# Arch Linux
sudo pacman -S alsa-lib mesa libx11 libxrandr libxi libxcursor libxinerama
For more information click here.
Installing Raylib:
git clone https://github.com/raysan5/raylib
cd raylib
mkdir build && cd build
cmake -DBUILD_SHARED_LIBS=ON ..
make up
sudo make install
sudo cp /usr/local/lib/libraylib.so.420 /usr/lib/
Now you can remove the cloned directory:
cd ../.. && rm -rf raylib
Copy this example:
main.cpp
#include "raylib.h"
int main(){
InitWindow(800, 450, "raylib [core] example - basic window");
while (!WindowShouldClose()){
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
EndDrawing();
}
CloseWindow();
return 0;
}
Compile:
g++ main.cpp -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
Code example 2
main.cpp
namespace ray {
#include <raylib.h>
}
int main(){
ray::InitWindow(1280, 720, "Getting started with Raylib");
ray::Texture sprite, bg;
sprite = ray::LoadTexture("./sprite.png");
bg = ray::LoadTexture("./bg.png");
float posx = -sprite.width;
while( !ray::WindowShouldClose() ){
posx += 0.9f;
if( posx > 1280 ){
posx = -sprite.width;
}
ray::BeginDrawing();
ray::ClearBackground(ray::WHITE);
ray::DrawText("First steps with Raylib", 50, 100, 50, ray::BLACK);
ray::DrawTexture(bg, 0, 0, ray::WHITE);
ray::DrawTexture(sprite, posx, 630 - sprite.height, ray::WHITE);
ray::EndDrawing();
}
ray::CloseWindow();
return 0;
}
Images used in the code example 2
sprite.png
bg.png
Watch the video
Note: The video is in Portuguese, but it is possible to follow the steps described in this article and the development from scratch of the code used as an example.
Comments