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.


Create Games for Windows, Linux and Web with Raylib C/C++

🔊 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

  1. Open your browser
  2. Access the address: https://github.com/raysan5/raylib
  3. Select and click on Releases on the right side of the screen
  4. Scroll down the course and download the version: raylib_installer_v4.2.mingw.exe
  5. After the download is finished, double-click on the file, click on Allow
  6. Install and Finish
  7. Open the shortcut: [Notepad++ for Raylib]
  8. 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

Basic car

bg.png

Background for the game


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.


Useful links



gamedev cpp raylib clanguage


Share


YouTube channel

Subscribe


Marcos Oliveira

Marcos Oliveira

Software developer
https://github.com/terroo

Related articles