Skip to content

Ponup/php-opengl

Repository files navigation

Build and test

PHP-OpenGL

PHP bindings of the OpenGL library. This library allows you to create inmersive 3D applications and games for the desktop with the comfort of the PHP language.

The extension only supports modern OpenGL and the core profile. The OpenGL compatibility profile (which provides functions such as glRotate, glBegin, glLight, etc...) is not supported.

Requirements

  • PHP8.1
  • SDL extension for PHP
  • OpenGL library/framework
  • Linux/MacOS (Windows support coming soon)
  • The PHP GD extension is required to run some of the examples.

Installation

Linux

pecl install opengl-devel

Or

git clone [email protected]:Ponup/php-opengl.git --recursive phpopengl
cd php-opengl
phpize
./configure --with-opengl
make
sudo make install

Examples

<?php
SDL_Init(SDL_INIT_EVERYTHING);

$window = SDL_CreateWindow("Fixed pipeline example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,                
                640, 480, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);                                                                                               
SDL_GL_CreateContext($window);    

glClearColor(0, 0, .2, 1); 
glClear(GL_COLOR_BUFFER_BIT);
SDL_GL_SwapWindow($window);

$event = new SDL_Event;
while(true) {
	SDL_PollEvent($event);
	if($event->type == SDL_KEYDOWN) break;
	SDL_Delay(50);
}

SDL_DestroyWindow($window);

Complete examples can be found in the examples folder.