Skip to content
This repository has been archived by the owner on Dec 18, 2021. It is now read-only.
/ raylib-phpcpp Public archive

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

License

Notifications You must be signed in to change notification settings

oraoto/raylib-phpcpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published