PHPackages                             microscrap/glfw - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. microscrap/glfw

ActiveLibrary[Framework](/categories/framework)

microscrap/glfw
===============

LibGLFW Bindings for The PHP GLFW Extension

0.5.1(yesterday)01↑2900%1MITPHP ^8.3

Since Jul 19Compare

[ Source](https://github.com/microscrap/glfw)[ Packagist](https://packagist.org/packages/microscrap/glfw)[ Docs](https://dosr.projectsaturnstudios.com)[ RSS](/packages/microscrap-glfw/feed)WikiDiscussions Synced today

READMEChangelogDependencies (1)Versions (3)Used By (1)

microscrap/glfw — LibGLFW bindings for PHP
==========================================

[](#microscrapglfw--libglfw-bindings-for-php)

PHP library that wraps the [**glfw**](https://github.com/php-io-extensions/glfw) extension with global helpers, enums, and data objects. Every helper delegates to a static wrapper class under `Microscrap\Bindings\GLFW`.

The package covers the entire extension surface (124 GLFWAPI methods + a small OpenGL convenience set across 8 extension classes): init, error, windows, monitors, input/joysticks/gamepads, context, Vulkan, and minimal GL clear/viewport helpers for visual proofs.

Highlights
----------

[](#highlights)

- Two calling styles — exact C names (`glfwCreateWindow(...)`) or static wrapper classes (`Window::createWindow(...)`)
- Opaque GLFW handles wrapped in typed `final readonly` data objects (`GlfwWindow`, `GlfwMonitor`, `GlfwCursor`)
- Enum layer transcribed from glfw3.h — keys, hints, actions, joysticks/gamepads, context/client API tokens, plus a few GL enums used by the convenience layer
- C-style error handling: no exceptions in `src/`; details via `glfwGetError()`
- Coverage drift guard: a Pest test reflects the extension and fails if any extension method lacks a wrapper method or helper function

Requirements
------------

[](#requirements)

- PHP 8.3+
- **ext-glfw** ^0.5.0 — install from [php-io-extensions/glfw](https://github.com/php-io-extensions/glfw)

Installation
------------

[](#installation)

Confirm **ext-glfw** is loaded:

```
php -m | grep glfw
```

```
composer require microscrap/glfw
```

Composer autoloads all helper files in `src/Helpers/`, registering the global `glfw*` / `gl*` functions when the package is installed. Helpers are only defined if the name is not already taken (`function_exists` guard).

The two calling styles
----------------------

[](#the-two-calling-styles)

**C-ish** — global functions with exact GLFW C names:

```
use Microscrap\Bindings\GLFW\Enums\TrueFalse;
use Microscrap\Bindings\GLFW\Enums\WindowHint;

glfwInit();
glfwWindowHint(WindowHint::GLFW_VISIBLE, TrueFalse::GLFW_FALSE->value);
$window = glfwCreateWindow(640, 480, 'hello');
glfwDestroyWindow($window);
glfwTerminate();
```

**OO-ish** — static wrapper classes, same behavior:

```
use Microscrap\Bindings\GLFW\Init;
use Microscrap\Bindings\GLFW\Window;
use Microscrap\Bindings\GLFW\Enums\TrueFalse;
use Microscrap\Bindings\GLFW\Enums\WindowHint;

Init::init();
Window::windowHint(WindowHint::GLFW_VISIBLE, TrueFalse::GLFW_FALSE->value);
$window = Window::createWindow(640, 480, 'hello');
Window::destroyWindow($window);
Init::terminate();
```

Helpers never touch the extension directly; they delegate one-to-one to the wrapper classes, which are the only layer calling `Glfw\GLFW\*`. Both styles accept and return the same data objects, and every flag/enum parameter takes `EnumType|int`.

### Name transforms

[](#name-transforms)

- Wrapper methods drop the `glfw` prefix: `glfwCreateWindow` → `Window::createWindow()`.
- The `GL` class drops the `gl` prefix: `glClearColor` → `GL::clearColor()`.
- Helpers use the exact C / extension method name (`glfwCreateWindow()`, `glClear()`).

> **macOS note:** data objects are named `GlfwWindow` / `GlfwMonitor` / `GlfwCursor` (not `GLFWwindow`) so they do not collide with the extension classes `GLFWWindow` / `GLFWMonitor` on case-insensitive filesystems.

Wrapper classes
---------------

[](#wrapper-classes)

ClassWrapsMethodsSubsystem`Init``Glfw\GLFW\GLFW`10init/terminate, version, platform, error callback`Error``GLFWError`1`glfwGetError``Window``Window\GLFWWindow`47windows, hints, attributes, event loop`Monitor``Monitor\GLFWMonitor`15monitors, video modes, gamma`Input``Input\GLFWInput`40keys, mouse, cursors, joystick/gamepad, clipboard, time`Context``Context\GLFWContext`6make current, swap, proc address`Vulkan``Vulkan\GLFWVulkan`5Vulkan support + surface`GL``GL\GLFWGL`8minimal OpenGL for visual demosData objects live under `Microscrap\Bindings\GLFW\DataObjects`. Enums live under `Microscrap\Bindings\GLFW\Enums` (case names match the C macros exactly; `TrueFalse` holds `GLFW_TRUE` / `GLFW_FALSE` because `Bool` is reserved in PHP).

Examples
--------

[](#examples)

### Hidden window (init smoke)

[](#hidden-window-init-smoke)

```
use Microscrap\Bindings\GLFW\Enums\TrueFalse;
use Microscrap\Bindings\GLFW\Enums\WindowHint;

glfwInit();
glfwWindowHint(WindowHint::GLFW_VISIBLE, TrueFalse::GLFW_FALSE->value);

$window = glfwCreateWindow(320, 240, 'demo');
if (is_null($window)) {
    [$code, $description] = glfwGetError();
    throw new RuntimeException($description ?: "glfw error {$code}");
}

while (! glfwWindowShouldClose($window)) {
    glfwPollEvents();
    glfwSetWindowShouldClose($window, TrueFalse::GLFW_TRUE->value);
}

glfwDestroyWindow($window);
glfwTerminate();
```

### OpenGL clear (needs a display)

[](#opengl-clear-needs-a-display)

```
use Microscrap\Bindings\GLFW\Context;
use Microscrap\Bindings\GLFW\GL;
use Microscrap\Bindings\GLFW\Init;
use Microscrap\Bindings\GLFW\Window;
use Microscrap\Bindings\GLFW\Enums\ClearBufferMask;

Init::init();
$window = Window::createWindow(640, 480, 'clear');
Context::makeContextCurrent($window);

GL::clearColor(0.1, 0.2, 0.3, 1.0);
GL::clear(ClearBufferMask::GL_COLOR_BUFFER_BIT);
Context::swapBuffers($window);

Window::destroyWindow($window);
Init::terminate();
```

Error handling
--------------

[](#error-handling)

Nothing in `src/` throws. The package keeps GLFW's C conventions:

- creation functions return `null` on failure (`?GlfwWindow`, `?GlfwCursor`, …)
- call `glfwGetError()` for `[code, description]`

Note: the underlying extension itself may throw `RuntimeException` from a handful of calls (e.g. failed `glfwCreateWindow`). Those propagate as-is.

Testing
-------

[](#testing)

```
./vendor/bin/pest
```

- `tests/Unit` runs without the extension: coverage drift guard (against a committed 0.5.0 method snapshot), style audit (no class constants, no throws, guarded helpers, backed enums, uppercase cases).
- `tests/Feature` is gated on `extension_loaded('glfw')` and smokes init/version/platform.

License
-------

[](#license)

MIT. See [LICENSE](LICENSE).

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance100

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10563160?v=4)[Angel Gonzalez](/maintainers/projectsaturnstudios)[@projectsaturnstudios](https://github.com/projectsaturnstudios)

---

Tags

frameworkglfwscrapyard-io

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/microscrap-glfw/health.svg)

```
[![Health](https://phpackages.com/badges/microscrap-glfw/health.svg)](https://phpackages.com/packages/microscrap-glfw)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
