PHP-GLFW: An OpenGL and GLFW Extension for PHP¶
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. Bringing a whole different set of tools into the PHP world to develop graphical applications like games, scientific simulations, user interfaces, and more.
Install in 5 minutes
If you haven't installed PHP-GLFW yet, follow the installation guide for your platform.
PHP OpenGL Tutorial
Everything ready to get started? Jump right into the first chapter of the tutorial.
Checkout the API documentation for all the functions and classes available in PHP-GLFW.
Want to directly dig into example code? Check out the examples folder.
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 only 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.
- 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
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, Windows, 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:
- Includes most common matrix operations for the use case like:
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:
Some OpenGL functions can directly accept the math structs as arguments
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
PHPGL - Textures¶
PHP-GLFW supports the loading of images/textures into buffers without requiring an additional extension:
- Can load common image formats such as
gif(gd or Imagick is not required)
- Can write images/textures back to disk
Writes data into a
BufferInterfaceobject, giving full access to the bitmap from userland
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. Currently, we only support triangulated geometry and no quads.
- Can parse
- 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
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.