Docs (production): ScrapyardIO · microscrap/open-gl 0.7.x
PHP library that wraps the open-gl extension (ext-opengl) with global helpers, enums, and a static wrapper class. Every helper delegates to Microscrap\Bindings\OpenGL\GL, which is the only layer that calls Opengl\GL\GL.
Token constants from the OpenGL SDK (GL_COLOR_BUFFER_BIT, …) live here as backed PHP enums — the native extension does not expose them.
This is the bindings package — not the native extension. Ecosystem docs: 0.7.x.
- Two calling styles — exact C names (
glClearColor(...)) or static wrapper (GL::clearColor(...)) - Named objects stay as extension DTOs (
Opengl\GL\GlBuffer,GlTexture,GlShader,GlProgram) with publicfd - Enum layer transcribed from the OpenGL SDK /
gl.hfor the slice-1 API surface - C-style error handling: no exceptions in
src/; details viaglGetError() - Coverage drift + style audit Pest guards keep the wrap 1:1 with the extension
- PHP 8.3+
- ext-opengl ^0.7.0 — install from php-io-extensions/open-gl
- A current OpenGL context from glfw or sdl3 before draw calls succeed
Confirm ext-opengl is loaded:
php -m | grep openglcomposer require microscrap/open-glComposer autoloads helper files in src/Helpers/, registering global gl* functions when the package is installed. Helpers are only defined if the name is not already taken (function_exists guard).
Note:
microscrap/glfwalso defines a small subset ofgl*helpers for visual proofs. Prefer this package as the canonical OpenGL binding; load order decides which definition wins under the guard.
C-ish — global functions with exact OpenGL C / extension names:
use Microscrap\Bindings\OpenGL\Enums\ClearBufferMask;
use Microscrap\Bindings\OpenGL\Enums\StringName;
glClearColor(0.1, 0.1, 0.12, 1.0);
glClear(ClearBufferMask::GL_COLOR_BUFFER_BIT);
echo glGetString(StringName::GL_VERSION);OO-ish — static wrapper class, same behavior:
use Microscrap\Bindings\OpenGL\GL;
use Microscrap\Bindings\OpenGL\Enums\ClearBufferMask;
use Microscrap\Bindings\OpenGL\Enums\StringName;
GL::clearColor(0.1, 0.1, 0.12, 1.0);
GL::clear(ClearBufferMask::GL_COLOR_BUFFER_BIT);
echo GL::getString(StringName::GL_VERSION);Helpers never touch the extension directly; they delegate one-to-one to GL, which is the only layer calling Opengl\GL\GL. Flag/enum parameters take EnumType|int.
- Wrapper methods drop the
glprefix:glClearColor→GL::clearColor(). - Helpers use the exact extension method name (
glClearColor(),glUseProgramNone()).
| Class | Wraps | Methods |
|---|---|---|
GL |
Opengl\GL\GL |
full slice-1 draw API (state, immediate mode, buffers, textures, shaders/programs, draw) |
| Enum | Purpose |
|---|---|
ClearBufferMask |
glClear bitfield |
EnableCap |
glEnable / glDisable |
StringName |
glGetString |
GetPName |
glGetIntegerv |
PrimitiveMode |
glBegin / glDrawArrays |
MatrixMode |
glMatrixMode |
BufferTarget / BufferUsage |
buffer binds & uploads |
TextureTarget / TextureParameterName / TextureParameter |
texture state |
ShaderType |
glCreateShader |
ErrorCode |
glGetError values |
composer install --ignore-platform-req=ext-opengl
./vendor/bin/pestCI runs the same suite on PHP 8.3–8.5 (coverage uses the committed extension method snapshot when ext-opengl is not loaded).
MIT — see LICENSE.