Llibreria raylib (videojocs) a la Raspberry Pi

De Wikijoan
Dreceres ràpides: navegació, cerca

Contingut

Instal.lació

He instal.lat la llibreria raylib en una Raspberry Pi 3 i he fet les primeres proves.

git clone https://github.com/raysan5/raylib.git
sudo apt install libopenal1 libopenal-dev libglfw3
#maybe libglfw3 can be skipped since we are using GLES
cd raylib/src/

make PLATFORM=PLATFORM_RPI
sudo make install

Sense fer cap canvi en el Makefile compila bé, però després no troba una llibreria.

O sigui que faig en el Makefile el canvi que es proposa:

# Use cross-compiler for PLATFORM_RPI
ifeq ($(PLATFORM),PLATFORM_RPI)
    RPI_CROSS_COMPILE ?= NO
    RPI_TOOLCHAIN ?=
    RPI_TOOLCHAIN_SYSROOT ?=
endif

compila bé el Make, però quan vull fer sudo make install busca la llibreria estàtica a /home/pi/raylib/release/libs/linux en comptes de /home/pi/raylib/release/libs/rpi, que és on realment està. Per tant, la copio allà on es pensa que està, i ja funcionarà tot:

$ cp /home/pi/raylib/release/libs/rpi/libraylib.a /home/pi/raylib/release/libs/linux
sudo make install

This installs the static library and headerfiles in /usr/local/lib and /usr/local/include.

So to test the installation I just copied out one of the examples and checked what options was needed to compile it.

$ gcc core_basic_window.c -L/opt/vc/lib/ -lraylib -lbrcmGLESv2 -lbrcmEGL -lpthread -lrt -lm -lbcm_host -lopenal

this created the file a.out which I ran with "./a.out"

PS: Some examples also need the "-std=c99" option.
PPS: Older versions of raspbian can probably remove the "brcm" letters from the library names, I think they came in Stretch. Check your "/opt/vc/lib" directory.

(ha funcionat)

Enllaç directe de descàrrega del codi:

També compila l'exemple bàsic amb C++:

$ g++ core_basic_window.cpp -L/opt/vc/lib/ -lraylib -lbrcmGLESv2 -lbrcmEGL -lpthread -lrt -lm -lbcm_host -lopenal -o core_basic_window

I també he provat i han funcionat els exemples:

Exemple bàsic: core_basic_window.c

/*******************************************************************************************
*
*   raylib [core] example - Basic window
*
*   Welcome to raylib!
*
*   To test examples, just press F6 and execute raylib_compile_execute script
*   Note that compiled executable is placed in the same folder as .c file
*
*   You can find all basic examples on C:\raylib\raylib\examples folder or
*   raylib official webpage: www.raylib.com
*
*   Enjoy using raylib. :)
*
*   This example has been created using raylib 1.0 (www.raylib.com)
*   raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
*   Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
*
********************************************************************************************/

#include "raylib.h"

int main()
{
    // Initialization
    //--------------------------------------------------------------------------------------
    int screenWidth = 800;
    int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
    
    SetTargetFPS(60);
    //--------------------------------------------------------------------------------------

    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        // Update
        //----------------------------------------------------------------------------------
        // TODO: Update your variables here
        //----------------------------------------------------------------------------------

        // Draw
        //----------------------------------------------------------------------------------
        BeginDrawing();

            ClearBackground(RAYWHITE);

            DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);

        EndDrawing();
        //----------------------------------------------------------------------------------
    }

    // De-Initialization
    //--------------------------------------------------------------------------------------   
    CloseWindow();        // Close window and OpenGL context
    //--------------------------------------------------------------------------------------

    return 0;
}

Instal.lació a Linux

$ sudo apt install build-essential git

$ sudo apt install libasound2-dev mesa-common-dev libx11-dev libxrandr-dev libxi-dev xorg-dev libgl1-mesa-dev libglu1-mesa-dev

You can compile three different types of raylib library:

Nosaltres fem l'opció estàndar, que és la dynamic shared library.

$ git clone https://github.com/raysan5/raylib.git raylib
$ cd raylib/src/
$ make PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=SHARED # To make the dynamic shared version. - Recommended
$ sudo make install RAYLIB_LIBTYPE=SHARED # Dynamic shared version

Per muntar tots els exemples que estan dins la carpeta examples/:

$ cd raylib/examples
$ make PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=SHARED

i es compilen tots els exemples (es poden fer coses xules).

A more detailed command for the OpenGL ES GRAPHICS variant on Ubuntu 16.04 is:

$ make  PLATFORM=PLATFORM_DESKTOP  GRAPHICS=GRAPHICS_API_OPENGLES_20 RAYLIB_LIBTYPE=SHARED USE_EXTERNAL_GLFW=TRUE \
    CFLAGS="-fPIC -I/usr/include/GL" LDFLAGS='-L/usr/local/lib/raysan5 -lGLESv2 -lglfw3'
To compile just one specific example, add flags as needed:

make core/core_basic_window PLATFORM=PLATFORM_DESKTOP

To force recompile one example:

make core/core_basic_window PLATFORM=PLATFORM_DESKTOP -B

I també compilo tots els jocs:

$ cd raylib/games
$ make PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=SHARED

Per compilar un exemple concret, per exemple el tetris:

$ gcc -o tetris tetris.c -O1 -s -Wall -std=c99 -D_DEFAULT_SOURCE -Wno-missing-braces -D_DEFAULT_SOURCE -I. -I../release/include -I../src -I../src/external -L. -L../release/libs/linux -L../src  -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 -DPLATFORM_DESKTOP

Fullscreen

src/core.c, a la línia 285:

static bool fullscreen = true;             // Fullscreen mode (useful only for PLATFORM_DESKTOP)

Hem de tornar a compilar tots els projectes, i ara per defecte, a Linux/Ubuntu, tots els exemples i games ja funcionen a fullscreen. (A la RPi, per defecte ja tots els exemples estaven a fullscreen).


creat per Joan Quintana Compte, maig 2018

Eines de l'usuari
Espais de noms
Variants
Accions
Navegació
Institut Jaume Balmes
Màquines recreatives
CNC
Informàtica musical
joanillo.org Planet
Eines