mario-deluna / php-glfw

πŸͺA fully-featured OpenGL and GLFW extension for PHP. πŸ”‹Batteries included (Math Functions, Texture Loaders, etc..)
http://phpgl.net/
Other
391 stars 14 forks source link
2d 3d game game-development glfw opengl php php-extension rendering

PHP-GLFW

LICENSE PHP Versions Supported GitHub tag issues - php-glfw

PHP-GLFW Tests MacOS Installer Windows Build

Website β€’ Getting Started β€’ API Docs β€’ Examples

A fully-featured OpenGL and GLFW extension for PHP. Batteries included πŸ”‹!

PHP-GLFW allows you to create 2D and 3D real-time applications in PHP. It introduces a whole new set of tools for PHP developers to build graphical applications like games, scientific simulations, user interfaces, and much more.

3D Rendering in PHP

Currently supports PHP8.x

What is this extension? Features πŸš€

PHP-GLFW aims to be a complete solution containing everything you need to start building graphical applications in PHP. It doesn't just provide GLFW library bindings, but also includes OpenGL bindings and a set of essential classes and helpers.

OpenGL

GLFW

This extension includes bindings for the powerful GLFW library, offering a range of amazing features, such as:

Vector Graphics API

PHP-GLFW includes a vector graphics API that allows you to draw in a HTML canvas-like manner in PHP. Its uses the same OpenGL context internally allowing you to build complex rendering pipelines utilizing both the vector graphics API and the more low-level OpenGL API.

PHP Vector Graphics Rendering Library

  1. Read more about the Vector Graphics API

PHPGL - Math

PHP-GLFW comes with a built-in mathematics library, written in C and optimized for graphical applications.

PHP Vector Math Library

Integration into the extension offers several advantages:

  1. Read more about math functions

PHPGL - Buffers

This extension also includes a set of buffer objects that internally hold data in native types.

  1. Read more about the buffers

PHPGL - Textures

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

  1. Read more about texture loading

PHPGL - Geometry

PHP-GLFW comes with a .obj wavefront file loader, allowing you to load and parse .obj files. It also provides helpers to generate tangent and bitangent vectors for the loaded geometry. Currently, only triangulated geometry is supported, with no support for quads.

  1. Read more about geometry loading

How are the bindings achieved?

PHP-GLFW parses the OpenGL specs to generate most of the C extension, instead of porting functions manually. Manual adjustments are made where necessary.

Documentation πŸ“š

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

Examples

glfw-previews

Explore the examples directory to dive into the code.

FlappyPHPant

A very simple Flappy Bird-like game written in PHP.

FlappyPHPant 2D PHP Game

https://github.com/phpgl/flappyphpant

php-chip8

Yet another CHIP-8 emulator, but in PHP!

A CHIP-8 Game Emulator written in PHP

https://github.com/mario-deluna/php-chip8

PHP-Towerdense Game

We are currently developing a 3D game entirely built with PHP, leveraging the power of PHP-GLFW. The game, named PHP-TowerDefense, is open-source and serves as a showcase for the capabilities of PHP-GLFW. Although the game is in active development, it is not yet ready for release.

PHP-TowerDefense Screenshot

Check out the game's repository on GitHub for more information and to follow its progress: https://github.com/phpgl/php-towerdefense

php-pong

Classic Pong game programmed with pure OpenGL wrapped in OOP code.

Classic Pong Game written in PHP

https://github.com/medilies/php-pong

Installation

Please refer to the comprehensive installation guide here: Installation

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

MacOS

Installer

You can use a simple installer script to install PHP-GLFW:

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

Once you see "Installation finished!", you're ready to go!

Manual installation

For 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

Don't forget 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.