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.
Currently supports PHP8.x
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.
This extension includes bindings for the powerful GLFW library, offering a range of amazing features, such as:
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-GLFW comes with a built-in mathematics library, written in C and optimized for graphical applications.
Vec2
, Vec3
, Vec4
, Mat4
, and Quat
lookAt
, perspective
, inverse
, rotate
, and moreIntegration into the extension offers several advantages:
use GL\Math\Vec2;
$v3 = Vec2(15, -5) + Vec2(42, 7); // returns Vec2(57, 2)
This extension also includes a set of buffer objects that internally hold data in native types.
PHP-GLFW supports the loading of images/textures into buffers without requiring an additional extension:
jpg
, png
, tga
, bmp
, and gif
(gd or Imagick is not required)BufferInterface
object, providing full access to the bitmapPHP-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.
.obj
and .mtl
filesPHP-GLFW parses the OpenGL specs to generate most of the C extension, instead of porting functions manually. Manual adjustments are made where necessary.
Explore the examples directory to dive into the code.
A very simple Flappy Bird-like game written in PHP.
https://github.com/phpgl/flappyphpant
Yet another CHIP-8 emulator, but in PHP!
https://github.com/mario-deluna/php-chip8
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.
Check out the game's repository on GitHub for more information and to follow its progress: https://github.com/phpgl/php-towerdefense
Classic Pong game programmed with pure OpenGL wrapped in OOP code.
https://github.com/medilies/php-pong
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.
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!
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"
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"
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
Please see License File for more information.