This repository was archived by the owner on Dec 18, 2021. It is now read-only.
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
* raylib-phpcpp PHP bindings for [[https://github.com/raysan5/raylib/][raylib]], a simple and easy-to-use library to learn videogames programming. It's developed using [[https://github.com/CopernicaMarketingSoftware/PHP-CPP/][PHP-CPP]], so it's called raylib-phpcpp. ** Example #+BEGIN_SRC php <?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(); #+END_SRC See more [[./examples][examples]]. ** Build Run #+BEGIN_SRC shell mkdir build && cd build cmake .. make -j$(nproc) #+END_SRC Then you have ~libraylib-phpcpp.so~ in build directory. ** Mapping C to PHP - All C functions are exposed as PHP global functions, for example: | C | raylib-phpcpp | |-------------------------------+-------------------------------| | WindowShouldClose() | WindowShouldClose() | | InitWindow(800, 450, "title") | InitWindow(800, 450, "title") | - Color constants are exposed as global functions, for example: | C | raylib-phpcpp | |-----------+---------------| | LIGHTGRAY | LIGHTGRAY() | | GREEN | GREEN() | - All C enums are exposed as global constants with ~RL_~ prefix: | C | raylib-phpcpp | |----------------+-------------------| | FLAG_SHOW_LOGO | RL_FLAG_SHOW_LOGO | | KEY_COMMA | RL_KEY_COMMA | - Constructor for simple structs (struct without array and pointer members) are exposed as function, for example to create a ~Camera2D~: #+BEGIN_SRC php <?php $offset = Vector2(1, 1); $target = Vector2(0, 0); $camera = Camera2D($offset, $target, 1.0, 1.0); #+END_SRC - Accessor for struct fields are implemented as ~__get~ and ~__set~, some update operation are more cumbersome: #+BEGIN_SRC php <?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; #+END_SRC - Known name conflicts | raylib-phpcpp | PHP | |---------------+--------------| | ImageCopy | [[https://www.php.net/manual/en/book.image.php][gd extension]] | | ImageCrop | [[https://www.php.net/manual/en/book.image.php][gd 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][LICENSE]] for further details.