{"id":15654335,"url":"https://github.com/serafimarts/ffi-sdl","last_synced_at":"2025-07-20T07:33:12.530Z","repository":{"id":72249541,"uuid":"242451883","full_name":"SerafimArts/ffi-sdl","owner":"SerafimArts","description":"SDL2 FFI bindings for the PHP language","archived":false,"fork":false,"pushed_at":"2023-08-12T20:25:09.000Z","size":5138,"stargazers_count":27,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-03-15T15:10:08.069Z","etag":null,"topics":["ffi","opengl","php","sdl","sdl2","sdl2-bindings"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SerafimArts.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-23T03:46:55.000Z","updated_at":"2024-02-03T22:16:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"2748746f-d98d-42c0-bb95-805b5cf98a6a","html_url":"https://github.com/SerafimArts/ffi-sdl","commit_stats":{"total_commits":48,"total_committers":2,"mean_commits":24.0,"dds":0.02083333333333337,"last_synced_commit":"ea37b2d805f259f83e1bf93bacbeb05bc725e8d9"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SerafimArts%2Fffi-sdl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SerafimArts%2Fffi-sdl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SerafimArts%2Fffi-sdl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SerafimArts%2Fffi-sdl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SerafimArts","download_url":"https://codeload.github.com/SerafimArts/ffi-sdl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251723311,"owners_count":21633134,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ffi","opengl","php","sdl","sdl2","sdl2-bindings"],"created_at":"2024-10-03T12:50:52.293Z","updated_at":"2025-04-30T14:44:25.557Z","avatar_url":"https://github.com/SerafimArts.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FFI SDL Bindings\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://packagist.org/packages/serafim/ffi-sdl\"\u003e\u003cimg src=\"https://poser.pugx.org/serafim/ffi-sdl/require/php?style=for-the-badge\" alt=\"PHP 8.1+\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/libsdl-org/SDL\"\u003e\u003cimg src=\"https://img.shields.io/badge/SDL-2.28.2-132B48.svg?style=for-the-badge\u0026logo=c%2b%2b\" alt=\"SDL\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/serafim/ffi-sdl\"\u003e\u003cimg src=\"https://poser.pugx.org/serafim/ffi-sdl/version?style=for-the-badge\" alt=\"Latest Stable Version\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/serafim/ffi-sdl\"\u003e\u003cimg src=\"https://poser.pugx.org/serafim/ffi-sdl/v/unstable?style=for-the-badge\" alt=\"Latest Unstable Version\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/serafim/ffi-sdl\"\u003e\u003cimg src=\"https://poser.pugx.org/serafim/ffi-sdl/downloads?style=for-the-badge\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://raw.githubusercontent.com/serafim/ffi-sdl/master/LICENSE.md\"\u003e\u003cimg src=\"https://poser.pugx.org/serafim/ffi-sdl/license?style=for-the-badge\" alt=\"License MIT\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nA SDL FFI bindings for the PHP language.\n\n- [System Requirements](#requirements)\n- [Installation](#installation)\n- [Extensions](#extensions)\n- [Documentation](#documentation)\n- [Initialization](#initialization)\n- [Example](#example)\n\n## Requirements\n\n- PHP ^8.1\n- ext-ffi\n- Windows, Linux, BSD or MacOS \n    - Android, iOS or something else are not supported yet\n- SDL \u003e= 2.0\n\n## Installation\n\nLibrary is available as composer repository and can be \ninstalled using the following command in a root of your project.\n\n```bash\n$ composer require serafim/ffi-sdl\n```\n\nAdditional dependencies:\n  - Debian-based Linux: `sudo apt install libsdl2-2.0-0 -y`\n  - MacOS: `brew install sdl2`\n  - Window: Can be [downloaded from here](https://github.com/libsdl-org/SDL/releases)\n\n## Extensions\n\n- [SDL Image](https://github.com/SerafimArts/ffi-sdl-image)\n- [SDL TTF](https://github.com/SerafimArts/ffi-sdl-ttf)\n- [SDL Mixer](https://github.com/SerafimArts/ffi-sdl-mixer)\n\n## Documentation\n\nThe library API completely supports and repeats the analogue in the C language.\n\n- [SDL2 official documentation](https://wiki.libsdl.org/FrontPage)\n\n- API not yet fully documented and may not work in places.\n- Low level and inline functions (such as `SDL_malloc` or `SDL_memcpy`) have\n  been removed.\n\n## Initialization\n\nTo specify a library pathname explicitly, you can add the `library` argument to\nthe `Serafim\\SDL\\SDL` constructor.\n\n\u003e By default, the library will try to resolve the binary's pathname automatically.\n\n```php\n// Load library from pathname (it may be relative or part of system-dependent path)\n$sdl = new Serafim\\SDL\\SDL(library: __DIR__ . '/path/to/library.so');\n\n// Try to automatically resolve library's pathname\n$sdl = new Serafim\\SDL\\SDL(library: null);\n```\n\nYou can explicitly specify the platform (OS) that will be used as the basis\nfor compiling headers. \n\n\u003e By default, the library will try to resolve the platform automatically.\n\n```php\n// Use Linux as compile-aware platform\n$sdl = new Serafim\\SDL\\SDL(platform: Serafim\\SDL\\Platform::LINUX);\n\n// Detect platform automatically\n$sdl = new Serafim\\SDL\\SDL(platform: null);\n```\n\nYou can also specify the library version explicitly. Depending on this version,\nthe corresponding functions of the SDL will be available.\n\n\u003e By default, the library will try to resolve SDL version automatically.\n\n```php\n// Use v2.28.2 from string\n$sdl = new Serafim\\SDL\\SDL(version: '2.28.2');\n\n// Use v2.24.1 from predefined versions constant\n$sdl = new Serafim\\SDL\\SDL(version: \\Serafim\\SDL\\Version::V2_24_1);\n\n// Use latest supported version\n$sdl = new Serafim\\SDL\\SDL(version: \\Serafim\\SDL\\Version::LATEST);\n```\n\nTo speed up the header compiler, you can use any PSR-16 compatible cache driver.\n\n```php\n$sdl = new Serafim\\SDL\\SDL(cache: new Psr16Cache(...));\n```\n\nIn addition, you can control other preprocessor directives explicitly:\n\n```php\n$pre = new \\FFI\\Preprocessor\\Preprocessor();\n$pre-\u003esetLogger(new ExampleLogger());\n$pre-\u003edefine('__ANDROID__', '1');\n\n$sdl = new Serafim\\SDL\\SDL(pre: $pre);\n$jni = $sdl-\u003eSDL_AndroidGetJNIEnv();\n```\n\n## Example\n\n```php\nuse Serafim\\SDL\\SDL;\nuse Serafim\\SDL\\Event\\Type;\n\n$sdl = new SDL();\n\n$sdl-\u003eSDL_Init(SDL::SDL_INIT_VIDEO);\n\n$window = $sdl-\u003eSDL_CreateWindow(\n    'An SDL2 window',\n    SDL::SDL_WINDOWPOS_UNDEFINED,\n    SDL::SDL_WINDOWPOS_UNDEFINED,\n    640,\n    480,\n    SDL::SDL_WINDOW_OPENGL\n);\n\nif ($window === null) {\n    throw new \\Exception(sprintf('Could not create window: %s', $sdl-\u003eSDL_GetError()));\n}\n\n$event = $sdl-\u003enew('SDL_Event');\n$running = true;\n\nwhile ($running) {\n    $sdl-\u003eSDL_PollEvent(FFI::addr($event));\n    if ($event-\u003etype === Type::SDL_QUIT) {\n        $running = false;\n    }\n}\n\n$sdl-\u003eSDL_DestroyWindow($window);\n$sdl-\u003eSDL_Quit();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserafimarts%2Fffi-sdl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserafimarts%2Fffi-sdl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserafimarts%2Fffi-sdl/lists"}