Getting Started
Installation
macOS (Homebrew + PHP 8.5)
# Install dependencies
brew install glfw glslang spirv-cross vulkan-loader ffmpeg
# Build the extension
cd php-vio
make clean; phpize --clean; phpize && \
./configure --enable-vio \
--with-glfw --with-glslang --with-spirv-cross \
--with-vulkan --with-ffmpeg --with-metal && \
make -j$(sysctl -n hw.ncpu)
# Install
sudo make installmacOS (Laravel Herd / PHP 8.4)
make clean
/usr/local/Cellar/php@8.4/8.4.19/bin/phpize --clean
/usr/local/Cellar/php@8.4/8.4.19/bin/phpize && \
./configure --enable-vio \
--with-glfw --with-glslang --with-spirv-cross \
--with-vulkan --with-ffmpeg --with-metal \
--with-php-config=/usr/local/Cellar/php@8.4/8.4.19/bin/php-config && \
make -j$(sysctl -n hw.ncpu)Linux (Ubuntu / Debian)
# Install dependencies
sudo apt install php-dev libglfw3-dev glslang-dev libvulkan-dev \
libavcodec-dev libavformat-dev libavutil-dev libswscale-dev \
spirv-cross libspirv-cross-c-shared-dev
# Build (no --with-metal on Linux)
phpize && \
./configure --enable-vio \
--with-glfw --with-glslang --with-spirv-cross \
--with-vulkan --with-ffmpeg && \
make -j$(nproc)
sudo make installWindows
Requires PHP SDK + Visual Studio Build Tools. Place precompiled dependencies in deps/.
cd C:\php-sdk\phpdev\vs17\x64\php-src\ext\vio
:: Full build (with DirectX 11 & 12)
configure --enable-vio --with-glfw=C:\deps\glfw ^
--with-vulkan=C:\VulkanSDK\1.3.xxx ^
--with-glslang=C:\deps\glslang ^
--with-spirv-cross=C:\deps\spirv-cross ^
--with-ffmpeg=C:\deps\ffmpeg ^
--with-d3d11 --with-d3d12
nmakeD3D11 and D3D12 are enabled by default on Windows when the system headers are available (part of the Windows SDK). They require d3d11.lib/d3d12.lib, dxgi.lib, d3dcompiler.lib, and dxguid.lib.
Enable the Extension
Add to your php.ini:
extension=vioVerify:
php -m | grep vioMinimal Build
All features are optional. A minimal build with just OpenGL windowing:
phpize && ./configure --enable-vio --with-glfw && makeFeatures not compiled in are simply unavailable at runtime – no errors, just false returns from unsupported functions.
Your First Window
<?php
// Create a window with OpenGL backend
$ctx = vio_create("opengl", [
"width" => 800,
"height" => 600,
"title" => "Hello php-vio",
]);
// Main loop
while (!vio_should_close($ctx)) {
vio_begin($ctx);
vio_clear($ctx, 0.1, 0.1, 0.15, 1.0);
// Draw a red rectangle
vio_rect($ctx, 100, 100, 200, 150, [
"color" => 0xFFFF0000,
]);
// Flush 2D batch
vio_draw_2d($ctx);
vio_end($ctx);
vio_poll_events($ctx);
// Close on Escape
if (vio_key_pressed($ctx, VIO_KEY_ESCAPE)) {
vio_close($ctx);
}
}
vio_destroy($ctx);Run it:
php -d extension=modules/vio.so hello.phpDrawing a 3D Triangle
<?php
$ctx = vio_create("opengl", [
"width" => 800, "height" => 600,
"title" => "3D Triangle",
]);
// Vertex data: position (xyz) + color (rgb)
$vertices = [
0.0, 0.5, 0.0, 1.0, 0.0, 0.0, // top (red)
-0.5, -0.5, 0.0, 0.0, 1.0, 0.0, // left (green)
0.5, -0.5, 0.0, 0.0, 0.0, 1.0, // right (blue)
];
$mesh = vio_mesh($ctx, [
"vertices" => $vertices,
"layout" => [VIO_FLOAT3, VIO_FLOAT3],
"topology" => VIO_TRIANGLES,
]);
$shader = vio_shader($ctx, [
"vertex" => "
#version 450
layout(location=0) in vec3 aPos;
layout(location=1) in vec3 aColor;
layout(location=0) out vec3 vColor;
void main() {
gl_Position = vec4(aPos, 1.0);
vColor = aColor;
}
",
"fragment" => "
#version 450
layout(location=0) in vec3 vColor;
layout(location=0) out vec4 fragColor;
void main() {
fragColor = vec4(vColor, 1.0);
}
",
]);
$pipeline = vio_pipeline($ctx, ["shader" => $shader]);
while (!vio_should_close($ctx)) {
vio_begin($ctx);
vio_clear($ctx, 0.1, 0.1, 0.15, 1.0);
vio_bind_pipeline($ctx, $pipeline);
vio_draw($ctx, $mesh);
vio_end($ctx);
vio_poll_events($ctx);
if (vio_key_pressed($ctx, VIO_KEY_ESCAPE)) {
vio_close($ctx);
}
}
vio_destroy($ctx);The shaders are #version 450 GLSL with explicit layout(location = …) qualifiers: php-vio compiles them to SPIR-V and cross-compiles to whatever the backend speaks (GLSL, HLSL, MSL), so the same source runs on OpenGL, Direct3D and Metal – swap "opengl" for "auto" and nothing else changes. See the Shaders guide.
Playing Audio
<?php
$sound = vio_audio_load("background.mp3");
vio_audio_play($sound, [
"volume" => 0.7,
"loop" => true,
]);
// Keep running until Ctrl+C
while (vio_audio_playing($sound)) {
usleep(100000);
}Running Tests
NO_INTERACTION=1 TEST_PHP_EXECUTABLE=$(which php) \
php run-tests.php -d extension=$PWD/modules/vio.so tests/Next Steps
- Architecture – How the backend dispatch works
- Backends – OpenGL, Vulkan, Metal, D3D details
- 2D Rendering – Sprites, shapes, text
- 3D Rendering – Meshes, shaders, pipelines