Giter VIP home page Giter VIP logo

raylib-phpcpp's Introduction

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.

raylib-phpcpp's People

Contributors

oraoto avatar

Stargazers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.