DEV Community

drew
drew

Posted on

Get Started With Rayex(Raylib for Elixir)

This is a getting started guide for Rayex, an Elixir implementation of the Raylib games library written in C, which you can find here.

This guide currently only works on linux, I haven't worked through the steps for mac or windows yet. I might just do separate guides for those to keep this one from getting bloated.

Some of this guide will be copied from Raylib sources and other places, primarily because I had to dig to find everything to make it work, and I wanted it all in one place so I don't have to hunt for it next time.

NOTE: Rayex is very much still being worked on and is not fully implemented.

List of things you'll need:

  • Erlang
  • Elixir
  • pkg-config
  • Raylib
  • glibc
  • clang-tools(formatter)

Instructions

Hopefully if you're wanting to do this, you already have Elixir/Erlang already installed so I won't go through that.
I used asdf to install Erlang and Elixir on Fedora, as that seems to be the easiest way to get the latest version of Elixir on linux, since most of the distros include old versions. You can use asdf on other linux distros also.

https://github.com/asdf-vm/asdf-erlang

Prerequisites

For pkg-config run these commands:

sudo apt-get update -y
sudo apt-get install -y pkg-config
Enter fullscreen mode Exit fullscreen mode

C Tools
Run these commands:

#check if Clang is installed
clang --version
# If not run this:
sudo dnf install clang
Enter fullscreen mode Exit fullscreen mode
sudo apt install cmake
sudo dnf install clang-tools-extra
Enter fullscreen mode Exit fullscreen mode

Required Libraries
Run these commands depending on your distro:

Ubuntu:

sudo apt install libasound2-dev mesa-common-dev libx11-dev libxrandr-dev libxi-dev xorg-dev libgl1-mesa-dev libglu1-mesa-dev
Enter fullscreen mode Exit fullscreen mode

Fedora:

sudo dnf install alsa-lib-devel mesa-libGL-devel libX11-devel libXrandr-devel libXi-devel libXcursor-devel libXinerama-devel libatomic
Enter fullscreen mode Exit fullscreen mode

Arch:

sudo pacman -S alsa-lib mesa libx11 libxrandr libxi libxcursor libxinerama
Enter fullscreen mode Exit fullscreen mode

Glibc:

Check if glibc is installed:

ldd --version
Enter fullscreen mode Exit fullscreen mode

if not installed, run:

## ubuntu:
sudo apt install glibc-source -y

# Fedora:
dnf install glibc
Enter fullscreen mode Exit fullscreen mode

After all that, it's time to build Raylib. I recommend using cmake as it's the easiest way, so I'll only include those instructions. If you want to do it another way, you can check out the Raylib github.

paste these into the terminal line by line:

git clone https://github.com/raysan5/raylib.git raylib
cd raylib
mkdir build && cd build
cmake -DBUILD_SHARED_LIBS=ON ..
make
sudo make install
Enter fullscreen mode Exit fullscreen mode

When you run make install, be sure to note where it installs to, you'll need it later. In my case it was installed to

usr/local/lib64
Enter fullscreen mode Exit fullscreen mode

but for you it might just be:

/usr/local/lib
Enter fullscreen mode Exit fullscreen mode

After all that, you can try one of two things: you can try to run an example, or you can add your lib to path. I'd suggest adding to path, because I tried to install this on two different linux versions(Ubuntu and Fedora) and ran into the same problem.

paste this line into terminal and replace usr/local/lib with whatever location your make install showed:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib 
Enter fullscreen mode Exit fullscreen mode

My experience was that it installed to /usr/local/lib64, so:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib64
Enter fullscreen mode Exit fullscreen mode

This only adds it for the current terminal window. You can append this command to the end of your ~/.bashrc or ~/.zshrc or other user login script, to make the change permanent.

After that, it's time for Rayex!

Fork the project:

https://github.com/shiryel/rayex
Enter fullscreen mode Exit fullscreen mode

clone your fork:

git clone https://github.com/your username/rayex.git
Enter fullscreen mode Exit fullscreen mode

cd into the rayex folder and run:

mix deps.get
iex -S mix
Enter fullscreen mode Exit fullscreen mode

This should start an iex. Then run:

# Import all modules
iex> use Rayex

# open new window
iex> init_window(200, 200, "window name")

# draw a line
iex> begin_drawing()
iex> draw_line(10, 10, 50, 51, %{r: 255, g: 161, b: 0, a: 255})
iex> end_drawing()
Enter fullscreen mode Exit fullscreen mode

Now you can try one of the 3d examples:

cd examples/3d_picking/
mix deps.get
iex -S mix
Enter fullscreen mode Exit fullscreen mode

Then in iex run:

iex> The3dPicking.run()
Enter fullscreen mode Exit fullscreen mode

you should see this:

Image of a 3d render running in Raylib

You're good to go!

Ping me on twitter @andevrs if you find any mistakes or issues, or you can message me here. Thanks!

Top comments (0)