oraoto / raylib-phpcpp

PHP bindings for raylib, a simple and easy-to-use library to enjoy videogames programming

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

raylib-phpcpp

PHP bindings for raylib, a simple and easy-to-use library to learn videogames programming.

It’s developed using PHP-CPP, so it’s called raylib-phpcpp.

Example

<?php

InitWindow(800, 450, "raylib [core] example - basic window");

SetTargetFPS(60);

while (!WindowShouldClose())
{
    BeginDrawing();
    ClearBackground(RAYWHITE());
    DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY());
    EndDrawing();
}
CloseWindow();

See more examples.

Build

Run

mkdir build && cd build
cmake ..
make -j$(nproc)

Then you have libraylib-phpcpp.so in build directory.

Mapping C to PHP

  • All C functions are exposed as PHP global functions, for example:
    Craylib-phpcpp
    WindowShouldClose()WindowShouldClose()
    InitWindow(800, 450, “title”)InitWindow(800, 450, “title”)
  • Color constants are exposed as global functions, for example:
    Craylib-phpcpp
    LIGHTGRAYLIGHTGRAY()
    GREENGREEN()
  • All C enums are exposed as global constants with RL_ prefix:
    Craylib-phpcpp
    FLAG_SHOW_LOGORL_FLAG_SHOW_LOGO
    KEY_COMMARL_KEY_COMMA
  • Constructor for simple structs (struct without array and pointer members) are exposed as function, for example to create a Camera2D:
    <?php
    
    $offset = Vector2(1, 1);
    $target = Vector2(0, 0);
    $camera = Camera2D($offset, $target, 1.0, 1.0);
        
  • Accessor for struct fields are implemented as __get and __set, some update operation are more cumbersome:
    <?php
    
    $v = Vector2(1, 2);
    // $v->x += 1; doesn't work
    $v->x = $v->x + 1;
    
    $camera = Camera2D(Vector2(1, 1), Vector2(0, 0), 1.0, 1.0);
    // $camera->target->x = 1; // doesn't work
    $target = $camera->target;
    $target->x = 1;
    $camera->target = $target;
        
  • Known name conflicts
    raylib-phpcppPHP
    ImageCopygd extension
    ImageCropgd extension

    You should disable gd extension while exploring raylib :)

  • API differences

    TBD.

    Function
    GetDroppedFiles
    ImageExtractPalette
    LoadModelAnimations
    LoadMeshes
    LoadMaterials

Completeness

Most functions and features are supported.

For most file and text functions, you can use counterparts in PHP.

License

raylib-phpcpp is licensed under an unmodified zlib/libpng license, which is an OSI-certified, BSD-like license that allows static linking with closed source software. Check LICENSE for further details.

About

PHP bindings for raylib, a simple and easy-to-use library to enjoy videogames programming

License:zlib License


Languages

Language:C++ 68.9%Language:PHP 28.4%Language:Objective-C 1.9%Language:CMake 0.8%