Advertisement
krishean

minimal.php (Linux)

Mar 9th, 2020
11,671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 16.88 KB | None | 0 0
  1. <?php
  2.  
  3. error_reporting(E_ALL);
  4. set_time_limit(120);
  5.  
  6. $libSDL2 = FFI::cdef("
  7. typedef uint8_t     Uint8;
  8. typedef uint16_t    Uint16;
  9. typedef uint32_t    Uint32;
  10. typedef int16_t     Sint16;
  11. typedef int32_t     Sint32;
  12. typedef int64_t     Sint64;
  13. typedef Sint32      SDL_Keycode;
  14. typedef Sint32      SDL_JoystickID;
  15. typedef Sint64      SDL_TouchID;
  16. typedef Sint64      SDL_FingerID;
  17. typedef Sint64      SDL_GestureID;
  18. typedef struct SDL_Window SDL_Window;
  19. typedef void *SDL_GLContext;
  20. typedef enum{
  21.    SDL_SCANCODE_UNKNOWN = 0,
  22.    SDL_SCANCODE_A = 4,
  23.    SDL_SCANCODE_B = 5,
  24.    SDL_SCANCODE_C = 6,
  25.    SDL_SCANCODE_D = 7,
  26.    SDL_SCANCODE_E = 8,
  27.    SDL_SCANCODE_F = 9,
  28.    SDL_SCANCODE_G = 10,
  29.    SDL_SCANCODE_H = 11,
  30.    SDL_SCANCODE_I = 12,
  31.    SDL_SCANCODE_J = 13,
  32.    SDL_SCANCODE_K = 14,
  33.    SDL_SCANCODE_L = 15,
  34.    SDL_SCANCODE_M = 16,
  35.    SDL_SCANCODE_N = 17,
  36.    SDL_SCANCODE_O = 18,
  37.    SDL_SCANCODE_P = 19,
  38.    SDL_SCANCODE_Q = 20,
  39.    SDL_SCANCODE_R = 21,
  40.    SDL_SCANCODE_S = 22,
  41.    SDL_SCANCODE_T = 23,
  42.    SDL_SCANCODE_U = 24,
  43.    SDL_SCANCODE_V = 25,
  44.    SDL_SCANCODE_W = 26,
  45.    SDL_SCANCODE_X = 27,
  46.    SDL_SCANCODE_Y = 28,
  47.    SDL_SCANCODE_Z = 29,
  48.    SDL_SCANCODE_1 = 30,
  49.    SDL_SCANCODE_2 = 31,
  50.    SDL_SCANCODE_3 = 32,
  51.    SDL_SCANCODE_4 = 33,
  52.    SDL_SCANCODE_5 = 34,
  53.    SDL_SCANCODE_6 = 35,
  54.    SDL_SCANCODE_7 = 36,
  55.    SDL_SCANCODE_8 = 37,
  56.    SDL_SCANCODE_9 = 38,
  57.    SDL_SCANCODE_0 = 39,
  58.    SDL_SCANCODE_RETURN = 40,
  59.    SDL_SCANCODE_ESCAPE = 41,
  60.    SDL_SCANCODE_BACKSPACE = 42,
  61.    SDL_SCANCODE_TAB = 43,
  62.    SDL_SCANCODE_SPACE = 44,
  63.    SDL_SCANCODE_MINUS = 45,
  64.    SDL_SCANCODE_EQUALS = 46,
  65.    SDL_SCANCODE_LEFTBRACKET = 47,
  66.    SDL_SCANCODE_RIGHTBRACKET = 48,
  67.    SDL_SCANCODE_BACKSLASH = 49,
  68.    SDL_SCANCODE_NONUSHASH = 50,
  69.    SDL_SCANCODE_SEMICOLON = 51,
  70.    SDL_SCANCODE_APOSTROPHE = 52,
  71.    SDL_SCANCODE_GRAVE = 53,
  72.    SDL_SCANCODE_COMMA = 54,
  73.    SDL_SCANCODE_PERIOD = 55,
  74.    SDL_SCANCODE_SLASH = 56,
  75.    SDL_SCANCODE_CAPSLOCK = 57,
  76.    SDL_SCANCODE_F1 = 58,
  77.    SDL_SCANCODE_F2 = 59,
  78.    SDL_SCANCODE_F3 = 60,
  79.    SDL_SCANCODE_F4 = 61,
  80.    SDL_SCANCODE_F5 = 62,
  81.    SDL_SCANCODE_F6 = 63,
  82.    SDL_SCANCODE_F7 = 64,
  83.    SDL_SCANCODE_F8 = 65,
  84.    SDL_SCANCODE_F9 = 66,
  85.    SDL_SCANCODE_F10 = 67,
  86.    SDL_SCANCODE_F11 = 68,
  87.    SDL_SCANCODE_F12 = 69,
  88.    SDL_SCANCODE_PRINTSCREEN = 70,
  89.    SDL_SCANCODE_SCROLLLOCK = 71,
  90.    SDL_SCANCODE_PAUSE = 72,
  91.    SDL_SCANCODE_INSERT = 73,
  92.    SDL_SCANCODE_HOME = 74,
  93.    SDL_SCANCODE_PAGEUP = 75,
  94.    SDL_SCANCODE_DELETE = 76,
  95.    SDL_SCANCODE_END = 77,
  96.    SDL_SCANCODE_PAGEDOWN = 78,
  97.    SDL_SCANCODE_RIGHT = 79,
  98.    SDL_SCANCODE_LEFT = 80,
  99.    SDL_SCANCODE_DOWN = 81,
  100.    SDL_SCANCODE_UP = 82,
  101.    SDL_SCANCODE_NUMLOCKCLEAR = 83,
  102.    SDL_SCANCODE_KP_DIVIDE = 84,
  103.    SDL_SCANCODE_KP_MULTIPLY = 85,
  104.    SDL_SCANCODE_KP_MINUS = 86,
  105.    SDL_SCANCODE_KP_PLUS = 87,
  106.    SDL_SCANCODE_KP_ENTER = 88,
  107.    SDL_SCANCODE_KP_1 = 89,
  108.    SDL_SCANCODE_KP_2 = 90,
  109.    SDL_SCANCODE_KP_3 = 91,
  110.    SDL_SCANCODE_KP_4 = 92,
  111.    SDL_SCANCODE_KP_5 = 93,
  112.    SDL_SCANCODE_KP_6 = 94,
  113.    SDL_SCANCODE_KP_7 = 95,
  114.    SDL_SCANCODE_KP_8 = 96,
  115.    SDL_SCANCODE_KP_9 = 97,
  116.    SDL_SCANCODE_KP_0 = 98,
  117.    SDL_SCANCODE_KP_PERIOD = 99,
  118.    SDL_SCANCODE_NONUSBACKSLASH = 100,
  119.    SDL_SCANCODE_APPLICATION = 101,
  120.    SDL_SCANCODE_POWER = 102,
  121.    SDL_SCANCODE_KP_EQUALS = 103,
  122.    SDL_SCANCODE_F13 = 104,
  123.    SDL_SCANCODE_F14 = 105,
  124.    SDL_SCANCODE_F15 = 106,
  125.    SDL_SCANCODE_F16 = 107,
  126.    SDL_SCANCODE_F17 = 108,
  127.    SDL_SCANCODE_F18 = 109,
  128.    SDL_SCANCODE_F19 = 110,
  129.    SDL_SCANCODE_F20 = 111,
  130.    SDL_SCANCODE_F21 = 112,
  131.    SDL_SCANCODE_F22 = 113,
  132.    SDL_SCANCODE_F23 = 114,
  133.    SDL_SCANCODE_F24 = 115,
  134.    SDL_SCANCODE_EXECUTE = 116,
  135.    SDL_SCANCODE_HELP = 117,
  136.    SDL_SCANCODE_MENU = 118,
  137.    SDL_SCANCODE_SELECT = 119,
  138.    SDL_SCANCODE_STOP = 120,
  139.    SDL_SCANCODE_AGAIN = 121,
  140.    SDL_SCANCODE_UNDO = 122,
  141.    SDL_SCANCODE_CUT = 123,
  142.    SDL_SCANCODE_COPY = 124,
  143.    SDL_SCANCODE_PASTE = 125,
  144.    SDL_SCANCODE_FIND = 126,
  145.    SDL_SCANCODE_MUTE = 127,
  146.    SDL_SCANCODE_VOLUMEUP = 128,
  147.    SDL_SCANCODE_VOLUMEDOWN = 129,
  148.    SDL_SCANCODE_KP_COMMA = 133,
  149.    SDL_SCANCODE_KP_EQUALSAS400 = 134,
  150.    SDL_SCANCODE_INTERNATIONAL1 = 135,
  151.    SDL_SCANCODE_INTERNATIONAL2 = 136,
  152.    SDL_SCANCODE_INTERNATIONAL3 = 137,
  153.    SDL_SCANCODE_INTERNATIONAL4 = 138,
  154.    SDL_SCANCODE_INTERNATIONAL5 = 139,
  155.    SDL_SCANCODE_INTERNATIONAL6 = 140,
  156.    SDL_SCANCODE_INTERNATIONAL7 = 141,
  157.    SDL_SCANCODE_INTERNATIONAL8 = 142,
  158.    SDL_SCANCODE_INTERNATIONAL9 = 143,
  159.    SDL_SCANCODE_LANG1 = 144,
  160.    SDL_SCANCODE_LANG2 = 145,
  161.    SDL_SCANCODE_LANG3 = 146,
  162.    SDL_SCANCODE_LANG4 = 147,
  163.    SDL_SCANCODE_LANG5 = 148,
  164.    SDL_SCANCODE_LANG6 = 149,
  165.    SDL_SCANCODE_LANG7 = 150,
  166.    SDL_SCANCODE_LANG8 = 151,
  167.    SDL_SCANCODE_LANG9 = 152,
  168.    SDL_SCANCODE_ALTERASE = 153,
  169.    SDL_SCANCODE_SYSREQ = 154,
  170.    SDL_SCANCODE_CANCEL = 155,
  171.    SDL_SCANCODE_CLEAR = 156,
  172.    SDL_SCANCODE_PRIOR = 157,
  173.    SDL_SCANCODE_RETURN2 = 158,
  174.    SDL_SCANCODE_SEPARATOR = 159,
  175.    SDL_SCANCODE_OUT = 160,
  176.    SDL_SCANCODE_OPER = 161,
  177.    SDL_SCANCODE_CLEARAGAIN = 162,
  178.    SDL_SCANCODE_CRSEL = 163,
  179.    SDL_SCANCODE_EXSEL = 164,
  180.    SDL_SCANCODE_KP_00 = 176,
  181.    SDL_SCANCODE_KP_000 = 177,
  182.    SDL_SCANCODE_THOUSANDSSEPARATOR = 178,
  183.    SDL_SCANCODE_DECIMALSEPARATOR = 179,
  184.    SDL_SCANCODE_CURRENCYUNIT = 180,
  185.    SDL_SCANCODE_CURRENCYSUBUNIT = 181,
  186.    SDL_SCANCODE_KP_LEFTPAREN = 182,
  187.    SDL_SCANCODE_KP_RIGHTPAREN = 183,
  188.    SDL_SCANCODE_KP_LEFTBRACE = 184,
  189.    SDL_SCANCODE_KP_RIGHTBRACE = 185,
  190.    SDL_SCANCODE_KP_TAB = 186,
  191.    SDL_SCANCODE_KP_BACKSPACE = 187,
  192.    SDL_SCANCODE_KP_A = 188,
  193.    SDL_SCANCODE_KP_B = 189,
  194.    SDL_SCANCODE_KP_C = 190,
  195.    SDL_SCANCODE_KP_D = 191,
  196.    SDL_SCANCODE_KP_E = 192,
  197.    SDL_SCANCODE_KP_F = 193,
  198.    SDL_SCANCODE_KP_XOR = 194,
  199.    SDL_SCANCODE_KP_POWER = 195,
  200.    SDL_SCANCODE_KP_PERCENT = 196,
  201.    SDL_SCANCODE_KP_LESS = 197,
  202.    SDL_SCANCODE_KP_GREATER = 198,
  203.    SDL_SCANCODE_KP_AMPERSAND = 199,
  204.    SDL_SCANCODE_KP_DBLAMPERSAND = 200,
  205.    SDL_SCANCODE_KP_VERTICALBAR = 201,
  206.    SDL_SCANCODE_KP_DBLVERTICALBAR = 202,
  207.    SDL_SCANCODE_KP_COLON = 203,
  208.    SDL_SCANCODE_KP_HASH = 204,
  209.    SDL_SCANCODE_KP_SPACE = 205,
  210.    SDL_SCANCODE_KP_AT = 206,
  211.    SDL_SCANCODE_KP_EXCLAM = 207,
  212.    SDL_SCANCODE_KP_MEMSTORE = 208,
  213.    SDL_SCANCODE_KP_MEMRECALL = 209,
  214.    SDL_SCANCODE_KP_MEMCLEAR = 210,
  215.    SDL_SCANCODE_KP_MEMADD = 211,
  216.    SDL_SCANCODE_KP_MEMSUBTRACT = 212,
  217.    SDL_SCANCODE_KP_MEMMULTIPLY = 213,
  218.    SDL_SCANCODE_KP_MEMDIVIDE = 214,
  219.    SDL_SCANCODE_KP_PLUSMINUS = 215,
  220.    SDL_SCANCODE_KP_CLEAR = 216,
  221.    SDL_SCANCODE_KP_CLEARENTRY = 217,
  222.    SDL_SCANCODE_KP_BINARY = 218,
  223.    SDL_SCANCODE_KP_OCTAL = 219,
  224.    SDL_SCANCODE_KP_DECIMAL = 220,
  225.    SDL_SCANCODE_KP_HEXADECIMAL = 221,
  226.    SDL_SCANCODE_LCTRL = 224,
  227.    SDL_SCANCODE_LSHIFT = 225,
  228.    SDL_SCANCODE_LALT = 226,
  229.    SDL_SCANCODE_LGUI = 227,
  230.    SDL_SCANCODE_RCTRL = 228,
  231.    SDL_SCANCODE_RSHIFT = 229,
  232.    SDL_SCANCODE_RALT = 230,
  233.    SDL_SCANCODE_RGUI = 231,
  234.    SDL_SCANCODE_MODE = 257,
  235.    SDL_SCANCODE_AUDIONEXT = 258,
  236.    SDL_SCANCODE_AUDIOPREV = 259,
  237.    SDL_SCANCODE_AUDIOSTOP = 260,
  238.    SDL_SCANCODE_AUDIOPLAY = 261,
  239.    SDL_SCANCODE_AUDIOMUTE = 262,
  240.    SDL_SCANCODE_MEDIASELECT = 263,
  241.    SDL_SCANCODE_WWW = 264,
  242.    SDL_SCANCODE_MAIL = 265,
  243.    SDL_SCANCODE_CALCULATOR = 266,
  244.    SDL_SCANCODE_COMPUTER = 267,
  245.    SDL_SCANCODE_AC_SEARCH = 268,
  246.    SDL_SCANCODE_AC_HOME = 269,
  247.    SDL_SCANCODE_AC_BACK = 270,
  248.    SDL_SCANCODE_AC_FORWARD = 271,
  249.    SDL_SCANCODE_AC_STOP = 272,
  250.    SDL_SCANCODE_AC_REFRESH = 273,
  251.    SDL_SCANCODE_AC_BOOKMARKS = 274,
  252.    SDL_SCANCODE_BRIGHTNESSDOWN = 275,
  253.    SDL_SCANCODE_BRIGHTNESSUP = 276,
  254.    SDL_SCANCODE_DISPLAYSWITCH = 277,
  255.    SDL_SCANCODE_KBDILLUMTOGGLE = 278,
  256.    SDL_SCANCODE_KBDILLUMDOWN = 279,
  257.    SDL_SCANCODE_KBDILLUMUP = 280,
  258.    SDL_SCANCODE_EJECT = 281,
  259.    SDL_SCANCODE_SLEEP = 282,
  260.    SDL_SCANCODE_APP1 = 283,
  261.    SDL_SCANCODE_APP2 = 284,
  262.    SDL_SCANCODE_AUDIOREWIND = 285,
  263.    SDL_SCANCODE_AUDIOFASTFORWARD = 286,
  264.    SDL_NUM_SCANCODES = 512
  265. } SDL_Scancode;
  266. typedef struct SDL_Keysym{
  267.    SDL_Scancode scancode;
  268.    SDL_Keycode sym;
  269.    Uint16 mod;
  270.    Uint32 unused;
  271. } SDL_Keysym;
  272. typedef struct SDL_CommonEvent{
  273.    Uint32 type;
  274.    Uint32 timestamp;
  275. } SDL_CommonEvent;
  276. typedef struct SDL_DisplayEvent{
  277.    Uint32 type;
  278.    Uint32 timestamp;
  279.    Uint32 display;
  280.    Uint8 event;
  281.    Uint8 padding1;
  282.    Uint8 padding2;
  283.    Uint8 padding3;
  284.    Sint32 data1;
  285. } SDL_DisplayEvent;
  286. typedef struct SDL_WindowEvent{
  287.    Uint32 type;
  288.    Uint32 timestamp;
  289.    Uint32 windowID;
  290.    Uint8 event;
  291.    Uint8 padding1;
  292.    Uint8 padding2;
  293.    Uint8 padding3;
  294.    Sint32 data1;
  295.    Sint32 data2;
  296. } SDL_WindowEvent;
  297. typedef struct SDL_KeyboardEvent{
  298.    Uint32 type;
  299.    Uint32 timestamp;
  300.    Uint32 windowID;
  301.    Uint8 state;
  302.    Uint8 repeat;
  303.    Uint8 padding2;
  304.    Uint8 padding3;
  305.    SDL_Keysym keysym;
  306. } SDL_KeyboardEvent;
  307. typedef struct SDL_TextEditingEvent{
  308.    Uint32 type;
  309.    Uint32 timestamp;
  310.    Uint32 windowID;
  311.    char text[32];
  312.    Sint32 start;
  313.    Sint32 length;
  314. } SDL_TextEditingEvent;
  315. typedef struct SDL_TextInputEvent{
  316.    Uint32 type;
  317.    Uint32 timestamp;
  318.    Uint32 windowID;
  319.    char text[32];
  320. } SDL_TextInputEvent;
  321. typedef struct SDL_MouseMotionEvent{
  322.    Uint32 type;
  323.    Uint32 timestamp;
  324.    Uint32 windowID;
  325.    Uint32 which;
  326.    Uint32 state;
  327.    Sint32 x;
  328.    Sint32 y;
  329.    Sint32 xrel;
  330.    Sint32 yrel;
  331. } SDL_MouseMotionEvent;
  332. typedef struct SDL_MouseButtonEvent{
  333.    Uint32 type;
  334.    Uint32 timestamp;
  335.    Uint32 windowID;
  336.    Uint32 which;
  337.    Uint8 button;
  338.    Uint8 state;
  339.    Uint8 clicks;
  340.    Uint8 padding1;
  341.    Sint32 x;
  342.    Sint32 y;
  343. } SDL_MouseButtonEvent;
  344. typedef struct SDL_MouseWheelEvent{
  345.    Uint32 type;
  346.    Uint32 timestamp;
  347.    Uint32 windowID;
  348.    Uint32 which;
  349.    Sint32 x;
  350.    Sint32 y;
  351.    Uint32 direction;
  352. } SDL_MouseWheelEvent;
  353. typedef struct SDL_JoyAxisEvent{
  354.    Uint32 type;
  355.    Uint32 timestamp;
  356.    SDL_JoystickID which;
  357.    Uint8 axis;
  358.    Uint8 padding1;
  359.    Uint8 padding2;
  360.    Uint8 padding3;
  361.    Sint16 value;
  362.    Uint16 padding4;
  363. } SDL_JoyAxisEvent;
  364. typedef struct SDL_JoyBallEvent{
  365.    Uint32 type;
  366.    Uint32 timestamp;
  367.    SDL_JoystickID which;
  368.    Uint8 ball;
  369.    Uint8 padding1;
  370.    Uint8 padding2;
  371.    Uint8 padding3;
  372.    Sint16 xrel;
  373.    Sint16 yrel;
  374. } SDL_JoyBallEvent;
  375. typedef struct SDL_JoyHatEvent{
  376.    Uint32 type;
  377.    Uint32 timestamp;
  378.    SDL_JoystickID which;
  379.    Uint8 hat;
  380.    Uint8 value;
  381.    Uint8 padding1;
  382.    Uint8 padding2;
  383. } SDL_JoyHatEvent;
  384. typedef struct SDL_JoyButtonEvent{
  385.    Uint32 type;
  386.    Uint32 timestamp;
  387.    SDL_JoystickID which;
  388.    Uint8 button;
  389.    Uint8 state;
  390.    Uint8 padding1;
  391.    Uint8 padding2;
  392. } SDL_JoyButtonEvent;
  393. typedef struct SDL_JoyDeviceEvent{
  394.    Uint32 type;
  395.    Uint32 timestamp;
  396.    Sint32 which;
  397. } SDL_JoyDeviceEvent;
  398. typedef struct SDL_ControllerAxisEvent{
  399.    Uint32 type;
  400.    Uint32 timestamp;
  401.    SDL_JoystickID which;
  402.    Uint8 axis;
  403.    Uint8 padding1;
  404.    Uint8 padding2;
  405.    Uint8 padding3;
  406.    Sint16 value;
  407.    Uint16 padding4;
  408. } SDL_ControllerAxisEvent;
  409. typedef struct SDL_ControllerButtonEvent{
  410.    Uint32 type;
  411.    Uint32 timestamp;
  412.    SDL_JoystickID which;
  413.    Uint8 button;
  414.    Uint8 state;
  415.    Uint8 padding1;
  416.    Uint8 padding2;
  417. } SDL_ControllerButtonEvent;
  418. typedef struct SDL_ControllerDeviceEvent{
  419.    Uint32 type;
  420.    Uint32 timestamp;
  421.    Sint32 which;
  422. } SDL_ControllerDeviceEvent;
  423. typedef struct SDL_AudioDeviceEvent{
  424.    Uint32 type;
  425.    Uint32 timestamp;
  426.    Uint32 which;
  427.    Uint8 iscapture;
  428.    Uint8 padding1;
  429.    Uint8 padding2;
  430.    Uint8 padding3;
  431. } SDL_AudioDeviceEvent;
  432. typedef struct SDL_TouchFingerEvent{
  433.    Uint32 type;
  434.    Uint32 timestamp;
  435.    SDL_TouchID touchId;
  436.    SDL_FingerID fingerId;
  437.    float x;
  438.    float y;
  439.    float dx;
  440.    float dy;
  441.    float pressure;
  442. } SDL_TouchFingerEvent;
  443. typedef struct SDL_MultiGestureEvent{
  444.    Uint32 type;
  445.    Uint32 timestamp;
  446.    SDL_TouchID touchId;
  447.    float dTheta;
  448.    float dDist;
  449.    float x;
  450.    float y;
  451.    Uint16 numFingers;
  452.    Uint16 padding;
  453. } SDL_MultiGestureEvent;
  454. typedef struct SDL_DollarGestureEvent{
  455.    Uint32 type;
  456.    Uint32 timestamp;
  457.    SDL_TouchID touchId;
  458.    SDL_GestureID gestureId;
  459.    Uint32 numFingers;
  460.    float error;
  461.    float x;
  462.    float y;
  463. } SDL_DollarGestureEvent;
  464. typedef struct SDL_DropEvent{
  465.    Uint32 type;
  466.    Uint32 timestamp;
  467.    char *file;
  468.    Uint32 windowID;
  469. } SDL_DropEvent;
  470. typedef struct SDL_SensorEvent{
  471.    Uint32 type;
  472.    Uint32 timestamp;
  473.    Sint32 which;
  474.    float data[6];
  475. } SDL_SensorEvent;
  476. typedef struct SDL_QuitEvent{
  477.    Uint32 type;
  478.    Uint32 timestamp;
  479. } SDL_QuitEvent;
  480. typedef struct SDL_UserEvent{
  481.    Uint32 type;
  482.    Uint32 timestamp;
  483.    Uint32 windowID;
  484.    Sint32 code;
  485.    void *data1;
  486.    void *data2;
  487. } SDL_UserEvent;
  488. struct SDL_SysWMmsg;
  489. typedef struct SDL_SysWMmsg SDL_SysWMmsg;
  490. typedef struct SDL_SysWMEvent{
  491.    Uint32 type;
  492.    Uint32 timestamp;
  493.    SDL_SysWMmsg *msg;
  494. } SDL_SysWMEvent;
  495. typedef union SDL_Event{
  496.    Uint32 type;
  497.    SDL_CommonEvent common;
  498.    SDL_DisplayEvent display;
  499.    SDL_WindowEvent window;
  500.    SDL_KeyboardEvent key;
  501.    SDL_TextEditingEvent edit;
  502.    SDL_TextInputEvent text;
  503.    SDL_MouseMotionEvent motion;
  504.    SDL_MouseButtonEvent button;
  505.    SDL_MouseWheelEvent wheel;
  506.    SDL_JoyAxisEvent jaxis;
  507.    SDL_JoyBallEvent jball;
  508.    SDL_JoyHatEvent jhat;
  509.    SDL_JoyButtonEvent jbutton;
  510.    SDL_JoyDeviceEvent jdevice;
  511.    SDL_ControllerAxisEvent caxis;
  512.    SDL_ControllerButtonEvent cbutton;
  513.    SDL_ControllerDeviceEvent cdevice;
  514.    SDL_AudioDeviceEvent adevice;
  515.    SDL_SensorEvent sensor;
  516.    SDL_QuitEvent quit;
  517.    SDL_UserEvent user;
  518.    SDL_SysWMEvent syswm;
  519.    SDL_TouchFingerEvent tfinger;
  520.    SDL_MultiGestureEvent mgesture;
  521.    SDL_DollarGestureEvent dgesture;
  522.    SDL_DropEvent drop;
  523.    Uint8 padding[56];
  524. } SDL_Event;
  525. int SDL_Init(Uint32 flags);
  526. SDL_Window * SDL_CreateWindow(const char *title,
  527.                              int x, int y, int w,
  528.                              int h, Uint32 flags);
  529. SDL_GLContext SDL_GL_CreateContext(SDL_Window *
  530.                                   window);
  531. int SDL_PollEvent(SDL_Event * event);
  532. void SDL_GL_SwapWindow(SDL_Window * window);
  533. ", "libSDL2.so");
  534.  
  535. $libGLEW = FFI::cdef("
  536. typedef unsigned int    GLenum;
  537. typedef unsigned char   GLubyte;
  538. GLenum glewInit (void);
  539. const GLubyte * glewGetErrorString (GLenum error);
  540. ", "libGLEW.so");
  541.  
  542. $libGL = FFI::cdef("
  543. typedef unsigned int    GLenum;
  544. typedef unsigned int    GLbitfield;
  545. typedef int             GLint;
  546. typedef float           GLfloat;
  547. void glClear( GLbitfield mask );
  548. void glFlush( void );
  549. void glBegin( GLenum mode );
  550. void glEnd( void );
  551. void glVertex2i( GLint x, GLint y );
  552. void glColor3f( GLfloat red, GLfloat green, GLfloat blue );
  553. ", "libGL.so");
  554.  
  555. define('GL_COLOR_BUFFER_BIT', 0x00004000);
  556. define('GL_TRIANGLES', 0x0004);
  557. define('SDL_QUIT', 0x100);
  558. define('SDL_INIT_VIDEO', 0x00000020);
  559. define('SDL_WINDOWPOS_CENTERED', 0x2FFF0000);
  560. define('SDL_WINDOW_RESIZABLE', 0x00000020);
  561. define('SDL_WINDOW_OPENGL', 0x00000002);
  562. define('GLEW_OK', 0);
  563. define('EXIT_FAILURE', 1);
  564. define('EXIT_SUCCESS', 0);
  565.  
  566. function display($window){
  567.     global $libSDL2, $libGL;
  568.    
  569.     /* rotate a triangle around */
  570.     $libGL->glClear(GL_COLOR_BUFFER_BIT);
  571.     $libGL->glBegin(GL_TRIANGLES);
  572.     $libGL->glColor3f(1.0, 0.0, 0.0);
  573.     $libGL->glVertex2i(0, 1);
  574.     $libGL->glColor3f(0.0, 1.0, 0.0);
  575.     $libGL->glVertex2i(-1, -1);
  576.     $libGL->glColor3f(0.0, 0.0, 1.0);
  577.     $libGL->glVertex2i(1, -1);
  578.     $libGL->glEnd();
  579.     $libGL->glFlush();
  580.    
  581.     /* Display the result */
  582.     $libSDL2->SDL_GL_SwapWindow($window);
  583. }
  584.  
  585. function mainLoop($window){
  586.     global $libSDL2;
  587.    
  588.     while(true){
  589.         $ev = $libSDL2->new("SDL_Event");
  590.         while($libSDL2->SDL_PollEvent(FFI::addr($ev))){
  591.             if($ev->type == SDL_QUIT)
  592.                 return;
  593.         }
  594.         display($window);
  595.     }
  596. }
  597.  
  598. exit(main());
  599. function main(){
  600.     global $libSDL2, $libGLEW;
  601.    
  602.     /* SDL-related initialising functions */
  603.     $libSDL2->SDL_Init(SDL_INIT_VIDEO);
  604.     $window = $libSDL2->SDL_CreateWindow("minimal",
  605.         SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
  606.         256, 256,
  607.         SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL);
  608.     $libSDL2->SDL_GL_CreateContext($window);
  609.    
  610.     /* Extension wrangler initialising */
  611.     $glew_status = $libGLEW->glewInit();
  612.     if($glew_status != GLEW_OK){
  613.         fwrite(STDERR, "Error: glewInit: " . FFI::string(FFI::cast("char*",
  614.             $libGLEW->glewGetErrorString($glew_status))) . PHP_EOL);
  615.         return EXIT_FAILURE;
  616.     }
  617.    
  618.     /* We can display something if everything goes OK */
  619.     mainLoop($window);
  620.    
  621.     return EXIT_SUCCESS;
  622. }
  623.  
  624. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement