1. Go to this page and download the library: Download php-sdl/sdl3-ttf library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
php-sdl / sdl3-ttf example snippets
use Sdl3ttf\SDLTTF\SDLTTF;
// Initialise SDL3_ttf
SDLTTF::TTFInit();
// Open a font at 32pt
$font = SDLTTF::TTFOpenFont('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 32.0);
printf("Font height: %d ascent: %d descent: %d\n",
$font['height'], $font['ascent'], $font['descent']);
// Render white text to an SDL_Surface
$surface = SDLTTF::TTFRenderTextBlended(
$font['ptr'], // font pointer
'Hello, SDL3_ttf!', // text
255, 255, 255, 255 // RGBA
);
printf("Rendered surface: %dx%d (%d pixels)\n",
$surface['w'], $surface['h'],
count($surface['pixels']['data'])
);
// Clean up
SDLTTF::TTFCloseFont($font['ptr']);
SDLTTF::TTFQuit();