Giter VIP home page Giter VIP logo

php-glfw's Introduction

PHP-GLFW

WebsiteGetting StartedAPI DocsExamples

A fully-featured OpenGL and GLFW extension for PHP. Batteries included 🔋!

PHP-GLFW Tests MacOS Installer Windows Build

PHP-GLFW allows you to create 2D and 3D real-time applications in PHP. Bringing a whole different set of tools into the PHP world to develop graphical applications like games, scientific simulations, user interfaces and co.

Currently supports PHP8.0, 8.1 and 8.2

What is this extension? Features 🚀

PHP-GLFW aims to be one extension containing all basics you need to start building graphical applications in PHP. That means that PHP-GLFW does NOT just provide GLFW library bindings. Instead, it also includes OpenGL bindings and a bunch of classes and helpers pretty much required for building these types of applications.

OpenGL

  • Full native support of OpenGL (4.1+ core), GPU accelerated rendering in PHP.
  • Targeting OpenGL 4.1, but it can also be built for newer versions.
  • Support for OpenGL extensions (limited).
  • Mostly mirroring the C API, adjustments were made where required or otherwise nonsensical.
  • We currently support about ~90% of the full standard, check GLSUPPORT.md

GLFW

This extension comes obviously with bindings for the amazing GLFW library. GLFW comes with great features, to name a few:

  • Multiplatform Window creation and handling. (MacOS / Window / Linux)
  • Support for multiple windows and monitors.
  • Real-time user input handling.
    • Keyboard and Mouse event handling.
    • Joystick input support.

PHPGL - Math

PHPGL is what I call the extras in this extension, aka classes and helpers additionally provided that are pretty much a requirement for these kinds of applications. PHP-GLFW comes with a mathematics library written in C, covering the most common operations required for graphical applications.

  • Supported structs: Vec2, Vec3, Vec4, Mat4 and Quat.
  • Includes most common matrix operations for the use case like: lookAt, perspective, inverse, rotate etc..

Having this integrated into the extension comes with a bunch of advantages:

  • It's fast.
  • low memory footprint.
  • The math structures have overloaded operators, so you can write things like:
    use GL\Math\Vec2;
    $v3 = Vec2(15, -5) + Vec2(42, 7); // returns Vec2(54, 2)
  • Some OpenGL functions can directly accept the math structs as arguments.
  1. Read more about math functions

PHPGL - Buffers

This extension also contains a collection of buffer objects that internally hold data in native types.

  • Can handle large arrays of data.
  • Low memory footprint and very fast.
  • Data is stored internally to be directly uploadable to the GPU.
  1. Read more about the buffers

PHPGL - Textures

PHP-GLFW supports the loading of images/textures into buffers without requiring an additional extension:

  • can load common image formats as jpg, png, tga, bmp, gif. (gd or Imagick is not required)
  • can write images/textures back to disk.
  • writes data into a BufferInterface object giving full access to the bitmap from userland.
  1. Read more about texture loading

PHPGL - Geometry

PHP-GLFW also comes with a .obj wavefront file loader. This allows you to load and parse .obj files. We also provide a few helpers to generate tangent and bitangent vectors for the loaded geometry directly. Right now, we only support triangulated geometry and no quads.

  • can parse .obj and .mtl files.
  • can generate the normal, tangent, and bitangent vectors for the loaded geometry on the fly.
  • allows you to extract separate meshes and groups from the loaded geometry.
  • can group the vertices by their material.
  • can reindex extracted meshes to reduce the number of vertices.
  1. Read more about geometry loading

How are the bindings achieved?

Instead of porting function by function manually, PHP-GLFW parses the OpenGL specs to generate most of this C extension. Adjustments are made manually where necessary.

Documentation 📚

  1. Full Documentation
  2. Getting Started Guide
  3. User Guide
  4. API Docs

Examples

glfw-previews

If you want to check out the code straight away, check out the examples directory.

Installation

Please see the complete detailed installation guide here: Installation

PHP Version: >= 8.0 While I would love to support older PHP builds, it was just not feasable for this extension.

MacOS

Installer

There is a simple installer script you can use to install php-gflw:

php -r "copy('https://raw.githubusercontent.com/mario-deluna/php-glfw/master/install/macos-installer.php', 'phpglfw-installer.php');" && php phpglfw-installer.php

Thats it, if you see the text "Installation finished!" you should be ready to go!

Manual installation

If you prefer a manual approach, ensure you have installed the php-dev, git and cmake packages. They are required!

git clone https://github.com/mario-deluna/php-glfw
cd php-glfw
sudo phpize && ./configure --enable-glfw
sudo make install

make sure to add glfw.so in the php.ini file:

extension="glfw.so"

Linux

cmake is required for the installation. You can skip the first step if it's already installed. Also, make sure that you install the php-dev package for example, php8.1-dev.

sudo apt install -y cmake git 
git clone https://github.com/mario-deluna/php-glfw
cd php-glfw
sudo phpize && ./configure --enable-glfw
sudo make install

make sure to add glfw.so in the php.ini file:

extension="glfw.so"

Stubs (IDE Support)

As this is a PHP extension, your editor / IDE does not support auto-completion and doc lookups without some help. We created a composer package you can include as a dev dependency to have full support:

composer require --dev phpgl/ide-stubs

Credits

License

Please see License File for more information.

php-glfw's People

Contributors

mario-deluna 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.