<?php

// Test script for SDL_GetNumVideoDrivers and SDL_GetVideoDriver

echo "SDL3 Video Drivers Test\n";
echo "========================\n\n";

// Initialize SDL
if (!sdl_init(SDL_INIT_VIDEO)) {
    die("Failed to initialize SDL: " . sdl_get_error() . "\n");
}

echo "SDL initialized successfully\n\n";

// Get number of video drivers
$numDrivers = sdl_get_num_video_drivers();
echo "Number of available video drivers: $numDrivers\n\n";

// List all available video drivers
echo "Available video drivers:\n";
for ($i = 0; $i < $numDrivers; $i++) {
    $driver = sdl_get_video_driver($i);
    if ($driver !== false) {
        echo "  [$i] $driver\n";
    } else {
        echo "  [$i] Error getting driver\n";
    }
}

echo "\n";

// Get current video driver
$currentDriver = sdl_get_current_video_driver();
if ($currentDriver !== false) {
    echo "Current video driver: $currentDriver\n";
} else {
    echo "No video driver initialized yet (window not created)\n";
}

echo "\n";

// Create a window to initialize video driver
echo "Creating a window to initialize video driver...\n";
$window = sdl_create_window("Video Driver Test", 800, 600, SDL_WINDOW_HIDDEN);
if (!$window) {
    die("Failed to create window: " . sdl_get_error() . "\n");
}

echo "Window created successfully\n\n";

// Now get the current driver again
$currentDriver = sdl_get_current_video_driver();
if ($currentDriver !== false) {
    echo "Current video driver (after window creation): $currentDriver\n";
} else {
    echo "Failed to get current video driver\n";
}

// Cleanup
sdl_destroy_window($window);
sdl_quit();

echo "\nTest completed successfully!\n";
