DEADSOFTWARE

added opengl and sdl2 wrappers to allegro (WIP)
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Thu, 3 Jan 2019 11:58:16 +0000 (14:58 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Sun, 10 Feb 2019 10:05:11 +0000 (13:05 +0300)
14 files changed:
src/game/Doom2DF.lpr
src/game/g_menu.pas
src/lib/allegro4/allegro.pas [new file with mode: 0644]
src/nogl/noGL.pas
src/nogl/noGLALSW.inc [new file with mode: 0644]
src/nogl/noGLuses.inc
src/shared/a_modes.inc
src/shared/utils.pas
src/wrappers/sdl2/SDL2_mixer.pas
src/wrappers/sdl2/sdl2.pas
src/wrappers/sdl2/sdl2allegro.inc [new file with mode: 0644]
src/wrappers/sdl2/sdl2stub.inc [new file with mode: 0644]
src/wrappers/sdl2/sdl2stub_mixer.inc [new file with mode: 0644]
src/wrappers/sdl2/sdlpixels.inc [new file with mode: 0644]

index f50c895d58cae48e6a406ab4099988ff06c6e4a5..a897aea46837941e4faa6ab7ced11b7f938b79c9 100644 (file)
@@ -48,7 +48,7 @@ uses
 {$IFDEF USE_MINIUPNPC}
   miniupnpc in '../lib/miniupnpc/miniupnpc.pas',
 {$ENDIF}
-{$IFDEF USE_SDL2WRAP}
+{$IF DEFINED(USE_SDL2STUB) OR DEFINED(USE_SDL2ALLEGRO)}
   SDL2 in '../wrappers/sdl2/sdl2.pas',
   {$IFDEF USE_SDLMIXER}
     SDL2_mixer in '../wrappers/sdl2/SDL2_mixer.pas',
index 1b33864f7f606bda8e8325b4718756c9b412ce13..5df0bf1c4e849834f638a8653252f38c0cd24cc9 100644 (file)
@@ -951,10 +951,12 @@ begin
     g_Texture_CreateWADEx('FONT_STD', GameWAD+':FONTS\'+texture);
 
     config := TConfig.CreateMem(cfgdata, cfglen);
-    cwdt := Min(Max(config.ReadInt('FontMap', 'CharWidth', 0), 0), 255);
-    chgt := Min(Max(config.ReadInt('FontMap', 'CharHeight', 0), 0), 255);
+    cwdt := Min(Max(config.ReadInt('FontMap', 'CharWidth', 1), 1), 255);
+    chgt := Min(Max(config.ReadInt('FontMap', 'CharHeight', 1), 1), 255);
     spc := Min(Max(config.ReadInt('FontMap', 'Kerning', 0), -128), 127);
 
+    e_LogWritefln('LoadStdFont cwdt=%s chgt=%s spc=%s', [cwdt, chgt, spc]);
+
     if g_Texture_Get('FONT_STD', ID) then
       e_TextureFontBuild(ID, FontID, cwdt, chgt, spc);
 
diff --git a/src/lib/allegro4/allegro.pas b/src/lib/allegro4/allegro.pas
new file mode 100644 (file)
index 0000000..ae5adb5
--- /dev/null
@@ -0,0 +1,282 @@
+{$LONGSTRINGS ON}
+{$MACRO ON}
+
+{$IF DEFINED(GO32V2)}
+  {$LINKLIB liballeg.a}
+  {$LINKLIB libc.a}
+  {$LINKLIB libgcc.a}
+  {$DEFINE LibraryLibAllegroDecl := cdecl}
+  {$DEFINE LibraryLibAllegroImp := cdecl; external}
+  {$DEFINE LibraryLibAllegroVar := cvar; external}
+{$ELSEIF DEFINED(UNIX)}
+  {$LINKLIB liballeg.so}
+  {$DEFINE LibraryLibAllegroDecl := cdecl}
+  {$DEFINE LibraryLibAllegroImp := cdecl; external 'alleg'}
+  {$DEFINE LibraryLibAllegroVar := cvar; external 'alleg'}
+{$ELSE}
+  {$ERROR unsupported platform!}
+{$ENDIF}
+
+unit allegro;
+
+interface
+
+  uses ctypes;
+
+  const
+{$IF DEFINED(GO32V2)}
+    ALLEGRO_VERSION = 4;
+    ALEGRO_SUB_VERSION = 2;
+    ALLEGRO_WIP_VERSION = 3;
+    ALLEGRO_VERSION_STR = '4.2.3';
+{$ELSEIF DEFINED(UNIX)}
+    ALLEGRO_VERSION = 4;
+    ALEGRO_SUB_VERSION = 4;
+    ALLEGRO_WIP_VERSION = 2;
+    ALLEGRO_VERSION_STR = '4.4.2';
+{$ELSE}
+  {$ERROR unsupported platform!}
+{$ENDIF}
+
+    SYSTEM_AUTODETECT = 0;
+    SYSTEM_NONE = $4e4f4e45;
+
+    GFX_TEXT = -1;
+    GFX_AUTODETECT = 0;
+    GFX_AUTODETECT_FULLSCREEN = 1;
+    GFX_AUTODETECT_WINDOWED = 2;
+    GFX_SAFE = $53414645;
+
+    KEY_A = 1;
+    KEY_B = 2;
+    KEY_C = 3;
+    KEY_D = 4;
+    KEY_E = 5;
+    KEY_F = 6;
+    KEY_G = 7;
+    KEY_H = 8;
+    KEY_I = 9;
+    KEY_J = 10;
+    KEY_K = 11;
+    KEY_L = 12;
+    KEY_M = 13;
+    KEY_N = 14;
+    KEY_O = 15;
+    KEY_P = 16;
+    KEY_Q = 17;
+    KEY_R = 18;
+    KEY_S = 19;
+    KEY_T = 20;
+    KEY_U = 21;
+    KEY_V = 22;
+    KEY_W = 23;
+    KEY_X = 24;
+    KEY_Y = 25;
+    KEY_Z = 26;
+    KEY_0 = 27;
+    KEY_1 = 28;
+    KEY_2 = 29;
+    KEY_3 = 30;
+    KEY_4 = 31;
+    KEY_5 = 32;
+    KEY_6 = 33;
+    KEY_7 = 34;
+    KEY_8 = 35;
+    KEY_9 = 36;
+    KEY_0_PAD = 37;
+    KEY_1_PAD = 38;
+    KEY_2_PAD = 39;
+    KEY_3_PAD = 40;
+    KEY_4_PAD = 41;
+    KEY_5_PAD = 42;
+    KEY_6_PAD = 43;
+    KEY_7_PAD = 44;
+    KEY_8_PAD = 45;
+    KEY_9_PAD = 46;
+    KEY_F1 = 47;
+    KEY_F2 = 48;
+    KEY_F3 = 49;
+    KEY_F4 = 50;
+    KEY_F5 = 51;
+    KEY_F6 = 52;
+    KEY_F7 = 53;
+    KEY_F8 = 54;
+    KEY_F9 = 55;
+    KEY_F10 = 56;
+    KEY_F11 = 57;
+    KEY_F12 = 58;
+    KEY_ESC = 59;
+    KEY_TILDE = 60;
+    KEY_MINUS = 61;
+    KEY_EQUALS = 62;
+    KEY_BACKSPACE = 63;
+    KEY_TAB = 64;
+    KEY_OPENBRACE = 65;
+    KEY_CLOSEBRACE = 66;
+    KEY_ENTER = 67;
+    KEY_COLON = 68;
+    KEY_QUOTE = 69;
+    KEY_BACKSLASH = 70;
+    KEY_BACKSLASH2 = 71;
+    KEY_COMMA = 72;
+    KEY_STOP  = 73;
+    KEY_SLASH = 74;
+    KEY_SPACE = 75;
+    KEY_INSERT = 76;
+    KEY_DEL = 77;
+    KEY_HOME = 78;
+    KEY_END = 79;
+    KEY_PGUP = 80;
+    KEY_PGDN = 81;
+    KEY_LEFT = 82;
+    KEY_RIGHT = 83;
+    KEY_UP = 84;
+    KEY_DOWN = 85;
+    KEY_SLASH_PAD = 86;
+    KEY_ASTERISK = 87;
+    KEY_MINUS_PAD = 88;
+    KEY_PLUS_PAD = 89;
+    KEY_DEL_PAD = 90;
+    KEY_ENTER_PAD = 91;
+    KEY_PRTSCR = 92;
+    KEY_PAUSE = 93;
+    KEY_ABNT_C1 = 94;
+    KEY_YEN = 95;
+    KEY_KANA = 96;
+    KEY_CONVERT = 97;
+    KEY_NOCONVERT = 98;
+    KEY_AT = 99;
+    KEY_CIRCUMFLEX = 100;
+    KEY_COLON2 = 101;
+    KEY_KANJI = 102;
+    KEY_EQUALS_PAD = 103;
+    KEY_BACKQUOTE = 104;
+    KEY_SEMICOLON = 105;
+    KEY_COMMAND = 106;
+    KEY_UNKNOWN1 = 107;
+    KEY_UNKNOWN2 = 108;
+    KEY_UNKNOWN3 = 109;
+    KEY_UNKNOWN4 = 110;
+    KEY_UNKNOWN5 = 111;
+    KEY_UNKNOWN6 = 112;
+    KEY_UNKNOWN7 = 113;
+    KEY_UNKNOWN8 = 114;
+    KEY_MODIFIERS = 115;
+    KEY_LSHIFT = 115;
+    KEY_RSHIFT = 116;
+    KEY_LCONTROL = 117;
+    KEY_RCONTROL = 118;
+    KEY_ALT = 119;
+    KEY_ALTGR = 120;
+    KEY_LWIN = 121;
+    KEY_RWIN = 122;
+    KEY_MENU = 123;
+    KEY_SCRLOCK = 124;
+    KEY_NUMLOCK = 125;
+    KEY_CAPSLOCK = 126;
+    KEY_MAX   = 127;
+
+    KB_SHIFT_FLAG = $0001;
+    KB_CTRL_FLAG = $0002;
+    KB_ALT_FLAG = $0004;
+    KB_LWIN_FLAG = $0008;
+    KB_RWIN_FLAG = $0010;
+    KB_MENU_FLAG = $0020;
+    KB_COMMAND_FLAG = $0040;
+    KB_SCROLOCK_FLAG = $0100;
+    KB_NUMLOCK_FLAG = $0200;
+    KB_CAPSLOCK_FLAG = $0400;
+    KB_INALTSEQ_FLAG = $0800;
+    KB_ACCENT1_FLAG = $1000;
+    KB_ACCENT2_FLAG = $2000;
+    KB_ACCENT3_FLAG = $4000;
+    KB_ACCENT4_FLAG = $8000;
+
+    ALLEGRO_ERROR_SIZE = 256;
+
+  type
+    PBITMAP = ^BITMAP;
+    BITMAP = record
+      w, h: cint;
+      clip: cint;
+      cl, cr, ct, cb: cint;
+      vtable: Pointer; {PGFX_VTABLE}
+      write_bank: Pointer;
+      read_bank: Pointer;
+      dat: Pointer;
+      id: culong;
+      extra: Pointer;
+      x_ofs: cint;
+      y_ofs: cint;
+      seg: cint;
+      line: Pointer;
+    end;
+
+    PGFX_MODE = ^GFX_MODE;
+    GFX_MODE = record
+      width, height, bpp: cint;
+    end;
+
+    PGFX_MODE_LIST = ^GFX_MODE_LIST;
+    GFX_MODE_LIST = record
+      num_modes: cint;
+      mode: PGFX_MODE;
+    end;
+
+   KeyboardCallback = procedure (scancode: cint); LibraryLibAllegroDecl;   
+   AtExitCallback = procedure; LibraryLibAllegroDecl;
+   AtExitFunction = function (func: AtExitCallback): cint; LibraryLibAllegroDecl;
+
+  var
+    allegro_id: array [0..ALLEGRO_ERROR_SIZE] of char; LibraryLibAllegroVar;
+    allegro_error: array [0..ALLEGRO_ERROR_SIZE] of char; LibraryLibAllegroVar;
+    keyboard_lowlevel_callback: KeyboardCallback; LibraryLibAllegroVar;
+
+  function get_desktop_resolution (width, height: Pcint): cint; LibraryLibAllegroImp;
+  function get_gfx_mode_list (card: cint): PGFX_MODE_LIST; LibraryLibAllegroImp;
+  procedure destroy_gfx_mode_list (gfx_mode_list: PGFX_MODE_LIST); LibraryLibAllegroImp;
+  function set_gfx_mode (card, w, h, v_w, v_h: cint): cint; LibraryLibAllegroImp;
+  procedure set_window_title (name: Pchar); LibraryLibAllegroImp;
+  function create_video_bitmap (width, height: cint): PBITMAP; LibraryLibAllegroImp;
+  procedure destroy_bitmap (bitmap: PBITMAP); LibraryLibAllegroImp;
+  function show_video_bitmap (bitmap: PBITMAP): cint; LibraryLibAllegroImp;
+  function poll_keyboard: cint; LibraryLibAllegroImp;
+  function install_keyboard: cint; LibraryLibAllegroImp;
+  procedure remove_keyboard; LibraryLibAllegroImp;
+  function _install_allegro_version_check (system_id: cint; errno_ptr: Pcint; atexit_ptr: AtExitFunction; version: cint): cint; LibraryLibAllegroImp;
+
+  function install_allegro (system_id: cint; errno_ptr: Pcint; atexit_ptr: AtExitFunction): cint; inline; (* macros *)
+  function allegro_init: cint; inline; (* macros *)
+
+  function install_timer: cint; LibraryLibAllegroImp;
+  procedure remove_timer; LibraryLibAllegroImp;
+  procedure set_keyboard_rate (delay, _repeat: cint); LibraryLibAllegroImp;
+  function makeacol (r, g, b, a: cint): cint; LibraryLibAllegroImp;
+  function makecol (r, g, b: cint): cint; LibraryLibAllegroImp;
+  procedure clear_to_color (source: PBITMAP; color: cint); LibraryLibAllegroImp;
+  procedure putpixel (bmp: PBITMAP; x, y, color: cint); LibraryLibAllegroImp;
+  procedure fastline (bmp: PBITMAP; x1, y_1, x2, y2, color: cint); LibraryLibAllegroImp;
+  procedure draw_sprite (bmp, sprite: PBITMAP; x, y: cint); LibraryLibAllegroImp;
+  procedure rect (bmp: PBITMAP; x1, y_1, x2, y2, color: cint); LibraryLibAllegroImp;
+  procedure rectfill (bmp: PBITMAP; x1, y_1, x2, y2, color: cint); LibraryLibAllegroImp;
+  function create_bitmap (width, height: cint): PBITMAP; LibraryLibAllegroImp;
+  function create_system_bitmap (width, height: cint): PBITMAP; LibraryLibAllegroImp;
+  procedure allegro_exit; LibraryLibAllegroImp;
+
+//  function _install_allegro (system_id: cint; errno_prt: Pcint; AtExitFunction): cint; LibraryLibAllegroImp;
+
+implementation
+
+  function install_allegro (system_id: cint; errno_ptr: Pcint; atexit_ptr: AtExitFunction): cint; inline;
+  begin
+    install_allegro := _install_allegro_version_check(system_id, errno_ptr, atexit_ptr, (ALLEGRO_VERSION shl 16) OR (ALEGRO_SUB_VERSION shl 8) OR ALLEGRO_WIP_VERSION)
+  end;
+
+  function allegro_init: cint; inline;
+  begin
+    (* original macros sets atexit_ptr *)
+    (* original macros sets libc errno? *)
+    allegro_init := _install_allegro_version_check(SYSTEM_AUTODETECT, nil, nil, (ALLEGRO_VERSION shl 16) OR (ALEGRO_SUB_VERSION shl 8) OR ALLEGRO_WIP_VERSION)
+  end;
+
+end.
index 0e1566cf757aa8893dbad8285e1fe91ce8ac7f59..955c236768283309a6aa56f63a3366509acad395 100644 (file)
@@ -170,12 +170,14 @@ interface
   procedure nogl_Init;
   procedure nogl_Quit;
 
-{$IFDEF USE_GLES1}}
+{$IF DEFINED(USE_GLES1)}
   {$I noGLES1.inc}
+{$ELSEIF DEFINED(USE_GLALSW)}
+  {$I noGLALSW.inc}
+{$ELSEIF DEFINED(USE_GLSTUB)}
+  {$I noGLSTUB.inc}
 {$ELSE}
-  {$IFDEF USE_GLSTUB}
-    {$I noGLSTUB.inc}
-  {$ENDIF}
+  {$ERROR use one of gl wrapper: USE_GLES1 USE_GLALSW USE_GLSTUB}}
 {$ENDIF}
 
 end.
diff --git a/src/nogl/noGLALSW.inc b/src/nogl/noGLALSW.inc
new file mode 100644 (file)
index 0000000..60b2072
--- /dev/null
@@ -0,0 +1,447 @@
+implementation
+
+  uses Allegro, Math, SDL2, e_Log;
+
+  const
+    GL_INVALID_ENUM = $0500;
+
+  const
+    ValPerVertex = 2;
+    ValPerColor = 4;
+    ValPerCoord = 2;
+
+  type
+    TArrayFloat = array of Integer;
+
+    TCmds = record
+      mode: GLenum;
+      v, c, t: TArrayFloat;
+    end;
+
+    TArrayTexture = array of record
+      used: Boolean;
+      bmp: PBITMAP;
+    end;
+
+  var
+    cmds: TCmds;
+    tex: TArrayTexture;
+    ctex: Integer;
+    ccol: Integer;
+
+  function AddTexture: Integer;
+    var i: Integer;
+  begin
+    for i := 0 to High(tex) do
+      if not tex[i].used then
+      begin
+        tex[i].used := true;
+        tex[i].bmp := nil;
+        result := i;
+        exit
+      end;
+    i :=  Length(tex);
+    SetLength(tex, i + 1);
+    tex[i].used := true;
+    tex[i].bmp := nil;
+    result := i
+  end;
+
+  procedure RemoveTexture(i: Integer);
+  begin
+    assert(i >= 0);
+    assert(i <= High(tex));
+    assert(tex[i].used);
+    tex[i].used := false;
+    if tex[i].bmp <> nil then
+      destroy_bitmap(tex[i].bmp)
+  end;
+
+  procedure Add (var x: TArrayFloat; f: Integer);
+    var i: Integer;
+  begin
+    i := Length(x);
+    SetLength(x, i + 1);
+    x[i] := f;
+  end;
+
+  (** Open GL **)
+
+  procedure glEnable(cap: GLenum);
+  begin
+  end;
+
+  procedure glDisable(cap: GLenum);
+  begin
+  end;
+
+  function glIsEnabled(cap: GLenum): GLboolean;
+  begin
+    result := 0
+  end;
+
+  function glGetString(name: GLenum): PChar;
+  begin
+    result := ''
+  end;
+
+  procedure glClearColor(red, green, blue, alpha: GLclampf);
+    var color: Integer;
+  begin
+    color := makeacol(floor(red * 255), floor(green * 255), floor(blue * 255), floor(alpha * 255));
+    clear_to_color(sdl2allegro_screen, color)
+  end;
+
+  procedure glClear(mask: GLbitfield);
+  begin
+  end;
+
+  procedure glAlphaFunc(func: GLenum; ref: GLclampf);
+  begin
+  end;
+
+  procedure glBlendFunc(sfactor, dfactor: GLenum);
+  begin
+  end;
+
+  procedure glPointSize(size: GLfloat);
+  begin
+  end;
+
+  procedure glLineWidth(width: GLfloat);
+  begin
+  end;
+
+  procedure glGetIntegerv(pname: GLenum; params: PGLint);
+  begin
+    params^ := 0
+  end;
+
+  procedure glFlush;
+  begin
+  end;
+
+  procedure glFinish;
+  begin
+  end;
+
+  procedure glBegin(mode: GLenum);
+  begin
+    assert(cmds.mode = GL_INVALID_ENUM);
+    assert((mode = GL_POINTS) or (mode = GL_LINES) or (mode = GL_QUADS));
+    cmds.mode := mode;
+    SetLength(cmds.v, 0);
+    SetLength(cmds.c, 0);
+    SetLength(cmds.t, 0);
+  end;
+
+  procedure glEnd;
+    var i, x, y, w, h: Integer;
+  begin
+    assert(cmds.mode <> GL_INVALID_ENUM);
+    assert(Length(cmds.v) mod ValPerVertex = 0);
+    assert(Length(cmds.c) mod ValPerColor = 0);
+    assert(Length(cmds.t) mod ValPerCoord = 0);
+
+    case cmds.mode of
+    GL_POINTS:
+      begin
+         (* implement case for texture coords? *)
+         if Length(cmds.c) <> 0 then
+         begin
+           assert(Length(cmds.c) * 2 = Length(cmds.v)); (* not enough colors *)
+           for i := 0 to Length(cmds.v) div 2 - 1 do
+             putpixel(sdl2allegro_screen, cmds.v[i * 2], cmds.v[i * 2 + 1], cmds.c[i])
+         end
+         else
+         begin
+           for i := 0 to Length(cmds.v) div 2 - 1 do
+             putpixel(sdl2allegro_screen, cmds.v[i * 2], cmds.v[i * 2 + 1], ccol)
+         end
+      end;
+    GL_LINES:
+      begin
+        assert(Length(cmds.v) mod 4 = 0); (* broken line *)
+        (* implement case for texture coords? *)
+        if Length(cmds.c) <> 0 then
+        begin
+          assert(Length(cmds.c) * 2 = Length(cmds.v));
+          for i := 0 to Length(cmds.v) div 4 - 1 do
+            fastline(sdl2allegro_screen, cmds.v[i * 4], cmds.v[i * 4 + 1], cmds.v[i * 4 + 2], cmds.v[i * 4 + 3], cmds.c[i * 2])
+        end
+        else
+        begin
+          for i := 0 to Length(cmds.v) div 4 - 1 do
+            fastline(sdl2allegro_screen, cmds.v[i * 4], cmds.v[i * 4 + 1], cmds.v[i * 4 + 2], cmds.v[i * 4 + 3], ccol)
+        end
+      end;
+    GL_QUADS:
+      begin
+        assert(Length(cmds.v) mod 8 = 0); (* broken quad *)
+        if Length(cmds.t) <> 0 then
+        begin
+          assert(Length(cmds.t) = Length(cmds.v)); (* not enough texture coords *)
+          assert(ctex >= 0);
+          assert(ctex <= High(tex));
+          for i := 0 to Length(cmds.v) div 8 - 1 do
+          begin
+            x := cmds.v[i * 8];
+            y := cmds.v[i * 8 + 1];
+            w := abs(cmds.v[i * 4 + 5] - x);
+            h := abs(cmds.v[i * 4 + 6] - y);
+            //e_LogWriteFLn('Textured Quad %s %s', [w, h]);
+            draw_sprite(sdl2allegro_screen, tex[ctex].bmp, x, y);
+            //rect(sdl2allegro_screen, x, y, w, h, makecol(255, 0, 0))
+          end
+        end
+        else if Length(cmds.c) <> 0 then
+        begin
+          assert(Length(cmds.c) * 2 = Length(cmds.v)); (* not enough colors *)
+          for i := 0 to Length(cmds.v) div 8 - 1 do
+            rectfill(sdl2allegro_screen, cmds.v[i * 8], cmds.v[i * 8 + 1], cmds.v[i * 4 + 5], cmds.v[i * 4 + 6], cmds.c[i * 4])
+        end
+        else
+        begin
+          for i := 0 to Length(cmds.v) div 8 - 1 do
+            rectfill(sdl2allegro_screen, cmds.v[i * 8], cmds.v[i * 8 + 1], cmds.v[i * 4 + 5], cmds.v[i * 4 + 6], ccol)
+        end
+      end;
+    else
+      assert(false)
+    end;
+
+    SetLength(cmds.v, 0);
+    SetLength(cmds.c, 0);
+    SetLength(cmds.t, 0);
+    cmds.mode := GL_INVALID_ENUM;
+  end;
+
+  procedure glVertex2f(x, y: GLfloat);
+  begin
+    Add(cmds.v, ceil(x));
+    Add(cmds.v, ceil(y))
+  end;
+
+  procedure glVertex2i(x, y: GLint);
+  begin
+    Add(cmds.v, x);
+    Add(cmds.v, y)
+  end;
+
+  procedure glColor4f(red, green, blue, alpha: GLfloat);
+  begin
+    ccol := makeacol(floor(red * 255), floor(green * 255), floor(blue * 255), floor(alpha * 255));
+    Add(cmds.c, ccol)
+  end;
+
+  procedure glColor4ub(red, green, blue, alpha: GLubyte);
+  begin
+    ccol := makeacol(red, green, blue, alpha);
+    Add(cmds.c, ccol)
+  end;
+
+  procedure glColor3ub(red, green, blue: GLubyte);
+  begin
+    ccol := makecol(red, green, blue);
+    Add(cmds.c, ccol)
+  end;
+
+  procedure glTexCoord2f(s, t: GLfloat);
+  begin
+    Add(cmds.t, floor(s));
+    Add(cmds.t, floor(t));
+  end;
+
+  procedure glTexCoord2i(s, t: GLint);
+  begin
+    Add(cmds.t, s);
+    Add(cmds.t, t);
+  end;
+
+  procedure glReadPixels(x, y: GLint; width, height: GLsizei; format, atype: GLenum; pixels: Pointer);
+  begin
+  end;
+
+  procedure glLoadIdentity;
+  begin
+  end;
+
+  procedure glMatrixMode(mode: GLenum);
+  begin
+  end;
+
+  procedure glLoadMatrixd(const m: PGLdouble);
+  begin
+    //m[x,y]
+  end;
+
+  procedure glPushMatrix;
+  begin
+  end;
+
+  procedure glPopMatrix;
+  begin
+  end;
+
+  procedure glTranslatef(x, y, z: GLfloat);
+  begin
+  end;
+
+  procedure glRotatef(angle, x, y, z: GLfloat);
+  begin
+  end;
+
+  procedure glScalef(x, y, z: GLfloat);
+  begin
+  end;
+
+  procedure glViewport(x, y: GLint; width, height: GLsizei);
+  begin
+  end;
+
+  procedure glScissor(x, y: GLint; width, height: GLsizei);
+  begin
+  end;
+
+  procedure glStencilMask(mask: GLuint);
+  begin
+  end;
+
+  procedure glStencilFunc(func: GLenum; ref: GLint; mask: GLuint);
+  begin
+  end;
+
+  procedure glStencilOp(fail, zfail, zpass: GLenum);
+  begin
+  end;
+
+  procedure glColorMask(red, green, blue, alpha: GLboolean);
+  begin
+  end;
+
+  procedure glBindTexture(target: GLenum; texture: GLuint);
+  begin
+    assert(target = GL_TEXTURE_2D);
+    ctex := texture;
+  end;
+
+  procedure glGenTextures(n: GLsizei; textures: PGLuint);
+    var i: Integer;
+  begin
+    for i := 0 to n - 1 do
+      textures[i] := AddTexture
+  end;
+
+  procedure glTexEnvi(target: GLenum; pname: GLenum; param: GLint);
+  begin
+  end;
+
+  procedure glTexParameterf(target: GLenum; pname: GLenum; param: GLfloat);
+  begin
+  end;
+
+  procedure glTexParameteri(target: GLenum; pname: GLenum; param: GLint);
+  begin
+  end;
+
+  procedure glTexImage2D(target: GLenum; level, internalformat: GLint; width, height: GLsizei; border: GLint; format, atype: GLenum; const pixels: Pointer);
+    var i, j, adr: Integer; p: PByte;
+  begin
+    assert(target = GL_TEXTURE_2D);
+    assert(level = 0);
+    assert((internalformat = GL_RGBA) or (internalformat = GL_RGB));
+    assert((format = GL_RGBA) or (format = GL_RGB));
+    assert(border = 0);
+    assert(atype = GL_UNSIGNED_BYTE);
+
+    assert(ctex >= 0);
+    assert(ctex <= High(tex));
+    assert(tex[ctex].used);
+
+    if tex[ctex].bmp <> nil then
+      destroy_bitmap(tex[ctex].bmp);
+    //tex[ctex].bmp := create_video_bitmap(width, height);
+    //if tex[ctex].bmp = nil then
+      tex[ctex].bmp := create_system_bitmap(width, height);
+    if tex[ctex].bmp = nil then
+      tex[ctex].bmp := create_bitmap(width, height);
+    assert(tex[ctex].bmp <> nil);
+
+    if pixels = nil then exit;
+
+    p := pixels;
+    if format = GL_RGBA then
+    begin
+      for j := 0 to height - 1 do
+        for i := 0 to width - 1 do
+        begin
+          adr := j * width * 4 + i * 4;
+          putpixel(tex[ctex].bmp, i, height - j, makeacol(p[adr], p[adr + 1], p[adr + 2], p[adr + 3]))
+        end
+    end
+    else
+    begin
+      for j := 0 to height - 1 do
+        for i := 0 to width - 1 do
+        begin
+          adr := j * width * 3 + i * 3;
+          putpixel(tex[ctex].bmp, i, j, makecol(p[adr], p[adr + 1], p[adr + 2]))
+        end
+    end
+  end;
+
+  procedure glTexSubImage2D(target: GLenum; level, xoffset, yoffset: GLint; width, height: GLsizei; format, atype: GLenum; const pixels: Pointer);
+    var i, j, adr: Integer; p: PByte;
+  begin
+    assert(target = GL_TEXTURE_2D);
+    assert(level = 0);
+    assert((format = GL_RGBA) or (format = GL_RGB));
+    assert(atype = GL_UNSIGNED_BYTE);
+
+    assert(ctex >= 0);
+    assert(ctex <= High(tex));
+    assert(tex[ctex].used);
+    
+    assert(xoffset = 0);
+    assert(yoffset = 0);
+
+    if pixels = nil then exit;
+
+    p := pixels;
+    if format = GL_RGBA then
+    begin
+      for j := 0 to height - 1 do
+        for i := 0 to width - 1 do
+        begin
+          adr := j * width * 4 + i * 4;
+          putpixel(tex[ctex].bmp, i, height - j, makeacol(p[adr], p[adr + 1], p[adr + 2], p[adr + 3]))
+        end
+    end
+    else
+    begin
+      for j := 0 to height - 1 do
+        for i := 0 to width - 1 do
+        begin
+          adr := j * width * 3 + i * 3;
+          putpixel(tex[ctex].bmp, i, j, makecol(p[adr], p[adr + 1], p[adr + 2]))
+        end
+    end
+  end;
+
+  procedure glDeleteTextures(n: GLsizei; const textures: PGLuint);
+    var i: Integer;
+  begin
+    for i := 0 to n - 1 do
+      RemoveTexture(textures[i])
+  end;
+
+  procedure nogl_Init;
+  begin
+    cmds.mode := GL_INVALID_ENUM
+  end;
+
+  procedure nogl_Quit;
+  begin
+  end;
+
+initialization
index 02c07fb4bb39a219ccc8b7b6ebc3fb459ef5a8f7..9dcc1b52e9d0b8e77ca7b4832a03216e488725fa 100644 (file)
@@ -1,27 +1,21 @@
-{$IFDEF USE_NANOGL}
+{$IF DEFINED(USE_NANOGL) OR DEFINED(USE_NOGL)}
   {$DEFINE USE_GLES1}
-{$ELSE}
-  {$IFDEF USE_NOGL}
-    {$DEFINE USE_GLES1}
-  {$ENDIF}
 {$ENDIF}
 
-{$IF DEFINED(USE_GLES1) or DEFINED(USE_GLSTUB)}
+{$IF DEFINED(USE_GLES1) OR DEFINED(USE_GLSTUB) OR DEFINED(USE_GLALSW)}
   {$IFNDEF USE_NANOGL}
     {$DEFINE USE_NOGL}
   {$ENDIF}
 {$ENDIF}
 
 {$IF DEFINED(USE_NANOGL) and DEFINED(USE_NOGL)}
-  {$WARNING you can use only one OpenGL ES wrapper}
+  {$ERROR you can use only one OpenGL ES wrapper}
 {$ENDIF}
 
-{$IFDEF USE_NANOGL}
+{$IF DEFINED(USE_NANOGL)}
   nanoGL in '../lib/nanogl/nanoGL.pas',
+{$ELSEIF DEFINED(USE_NOGL) }
+  noGL in '../nogl/noGL.pas',
 {$ELSE}
-  {$IFDEF USE_NOGL}
-    noGL in '../nogl/noGL.pas',
-  {$ELSE}
-    GL, GLExt,
-  {$ENDIF}
+  GL, GLExt,
 {$ENDIF}
index efb88c0e1360fd905b236de0110d9e96e1a9b619..26f2fd218b1f075ab8df0cfe0d94b916e9a588ba 100644 (file)
 {$BOOLEVAL OFF}
 {$COPERATORS ON}
 {$EXTENDEDSYNTAX ON}
-{$IFDEF CPU386}
-  {$IFDEF GO32V2}
-  {$ELSE}
-    {$FPUTYPE SSE}
-  {$ENDIF}
+{$IF DEFINED(CPU386) AND NOT DEFINED(GO32V2)}
+  {$FPUTYPE SSE}
 {$ENDIF}
 {$GOTO ON}
 {$IEEEERRORS OFF}
@@ -55,8 +52,7 @@
 {$VARSTRINGCHECKS OFF}
 
 {$S-} // disable stack checking
-{$IFDEF GO32V2}
-{$ELSE}
+{$IF NOT DEFINED(GO32V2)}
   {$MMX-} // get lost, mmx
 {$ENDIF}
 
index 641cae7ddf44bc4d36a1360e0d3e6bd46394ace1..de20698b5fe0ca95e813a744c7b4f2a49db09199 100644 (file)
@@ -1393,42 +1393,7 @@ function nclamp (v, a, b: Extended): Extended; inline; overload; begin if (v < a
 function snprintf (buf: PAnsiChar; bufsize: SizeUInt; const fmt: PAnsiChar): SizeUInt; cdecl; varargs; external 'msvcrt.dll' name '_snprintf';
 {$ELSE}
   {$IFDEF GO32V2}
-
-function snprintf (buf: PAnsiChar; bufsize: SizeUInt; const fmt: PAnsiChar): SizeUInt;
-begin
-  {$WARNING snprintf not implemented!}
-  buf[0] := #0;
-  result := 0
-end;
-
-function snprintf (buf: PAnsiChar; bufsize: SizeUInt; const fmt: PAnsiChar; x: LongInt): SizeUInt; overload;
-begin
-  {$WARNING snprintf+longint not implemented!}
-  buf[0] := #0;
-  result := 0
-end;
-
-function snprintf (buf: PAnsiChar; bufsize: SizeUInt; const fmt: PAnsiChar; x: PAnsiChar): SizeUInt; overload;
-begin
-  {$WARNING snprintf+string not implemented!}
-  buf[0] := #0;
-  result := 0
-end;
-
-function snprintf (buf: PAnsiChar; bufsize: SizeUInt; const fmt: PAnsiChar; x: Char): SizeUInt; overload;
-begin
-  {$WARNING snprintf+char not implemented!}
-  buf[0] := #0;
-  result := 0
-end;
-
-function snprintf (buf: PAnsiChar; bufsize: SizeUInt; const fmt: PAnsiChar; x: Double): SizeUInt; overload;
-begin
-  {$WARNING snprintf+double not implemented!}
-  buf[0] := #0;
-  result := 0
-end;
-
+function snprintf (buf: PAnsiChar; bufsize: SizeUInt; const fmt: PAnsiChar): SizeUInt; cdecl; varargs; external;
   {$ELSE}
 function snprintf (buf: PAnsiChar; bufsize: SizeUInt; const fmt: PAnsiChar): SizeUInt; cdecl; varargs; external 'libc' name 'snprintf';
   {$ENDIF}
index 0d944b69a13eb5e332ff9a2bd8fda20d735f08c8..06d68c3b729aac02d11e1bac5e6ee5858c821c13 100644 (file)
@@ -1,250 +1,5 @@
-{$INCLUDE ../shared/a_modes.inc}
-{$SCOPEDENUMS OFF}
 unit SDL2_mixer;
 
-interface
-
-  uses SDL2;
-
-  const
-    MIX_INIT_FLAC        = $00000001;
-    MIX_INIT_MOD         = $00000002;
-    MIX_INIT_MODPLUG     = $00000004;
-    MIX_INIT_MP3         = $00000008;
-    MIX_INIT_OGG         = $00000010;
-    MIX_INIT_FLUIDSYNTH  = $00000020;
-
-    MIX_DEFAULT_FREQUENCY = 22050;
-    MIX_DEFAULT_CHANNELS = 2;
-    MIX_MAX_VOLUME       = 128;
-
-{$IFDEF FPC}
-   {$IF DEFINED(ENDIAN_LITTLE)}
-      MIX_DEFAULT_FORMAT = AUDIO_S16LSB;
-   {$ELSEIF DEFINED(ENDIAN_BIG)}
-      MIX_DEFAULT_FORMAT = AUDIO_S16MSB;
-   {$ELSE}
-      {$FATAL Unable to determine endianness.}
-   {$IFEND}
-{$ENDIF}
-
-  type
-    PMix_Chunk = ^TMix_Chunk;
-    TMix_Chunk = record
-      allocated: Integer;
-      abuf: PUInt8;
-      alen: UInt32;
-      volume: UInt8;
-    end;
-
-    PMix_Music = ^TMix_Music;
-    TMix_Music = record end;
-
-    TMix_Fading = (MIX_NO_FADING, MIX_FADING_OUT, MIX_FADING_IN);
-
-    TMix_MusicType = (MUS_NONE,
-                    MUS_CMD,
-                    MUS_WAV,
-                    MUS_MOD,
-                    MUS_MID,
-                    MUS_OGG,
-                    MUS_MP3,
-                    MUS_MP3_MAD,
-                    MUS_FLAC,
-                    MUS_MODPLUG);
-
-  TMix_Channel_Finished = procedure(channel: Integer); cdecl;
-
-  (** procedures **)
-
-  function Mix_GetMusicType(music: TMix_Music): TMix_MusicType;
-  function Mix_Init(flags: Integer): Integer;
-  function Mix_OpenAudio(frequency: Integer; format: UInt16; channels: Integer; chunksize: Integer): Integer;
-  function Mix_GetError: PAnsiChar;
-  function Mix_QuerySpec(frequency: PInt; format: PUInt16; channels: PInt): Integer;
-  function Mix_GetNumChunkDecoders: Integer;
-  function Mix_GetChunkDecoder(index: Integer): PAnsiChar;
-  function Mix_GetNumMusicDecoders: Integer;
-  function Mix_GetMusicDecoder(index: Integer): PAnsiChar;
-  function Mix_AllocateChannels(numchans: Integer): Integer;
-  procedure Mix_ChannelFinished(channel_finished: TMix_Channel_Finished);
-  function Mix_LoadMUS(_file: PAnsiChar): PMix_Music;
-  function Mix_LoadMUS_RW(src: PSDL_RWops; freesrc: Integer): PMix_Music;
-  function Mix_LoadWAV(_file: PAnsiChar): PMix_Chunk;
-  function Mix_LoadWAV_RW(src: PSDL_RWops; freesrc: Integer): PMix_Chunk;
-
-  function Mix_PlayChannel(channel: Integer; chunk: PMix_Chunk; loops: Integer): Integer;
-  function Mix_Volume(channel: Integer; volume: Integer): Integer;
-  function Mix_HaltMusic: Integer;
-  function Mix_PlayMusic(music: PMix_Music; loops: Integer): Integer;
-  function Mix_SetPanning(channel: Integer; left: UInt8; right: UInt8): Integer;
-  procedure Mix_FreeChunk(chunk: PMix_Chunk);
-  procedure Mix_FreeMusic(music: PMix_Music);
-
-  function Mix_VolumeMusic(volume: Integer): Integer;
-  function Mix_HaltChannel(channel: Integer): Integer;
-  procedure Mix_CloseAudio;
-  function Mix_PlayingMusic: Integer;
-  function Mix_Paused(channel: Integer): Integer;
-  procedure Mix_Pause(channel: Integer);
-  procedure Mix_Resume(channel: Integer);
-
-  procedure Mix_PauseMusic;
-  function Mix_PausedMusic: Integer;
-  procedure Mix_ResumeMusic;
-
-implementation
-
-  function Mix_GetMusicType(music: TMix_Music): TMix_MusicType;
-  begin
-    result := TMix_MusicType.MUS_NONE
-  end;
-
-  function Mix_Init(flags: Integer): Integer;
-  begin
-    result := 0
-  end;
-
-  function Mix_OpenAudio(frequency: Integer; format: UInt16; channels: Integer; chunksize: Integer): Integer;
-  begin
-    result := 0
-  end;
-
-  function Mix_GetError: PAnsiChar;
-  begin
-    result := ''
-  end;
-
-  function Mix_QuerySpec(frequency: PInt; format: PUInt16; channels: PInt): Integer;
-  begin
-    result := 0
-  end;
-
-  function Mix_GetNumChunkDecoders: Integer;
-  begin
-    result := 0
-  end;
-
-  function Mix_GetChunkDecoder(index: Integer): PAnsiChar;
-  begin
-    result := ''
-  end;
-
-  function Mix_GetNumMusicDecoders: Integer;
-  begin
-    result := 0
-  end;
-
-  function Mix_GetMusicDecoder(index: Integer): PAnsiChar;
-  begin
-    result := ''
-  end;
-
-  function Mix_AllocateChannels(numchans: Integer): Integer;
-  begin
-    result := 0
-  end;
-
-  procedure Mix_ChannelFinished(channel_finished: TMix_Channel_Finished);
-  begin
-  end;
-
-  function Mix_LoadMUS(_file: PAnsiChar): PMix_Music;
-  begin
-    result := nil
-  end;
-
-  function Mix_LoadMUS_RW(src: PSDL_RWops; freesrc: Integer): PMix_Music;
-  begin
-    result := nil
-  end;
-
-  function Mix_LoadWAV(_file: PAnsiChar): PMix_Chunk;
-  begin
-    Result := Mix_LoadWAV_RW(SDL_RWFromFile(_file, 'rb'), 1);
-  end;
-
-  function Mix_LoadWAV_RW(src: PSDL_RWops; freesrc: Integer): PMix_Chunk;
-  begin
-    result := nil
-  end;
-
-  function Mix_PlayChannel(channel: Integer; chunk: PMix_Chunk; loops: Integer): Integer;
-  begin
-    result := 0
-  end;
-
-  function Mix_Volume(channel: Integer; volume: Integer): Integer;
-  begin
-    result := 0
-  end;
-
-  function Mix_HaltMusic: Integer;
-  begin
-    result := 0
-  end;
-
-  function Mix_PlayMusic(music: PMix_Music; loops: Integer): Integer;
-  begin
-    result := 0
-  end;
-
-  function Mix_SetPanning(channel: Integer; left: UInt8; right: UInt8): Integer;
-  begin
-    result := 0
-  end;
-
-  procedure Mix_FreeChunk(chunk: PMix_Chunk);
-  begin
-  end;
-
-  procedure Mix_FreeMusic(music: PMix_Music);
-  begin
-  end;
-
-  function Mix_VolumeMusic(volume: Integer): Integer;
-  begin
-    result := 0
-  end;
-
-  function Mix_HaltChannel(channel: Integer): Integer;
-  begin
-    result := 0
-  end;
-
-  procedure Mix_CloseAudio;
-  begin
-  end;
-
-  function Mix_PlayingMusic: Integer;
-  begin
-    result := 0
-  end;
-
-  function Mix_Paused(channel: Integer): Integer;
-  begin
-    result := 0
-  end;
-
-  procedure Mix_Pause(channel: Integer);
-  begin
-  end;
-
-  procedure Mix_Resume(channel: Integer);
-  begin
-  end;
-
-  procedure Mix_PauseMusic;
-  begin
-  end;
-
-  function Mix_PausedMusic: Integer;
-  begin
-    result := 0
-  end;
-
-  procedure Mix_ResumeMusic;
-  begin
-  end;
+{$INCLUDE sdl2stub_mixer.inc}
 
 end.
index 873ada58d501333377ef87b393245446871ea614..465d00a09a2219338d9db4f71a7e0f511dd6b5d0 100644 (file)
@@ -1,616 +1,9 @@
-{$INCLUDE ../shared/a_modes.inc}
-{$SCOPEDENUMS OFF}
 unit sdl2;
 
-interface
-
-  {$I sdltype.inc}
-  {$I sdlscancode.inc}
-
-  const
-    SDL_HAT_CENTERED  = $00;
-    SDL_HAT_UP        = $01;
-    SDL_HAT_RIGHT     = $02;
-    SDL_HAT_DOWN      = $04;
-    SDL_HAT_LEFT      = $08;
-    SDL_HAT_RIGHTUP   = SDL_HAT_RIGHT or SDL_HAT_UP;
-    SDL_HAT_RIGHTDOWN = SDL_HAT_RIGHT or SDL_HAT_DOWN;
-    SDL_HAT_LEFTUP    = SDL_HAT_LEFT or SDL_HAT_UP;
-    SDL_HAT_LEFTDOWN  = SDL_HAT_LEFT or SDL_HAT_DOWN;
-
-  const
-    AUDIO_U8      = $0008;
-    AUDIO_S8      = $8008;
-    AUDIO_U16LSB  = $0010;
-    AUDIO_S16LSB  = $8010;
-    AUDIO_U16MSB  = $1010;
-    AUDIO_S16MSB  = $9010;
-    AUDIO_U16     = AUDIO_U16LSB;
-    AUDIO_S16     = AUDIO_S16LSB;
-
-  const
-    SDL_TOUCH_MOUSEID = UInt32(-1);
-
-  type
-    PSDL_Window = ^TSDL_Window;
-    TSDL_Window = record end;
-
-    PSDL_Joystick = Pointer;
-    TSDL_JoystickGUID = record
-      data: array[0..15] of UInt8;
-    end;
-    TSDL_JoystickID = SInt32;
-
-    PSDL_RWops = ^TSDL_RWops;
-
-    TSize = function(context: PSDL_RWops): SInt64; cdecl;
-    TSeek = function(context: PSDL_RWops; offset: SInt64; whence: SInt32): SInt64; cdecl;
-    TRead = function(context: PSDL_RWops; ptr: Pointer; size: size_t; maxnum: size_t): size_t; cdecl;
-    TWrite = function(context: PSDL_RWops; const ptr: Pointer; size: size_t; num: size_t): size_t; cdecl;
-    TClose = function(context: PSDL_RWops): SInt32; cdecl;
-
-    TStdio = record
-      autoclose: TSDL_Bool;
-      fp: file;
-    end;
-
-    TMem = record
-      base: PUInt8;
-      here: PUInt8;
-      stop: PUInt8;
-    end;
-
-    TUnknown = record
-      data1: Pointer;
-    end;
-
-    TSDL_RWops = packed record
-      size: TSize;
-      seek: TSeek;
-      read: TRead;
-      write: TWrite;
-      close: TClose;
-      _type: UInt32;
-    case Integer of
-      0: (stdio: TStdio);
-      1: (mem: TMem);
-      2: (unknown: TUnknown);
-      {$IFDEF ANDROID}
-      3: (androidio: TAndroidIO);
-      {$ENDIF}
-      {$IFDEF WINDOWS}
-      3: (windowsio: TWindowsIO);
-      {$ENDIF}
-    end;
-
-    PSDL_TouchID  = ^TSDL_TouchID;
-    TSDL_TouchID  = SInt64;
-
-    PSDL_FingerID = ^TSDL_FingerID;
-    TSDL_FingerID = SInt64;
-
-
-  const
-    { Touch events }
-    SDL_FINGERDOWN      = $700;
-    SDL_FINGERUP        = $701;
-    SDL_FINGERMOTION    = $702;
-
-  type
-    TSDL_TouchFingerEvent = record
-      type_: UInt32;
-      timestamp: UInt32;
-      touchId: TSDL_TouchID;
-      fingerId: TSDL_FingerID;
-      x, y, dx, dy: Float;
-      pressure: Float;
-    end;
-
-
-  const
-    SDL_WINDOWPOS_CENTERED_MASK = $2FFF0000;
-    SDL_WINDOWPOS_CENTERED = SDL_WINDOWPOS_CENTERED_MASK or 0;
-
-  type
-    PSDL_DisplayMode = ^TSDL_DisplayMode;
-    TSDL_DisplayMode = record
-      format: UInt32;
-      w: SInt32;
-      h: SInt32;
-      refresh_rate: SInt32;
-      driverdata: Pointer;
-    end;
-
-    TSDL_GLContext = Pointer;
-
-  const
-    SDL_WINDOW_FULLSCREEN = $00000001;
-    SDL_WINDOW_OPENGL = $00000002;
-    SDL_WINDOW_SHOWN = $00000004;
-    SDL_WINDOW_HIDDEN = $00000008;
-    SDL_WINDOW_BORDERLESS = $00000010;
-    SDL_WINDOW_RESIZABLE = $00000020;
-    SDL_WINDOW_MINIMIZED = $00000040;
-    SDL_WINDOW_MAXIMIZED = $00000080;
-    SDL_WINDOW_INPUT_GRABBED = $00000100;
-    SDL_WINDOW_INPUT_FOCUS = $00000200;
-    SDL_WINDOW_MOUSE_FOCUS = $00000400;
-    SDL_WINDOW_FULLSCREEN_DESKTOP = SDL_WINDOW_FULLSCREEN or $00001000;
-    SDL_WINDOW_FOREIGN = $00000800;
-    SDL_WINDOW_ALLOW_HIGHDPI = $00002000;
-
-    SDL_WINDOWEVENT_EXPOSED = 3;
-    SDL_WINDOWEVENT_MOVED = 4;
-    SDL_WINDOWEVENT_RESIZED = 5;
-    SDL_WINDOWEVENT_MINIMIZED = 7;
-    SDL_WINDOWEVENT_MAXIMIZED = 8;
-    SDL_WINDOWEVENT_RESTORED = 9;
-    SDL_WINDOWEVENT_FOCUS_GAINED = 12;
-    SDL_WINDOWEVENT_FOCUS_LOST = 13;
-
-    SDL_DISABLE = 0;
-    SDL_ENABLE = 1;
-
-    SDL_TEXTINPUTEVENT_TEXT_SIZE = 32;
-
-    SDL_FIRSTEVENT       = 0;
-    SDL_COMMONEVENT      = 1;
-    SDL_QUITEV           = $100;
-    SDL_WINDOWEVENT      = $200;
-    SDL_KEYDOWN          = $300;
-    SDL_KEYUP            = $301;
-    //SDL_TEXTEDITING      = $302;
-    SDL_TEXTINPUT        = $303;
-
-  type
-    TSDL_WindowEvent = record
-      type_: UInt32;       // SDL_WINDOWEVENT
-      timestamp: UInt32;
-      windowID: UInt32;    // The associated window
-      event: UInt8;        // SDL_WindowEventID
-      padding1: UInt8;
-      padding2: UInt8;
-      padding3: UInt8;
-      data1: SInt32;       // event dependent data
-      data2: SInt32;       // event dependent data
-    end;
-
-    PSDL_Keysym = ^TSDL_Keysym;
-    TSDL_Keysym = record
-      scancode: TSDL_ScanCode;      // SDL physical key code - see SDL_Scancode for details
-      sym: TSDL_KeyCode;            // SDL virtual key code - see SDL_Keycode for details
-      _mod: UInt16;                 // current key modifiers
-      unicode: UInt32;              // (deprecated) use SDL_TextInputEvent instead
-    end;
-
-    TSDL_KeyboardEvent = record
-      type_: UInt32;        // SDL_KEYDOWN or SDL_KEYUP
-      timestamp: UInt32;
-      windowID: UInt32;     // The window with keyboard focus, if any
-      state: UInt8;         // SDL_PRESSED or SDL_RELEASED
-      _repeat: UInt8;       // Non-zero if this is a key repeat
-      padding2: UInt8;
-      padding3: UInt8;
-      keysym: TSDL_KeySym;  // The key that was pressed or released
-    end;
-
-    TSDL_TextInputEvent = record
-      type_: UInt32;                                          // SDL_TEXTINPUT
-      timestamp: UInt32;
-      windowID: UInt32;                                       // The window with keyboard focus, if any
-      text: array[0..SDL_TEXTINPUTEVENT_TEXT_SIZE] of Char;   // The input text
-    end;
-
-    TSDL_QuitEvent = record
-      type_: UInt32;        // SDL_QUIT
-      timestamp: UInt32;
-    end;
-
-    PSDL_Event = ^TSDL_Event;
-    TSDL_Event = record
-      case Integer of
-      0:  (type_: UInt32);
-      //SDL_COMMONEVENT:  (common: TSDL_CommonEvent);
-      SDL_WINDOWEVENT:  (window: TSDL_WindowEvent);
-      SDL_KEYUP,
-      SDL_KEYDOWN:  (key: TSDL_KeyboardEvent);
-      //SDL_TEXTEDITING:  (edit: TSDL_TextEditingEvent);
-      SDL_TEXTINPUT:  (text: TSDL_TextInputEvent);
-      //SDL_MOUSEMOTION:  (motion: TSDL_MouseMotionEvent);
-      //SDL_MOUSEBUTTONUP,
-      //SDL_MOUSEBUTTONDOWN:  (button: TSDL_MouseButtonEvent);
-      //SDL_MOUSEWHEEL:  (wheel: TSDL_MouseWheelEvent);
-      //SDL_JOYAXISMOTION:  (jaxis: TSDL_JoyAxisEvent);
-      //SDL_JOYBALLMOTION: (jball: TSDL_JoyBallEvent);
-      //SDL_JOYHATMOTION: (jhat: TSDL_JoyHatEvent);
-      //SDL_JOYBUTTONDOWN,
-      //SDL_JOYBUTTONUP: (jbutton: TSDL_JoyButtonEvent);
-      //SDL_JOYDEVICEADDED,
-      //SDL_JOYDEVICEREMOVED: (jdevice: TSDL_JoyDeviceEvent);
-      //SDL_CONTROLLERAXISMOTION: (caxis: TSDL_ControllerAxisEvent);
-      //SDL_CONTROLLERBUTTONUP,
-      //SDL_CONTROLLERBUTTONDOWN: (cbutton: TSDL_ControllerButtonEvent);
-      //SDL_CONTROLLERDEVICEADDED,
-      //SDL_CONTROLLERDEVICEREMOVED,
-      //SDL_CONTROLLERDEVICEREMAPPED: (cdevice: TSDL_ControllerDeviceEvent);
-      //SDL_AUDIODEVICEADDED,
-      //SDL_AUDIODEVICEREMOVED: (adevice: TSDL_AudioDeviceEvent);
-      SDL_QUITEV: (quit: TSDL_QuitEvent);
-      //SDL_USEREVENT: (user: TSDL_UserEvent);
-      //SDL_SYSWMEVENT: (syswm: TSDL_SysWMEvent);
-      SDL_FINGERDOWN,
-      SDL_FINGERUP,
-      SDL_FINGERMOTION: (tfinger: TSDL_TouchFingerEvent);
-      //SDL_MULTIGESTURE: (mgesture: TSDL_MultiGestureEvent);
-      //SDL_DOLLARGESTURE,SDL_DOLLARRECORD: (dgesture: TSDL_DollarGestureEvent);
-      //SDL_DROPFILE: (drop: TSDL_DropEvent);
-    end;
-
-  const
-    SDL_GL_RED_SIZE = 0;
-    SDL_GL_GREEN_SIZE = 1;
-    SDL_GL_BLUE_SIZE = 2;
-    SDL_GL_ALPHA_SIZE = 3;
-    SDL_GL_BUFFER_SIZE = 4;
-    SDL_GL_DOUBLEBUFFER = 5;
-    SDL_GL_DEPTH_SIZE = 6;
-    SDL_GL_STENCIL_SIZE = 7;
-    SDL_GL_ACCUM_RED_SIZE = 8;
-    SDL_GL_ACCUM_GREEN_SIZE = 9;
-    SDL_GL_ACCUM_BLUE_SIZE = 10;
-    SDL_GL_ACCUM_ALPHA_SIZE = 11;
-    SDL_GL_STEREO = 12;
-    SDL_GL_MULTISAMPLEBUFFERS = 13;
-    SDL_GL_MULTISAMPLESAMPLES = 14;
-    SDL_GL_ACCELERATED_VISUAL = 15;
-    SDL_GL_RETAINED_BACKING = 16;
-    SDL_GL_CONTEXT_MAJOR_VERSION = 17;
-    SDL_GL_CONTEXT_MINOR_VERSION = 18;
-    SDL_GL_CONTEXT_EGL = 19;
-    SDL_GL_CONTEXT_FLAGS = 20;
-    SDL_GL_CONTEXT_PROFILE_MASK = 21;
-    SDL_GL_SHARE_WITH_CURRENT_CONTEXT = 22;
-    SDL_GL_FRAMEBUFFER_SRGB_CAPABLE = 23;
-
-  type
-    TSDL_GLattr = DWord;
-
-  const
-    SDL_INIT_TIMER          = $00000001;
-    SDL_INIT_AUDIO          = $00000010;
-    SDL_INIT_VIDEO          = $00000020;
-    SDL_INIT_JOYSTICK       = $00000200;
-    SDL_INIT_HAPTIC         = $00001000;
-    SDL_INIT_GAMECONTROLLER = $00002000;  //turn on game controller also implicitly does JOYSTICK
-    SDL_INIT_NOPARACHUTE    = $00100000;  //Don't catch fatal signals
-    SDL_INIT_EVERYTHING     = SDL_INIT_TIMER or SDL_INIT_AUDIO or
-                              SDL_INIT_VIDEO or SDL_INIT_JOYSTICK or
-                              SDL_INIT_HAPTIC or SDL_INIT_GAMECONTROLLER;
-
-    SDL_HINT_ACCELEROMETER_AS_JOYSTICK = 'SDL_ACCELEROMETER_AS_JOYSTICK';
-
-  /// MACRO ///
-  function SDL_BITSPERPIXEL(X: Cardinal): Cardinal;
-
-  /// FUNCTIONS ///
-
-  function SDL_SetWindowGammaRamp(window: PSDL_Window; const red: PUInt16; const green: PUInt16; const blue: PUInt16): SInt32;
-  function SDL_GetWindowGammaRamp(window: PSDL_Window; red: PUInt16; green: PUInt16; blue: PUInt16): SInt32;
-
-  function SDL_NumJoysticks: SInt32;
-  function SDL_JoystickOpen(device_index: SInt32): PSDL_Joystick;
-  function SDL_JoystickName(joystick: PSDL_Joystick): PAnsiChar;
-  function SDL_JoystickNumAxes(joystick: PSDL_Joystick): SInt32;
-  function SDL_JoystickNumButtons(joystick: PSDL_Joystick): SInt32;
-  function SDL_JoystickNumHats(joystick: PSDL_Joystick): SInt32;
-  procedure SDL_JoystickClose(joystick: PSDL_Joystick);
-  procedure SDL_JoystickUpdate;
-  function SDL_JoystickGetButton(joystick: PSDL_Joystick; button: SInt32): UInt8;
-  function SDL_JoystickGetAxis(joystick: PSDL_Joystick; axis: SInt32): SInt16;
-  function SDL_JoystickGetHat(joystick: PSDL_Joystick; hat: SInt32): UInt8;
-  
-  function SDL_GetScancodeName(scancode: TSDL_ScanCode): PAnsiChar;
-
-  function SDL_GetPerformanceCounter: UInt64;
-  function SDL_GetPerformanceFrequency: UInt64;
-  
-  function SDL_RWFromFile(const _file: PAnsiChar; const mode: PAnsiChar): PSDL_RWops;
-  function SDL_RWFromConstMem(const mem: Pointer; size: SInt32): PSDL_RWops;
-
-  function SDL_GetDisplayDPI(displayIndex: SInt32; ddpi, hdpi, vdpi: PFloat): SInt32;
-  function SDL_IsTextInputActive: TSDL_Bool;
-  procedure SDL_StartTextInput;
-  procedure SDL_StopTextInput;
-  function SDL_GetNumTouchDevices: SInt32;
-
-  function SDL_GetDesktopDisplayMode(displayIndex: SInt32; mode: PSDL_DisplayMode): SInt32;
-  function SDL_GetClosestDisplayMode(displayIndex: SInt32; const mode: PSDL_DisplayMode; closest: PSDL_DisplayMode): PSDL_DisplayMode;
-
-  procedure SDL_DestroyWindow(window: PSDL_Window);
-  procedure SDL_GL_DeleteContext(context: TSDL_GLContext);
-  procedure SDL_RestoreWindow(window: PSDL_Window);
-  procedure SDL_SetWindowSize(window: PSDL_Window; w: SInt32; h: SInt32);
-  function SDL_CreateWindow(const title: PAnsiChar; x: SInt32; y: SInt32; w: SInt32; h: SInt32; flags: UInt32): PSDL_Window;
-  function SDL_SetWindowFullscreen(window: PSDL_Window; flags: UInt32): SInt32;
-  function SDL_GL_MakeCurrent(window: PSDL_Window; context: TSDL_GLContext): SInt32;
-  procedure SDL_GetWindowSize(window: PSDL_Window; w: PInt; h: PInt);
-  function SDL_GetNumDisplayModes(displayIndex: SInt32): SInt32;
-  function SDL_GetDisplayMode(displayIndex: SInt32; modeIndex: SInt32; mode: PSDL_DisplayMode): SInt32;
-
-  function SDL_ShowCursor(toggle: SInt32): SInt32;
-  procedure SDL_Delay(ms: UInt32);
-  procedure SDL_GL_SwapWindow(window: PSDL_Window);
-
-  function SDL_GL_CreateContext(window: PSDL_Window): TSDL_GLContext;
-  function SDL_GetTicks: UInt32;
-
-  function SDL_PushEvent(event: PSDL_Event): SInt32;
-  function SDL_PollEvent(event: PSDL_Event): SInt32;
-  function SDL_GL_SetSwapInterval(interval: SInt32): SInt32;
-  function SDL_GL_SetAttribute(attr: TSDL_GLattr; value: SInt32): SInt32;
-  function SDL_GL_GetAttribute(attr: TSDL_GLattr; value: PInt): SInt32;
-
-  function SDL_GetError: PAnsiChar;
-
-  function SDL_Init(flags: UInt32): SInt32;
-  procedure SDL_Quit();
-  function SDL_SetHint( const name: PChar; const value: PChar) : boolean;
-
-implementation
-  /// MACRO ///
-
-  function SDL_BITSPERPIXEL(X: Cardinal): Cardinal;
-  begin
-    Result := (X shr 8) and $FF;
-  end;
-
-  /// FUNCTIONS ////
-
-  function SDL_SetWindowGammaRamp(window: PSDL_Window; const red: PUInt16; const green: PUInt16; const blue: PUInt16): SInt32;
-  begin
-    result := 0
-  end;
-
-  function SDL_GetWindowGammaRamp(window: PSDL_Window; red: PUInt16; green: PUInt16; blue: PUInt16): SInt32;
-  begin
-    result := 0
-  end;
-
-
-  function SDL_NumJoysticks: SInt32;
-  begin
-    result := 0
-  end;
-
-  function SDL_JoystickOpen(device_index: SInt32): PSDL_Joystick;
-  begin
-    result := nil
-  end;
-
-  function SDL_JoystickName(joystick: PSDL_Joystick): PAnsiChar;
-  begin
-    result := ''
-  end;
-
-  function SDL_JoystickNumAxes(joystick: PSDL_Joystick): SInt32;
-  begin
-    result := 0
-  end;
-
-  function SDL_JoystickNumButtons(joystick: PSDL_Joystick): SInt32;
-  begin
-    result := 0
-  end;
-
-  function SDL_JoystickNumHats(joystick: PSDL_Joystick): SInt32;
-  begin
-    result := 0
-  end;
-
-  procedure SDL_JoystickClose(joystick: PSDL_Joystick);
-  begin
-  end;
-
-  procedure SDL_JoystickUpdate;
-  begin
-  end;
-
-  function SDL_JoystickGetButton(joystick: PSDL_Joystick; button: SInt32): UInt8;
-  begin
-    result := 0
-  end;
-
-  function SDL_JoystickGetAxis(joystick: PSDL_Joystick; axis: SInt32): SInt16;
-  begin
-    result := 0
-  end;
-
-  function SDL_JoystickGetHat(joystick: PSDL_Joystick; hat: SInt32): UInt8;
-  begin
-    result := 0
-  end;
-  
-
-
-
-  function SDL_GetScancodeName(scancode: TSDL_ScanCode): PAnsiChar;
-  begin
-    result := ''
-  end;
-
-
-
-
-  function SDL_GetPerformanceCounter: UInt64;
-  begin
-    result := 0
-  end;
-
-  function SDL_GetPerformanceFrequency: UInt64;
-  begin
-    result := 0
-  end;
-
-
-
-  function SDL_RWFromFile(const _file: PAnsiChar; const mode: PAnsiChar): PSDL_RWops;
-  begin
-    result := nil
-  end;
-
-  function SDL_RWFromConstMem(const mem: Pointer; size: SInt32): PSDL_RWops;
-  begin
-    result := nil
-  end;
-
-
-
-
-  function SDL_GetDisplayDPI(displayIndex: SInt32; ddpi, hdpi, vdpi: PFloat): SInt32;
-  begin
-    result := 0
-  end;
-
-  function SDL_IsTextInputActive: TSDL_Bool;
-  begin
-    result := SDL_FALSE
-  end;
-
-  procedure SDL_StartTextInput;
-  begin
-  end;
-
-  procedure SDL_StopTextInput;
-  begin
-  end;
-
-  function SDL_GetNumTouchDevices: SInt32;
-  begin
-    result := 0
-  end;
-
-
-
-  function SDL_GetDesktopDisplayMode(displayIndex: SInt32; mode: PSDL_DisplayMode): SInt32;
-  begin
-    result := 0
-  end;
-
-  function SDL_GetClosestDisplayMode(displayIndex: SInt32; const mode: PSDL_DisplayMode; closest: PSDL_DisplayMode): PSDL_DisplayMode;
-  begin
-    result := nil
-  end;
-
-  procedure SDL_DestroyWindow(window: PSDL_Window);
-  begin
-  end;
-
-  procedure SDL_GL_DeleteContext(context: TSDL_GLContext);
-  begin
-  end;
-
-  procedure SDL_RestoreWindow(window: PSDL_Window);
-  begin
-  end;
-
-  procedure SDL_SetWindowSize(window: PSDL_Window; w: SInt32; h: SInt32);
-  begin
-  end;
-
-  function SDL_CreateWindow(const title: PAnsiChar; x: SInt32; y: SInt32; w: SInt32; h: SInt32; flags: UInt32): PSDL_Window;
-  begin
-    result := nil
-  end;
-
-  function SDL_SetWindowFullscreen(window: PSDL_Window; flags: UInt32): SInt32;
-  begin
-    result := 0
-  end;
-
-  function SDL_GL_MakeCurrent(window: PSDL_Window; context: TSDL_GLContext): SInt32;
-  begin
-    result := 0
-  end;
-
-  procedure SDL_GetWindowSize(window: PSDL_Window; w: PInt; h: PInt);
-  begin
-  end;
-
-  function SDL_GetNumDisplayModes(displayIndex: SInt32): SInt32;
-  begin
-    result := 0
-  end;
-
-  function SDL_GetDisplayMode(displayIndex: SInt32; modeIndex: SInt32; mode: PSDL_DisplayMode): SInt32;
-  begin
-    result := 0
-  end;
-
-  function SDL_ShowCursor(toggle: SInt32): SInt32;
-  begin
-    result := 0
-  end;
-
-  procedure SDL_Delay(ms: UInt32);
-  begin
-  end;
-
-  procedure SDL_GL_SwapWindow(window: PSDL_Window);
-  begin
-  end;
-
-  function SDL_GL_CreateContext(window: PSDL_Window): TSDL_GLContext;
-  begin
-    result := nil
-  end;
-
-  function SDL_GetTicks: UInt32;
-  begin
-    result := 0
-  end;
-
-  function SDL_PushEvent(event: PSDL_Event): SInt32;
-  begin
-    result := 0
-  end;
-
-  function SDL_PollEvent(event: PSDL_Event): SInt32;
-  begin
-    result := 0
-  end;
-
-  function SDL_GL_SetSwapInterval(interval: SInt32): SInt32;
-  begin
-    result := 0
-  end;
-
-  function SDL_GL_SetAttribute(attr: TSDL_GLattr; value: SInt32): SInt32;
-  begin
-    result := 0
-  end;
-
-  function SDL_GL_GetAttribute(attr: TSDL_GLattr; value: PInt): SInt32;
-  begin
-    result := 0
-  end;
-
-  function SDL_GetError: PAnsiChar;
-  begin
-    result := ''
-  end;
-
-  function SDL_Init(flags: UInt32): SInt32;
-  begin
-    result := 0
-  end;
-
-  procedure SDL_Quit();
-  begin
-  end;
-
-  function SDL_SetHint( const name: PChar; const value: PChar) : boolean;
-  begin
-    result := false
-  end;
+{$IF DEFINED(USE_SDL2ALLEGRO)}
+  {$INCLUDE sdl2allegro.inc}
+{$ELSE}
+  {$INCLUDE sdl2stub.inc}
+{$ENDIF}
 
 end.
diff --git a/src/wrappers/sdl2/sdl2allegro.inc b/src/wrappers/sdl2/sdl2allegro.inc
new file mode 100644 (file)
index 0000000..cb5ea6f
--- /dev/null
@@ -0,0 +1,961 @@
+{$INCLUDE ../shared/a_modes.inc}
+{$SCOPEDENUMS OFF}
+
+interface
+
+  uses Allegro;
+
+  {$I sdltype.inc}
+  {$I sdlpixels.inc}
+  {$I sdlscancode.inc}
+
+  const
+    SDL_HAT_CENTERED  = $00;
+    SDL_HAT_UP        = $01;
+    SDL_HAT_RIGHT     = $02;
+    SDL_HAT_DOWN      = $04;
+    SDL_HAT_LEFT      = $08;
+    SDL_HAT_RIGHTUP   = SDL_HAT_RIGHT or SDL_HAT_UP;
+    SDL_HAT_RIGHTDOWN = SDL_HAT_RIGHT or SDL_HAT_DOWN;
+    SDL_HAT_LEFTUP    = SDL_HAT_LEFT or SDL_HAT_UP;
+    SDL_HAT_LEFTDOWN  = SDL_HAT_LEFT or SDL_HAT_DOWN;
+
+  const
+    AUDIO_U8      = $0008;
+    AUDIO_S8      = $8008;
+    AUDIO_U16LSB  = $0010;
+    AUDIO_S16LSB  = $8010;
+    AUDIO_U16MSB  = $1010;
+    AUDIO_S16MSB  = $9010;
+    AUDIO_U16     = AUDIO_U16LSB;
+    AUDIO_S16     = AUDIO_S16LSB;
+
+  const
+    SDL_TOUCH_MOUSEID = UInt32(-1);
+
+  type
+    PSDL_Window = ^TSDL_Window;
+    TSDL_Window = record
+      w, h, mode: Integer; (* Allegro-specific *)
+    end;
+
+    PSDL_Joystick = Pointer;
+    TSDL_JoystickGUID = record
+      data: array[0..15] of UInt8;
+    end;
+    TSDL_JoystickID = SInt32;
+
+    PSDL_RWops = ^TSDL_RWops;
+
+    TSize = function(context: PSDL_RWops): SInt64; cdecl;
+    TSeek = function(context: PSDL_RWops; offset: SInt64; whence: SInt32): SInt64; cdecl;
+    TRead = function(context: PSDL_RWops; ptr: Pointer; size: size_t; maxnum: size_t): size_t; cdecl;
+    TWrite = function(context: PSDL_RWops; const ptr: Pointer; size: size_t; num: size_t): size_t; cdecl;
+    TClose = function(context: PSDL_RWops): SInt32; cdecl;
+
+    TStdio = record
+      autoclose: TSDL_Bool;
+      fp: file;
+    end;
+
+    TMem = record
+      base: PUInt8;
+      here: PUInt8;
+      stop: PUInt8;
+    end;
+
+    TUnknown = record
+      data1: Pointer;
+    end;
+
+    TSDL_RWops = packed record
+      size: TSize;
+      seek: TSeek;
+      read: TRead;
+      write: TWrite;
+      close: TClose;
+      _type: UInt32;
+    case Integer of
+      0: (stdio: TStdio);
+      1: (mem: TMem);
+      2: (unknown: TUnknown);
+      {$IFDEF ANDROID}
+      3: (androidio: TAndroidIO);
+      {$ENDIF}
+      {$IFDEF WINDOWS}
+      3: (windowsio: TWindowsIO);
+      {$ENDIF}
+    end;
+
+    PSDL_TouchID  = ^TSDL_TouchID;
+    TSDL_TouchID  = SInt64;
+
+    PSDL_FingerID = ^TSDL_FingerID;
+    TSDL_FingerID = SInt64;
+
+
+  const
+    { Touch events }
+    SDL_FINGERDOWN      = $700;
+    SDL_FINGERUP        = $701;
+    SDL_FINGERMOTION    = $702;
+
+  type
+    TSDL_TouchFingerEvent = record
+      type_: UInt32;
+      timestamp: UInt32;
+      touchId: TSDL_TouchID;
+      fingerId: TSDL_FingerID;
+      x, y, dx, dy: Float;
+      pressure: Float;
+    end;
+
+
+  const
+    SDL_WINDOWPOS_CENTERED_MASK = $2FFF0000;
+    SDL_WINDOWPOS_CENTERED = SDL_WINDOWPOS_CENTERED_MASK or 0;
+
+  type
+    PSDL_DisplayMode = ^TSDL_DisplayMode;
+    TSDL_DisplayMode = record
+      format: UInt32;
+      w: SInt32;
+      h: SInt32;
+      refresh_rate: SInt32;
+      driverdata: Pointer;
+    end;
+
+    TSDL_GLContext = Pointer;
+
+  const
+    SDL_WINDOW_FULLSCREEN = $00000001;
+    SDL_WINDOW_OPENGL = $00000002;
+    SDL_WINDOW_SHOWN = $00000004;
+    SDL_WINDOW_HIDDEN = $00000008;
+    SDL_WINDOW_BORDERLESS = $00000010;
+    SDL_WINDOW_RESIZABLE = $00000020;
+    SDL_WINDOW_MINIMIZED = $00000040;
+    SDL_WINDOW_MAXIMIZED = $00000080;
+    SDL_WINDOW_INPUT_GRABBED = $00000100;
+    SDL_WINDOW_INPUT_FOCUS = $00000200;
+    SDL_WINDOW_MOUSE_FOCUS = $00000400;
+    SDL_WINDOW_FULLSCREEN_DESKTOP = SDL_WINDOW_FULLSCREEN or $00001000;
+    SDL_WINDOW_FOREIGN = $00000800;
+    SDL_WINDOW_ALLOW_HIGHDPI = $00002000;
+
+    SDL_WINDOWEVENT_EXPOSED = 3;
+    SDL_WINDOWEVENT_MOVED = 4;
+    SDL_WINDOWEVENT_RESIZED = 5;
+    SDL_WINDOWEVENT_MINIMIZED = 7;
+    SDL_WINDOWEVENT_MAXIMIZED = 8;
+    SDL_WINDOWEVENT_RESTORED = 9;
+    SDL_WINDOWEVENT_FOCUS_GAINED = 12;
+    SDL_WINDOWEVENT_FOCUS_LOST = 13;
+
+    SDL_DISABLE = 0;
+    SDL_ENABLE = 1;
+
+    SDL_TEXTINPUTEVENT_TEXT_SIZE = 32;
+
+    SDL_FIRSTEVENT       = 0;
+    SDL_COMMONEVENT      = 1;
+    SDL_QUITEV           = $100;
+    SDL_WINDOWEVENT      = $200;
+    SDL_KEYDOWN          = $300;
+    SDL_KEYUP            = $301;
+    //SDL_TEXTEDITING      = $302;
+    SDL_TEXTINPUT        = $303;
+
+  type
+    TSDL_WindowEvent = record
+      type_: UInt32;       // SDL_WINDOWEVENT
+      timestamp: UInt32;
+      windowID: UInt32;    // The associated window
+      event: UInt8;        // SDL_WindowEventID
+      padding1: UInt8;
+      padding2: UInt8;
+      padding3: UInt8;
+      data1: SInt32;       // event dependent data
+      data2: SInt32;       // event dependent data
+    end;
+
+    PSDL_Keysym = ^TSDL_Keysym;
+    TSDL_Keysym = record
+      scancode: TSDL_ScanCode;      // SDL physical key code - see SDL_Scancode for details
+      sym: TSDL_KeyCode;            // SDL virtual key code - see SDL_Keycode for details
+      _mod: UInt16;                 // current key modifiers
+      unicode: UInt32;              // (deprecated) use SDL_TextInputEvent instead
+    end;
+
+    TSDL_KeyboardEvent = record
+      type_: UInt32;        // SDL_KEYDOWN or SDL_KEYUP
+      timestamp: UInt32;
+      windowID: UInt32;     // The window with keyboard focus, if any
+      state: UInt8;         // SDL_PRESSED or SDL_RELEASED
+      _repeat: UInt8;       // Non-zero if this is a key repeat
+      padding2: UInt8;
+      padding3: UInt8;
+      keysym: TSDL_KeySym;  // The key that was pressed or released
+    end;
+
+    TSDL_TextInputEvent = record
+      type_: UInt32;                                          // SDL_TEXTINPUT
+      timestamp: UInt32;
+      windowID: UInt32;                                       // The window with keyboard focus, if any
+      text: array[0..SDL_TEXTINPUTEVENT_TEXT_SIZE] of Char;   // The input text
+    end;
+
+    TSDL_QuitEvent = record
+      type_: UInt32;        // SDL_QUIT
+      timestamp: UInt32;
+    end;
+
+    PSDL_Event = ^TSDL_Event;
+    TSDL_Event = record
+      case Integer of
+      0:  (type_: UInt32);
+      //SDL_COMMONEVENT:  (common: TSDL_CommonEvent);
+      SDL_WINDOWEVENT:  (window: TSDL_WindowEvent);
+      SDL_KEYUP,
+      SDL_KEYDOWN:  (key: TSDL_KeyboardEvent);
+      //SDL_TEXTEDITING:  (edit: TSDL_TextEditingEvent);
+      SDL_TEXTINPUT:  (text: TSDL_TextInputEvent);
+      //SDL_MOUSEMOTION:  (motion: TSDL_MouseMotionEvent);
+      //SDL_MOUSEBUTTONUP,
+      //SDL_MOUSEBUTTONDOWN:  (button: TSDL_MouseButtonEvent);
+      //SDL_MOUSEWHEEL:  (wheel: TSDL_MouseWheelEvent);
+      //SDL_JOYAXISMOTION:  (jaxis: TSDL_JoyAxisEvent);
+      //SDL_JOYBALLMOTION: (jball: TSDL_JoyBallEvent);
+      //SDL_JOYHATMOTION: (jhat: TSDL_JoyHatEvent);
+      //SDL_JOYBUTTONDOWN,
+      //SDL_JOYBUTTONUP: (jbutton: TSDL_JoyButtonEvent);
+      //SDL_JOYDEVICEADDED,
+      //SDL_JOYDEVICEREMOVED: (jdevice: TSDL_JoyDeviceEvent);
+      //SDL_CONTROLLERAXISMOTION: (caxis: TSDL_ControllerAxisEvent);
+      //SDL_CONTROLLERBUTTONUP,
+      //SDL_CONTROLLERBUTTONDOWN: (cbutton: TSDL_ControllerButtonEvent);
+      //SDL_CONTROLLERDEVICEADDED,
+      //SDL_CONTROLLERDEVICEREMOVED,
+      //SDL_CONTROLLERDEVICEREMAPPED: (cdevice: TSDL_ControllerDeviceEvent);
+      //SDL_AUDIODEVICEADDED,
+      //SDL_AUDIODEVICEREMOVED: (adevice: TSDL_AudioDeviceEvent);
+      SDL_QUITEV: (quit: TSDL_QuitEvent);
+      //SDL_USEREVENT: (user: TSDL_UserEvent);
+      //SDL_SYSWMEVENT: (syswm: TSDL_SysWMEvent);
+      SDL_FINGERDOWN,
+      SDL_FINGERUP,
+      SDL_FINGERMOTION: (tfinger: TSDL_TouchFingerEvent);
+      //SDL_MULTIGESTURE: (mgesture: TSDL_MultiGestureEvent);
+      //SDL_DOLLARGESTURE,SDL_DOLLARRECORD: (dgesture: TSDL_DollarGestureEvent);
+      //SDL_DROPFILE: (drop: TSDL_DropEvent);
+    end;
+
+  const
+    SDL_GL_RED_SIZE = 0;
+    SDL_GL_GREEN_SIZE = 1;
+    SDL_GL_BLUE_SIZE = 2;
+    SDL_GL_ALPHA_SIZE = 3;
+    SDL_GL_BUFFER_SIZE = 4;
+    SDL_GL_DOUBLEBUFFER = 5;
+    SDL_GL_DEPTH_SIZE = 6;
+    SDL_GL_STENCIL_SIZE = 7;
+    SDL_GL_ACCUM_RED_SIZE = 8;
+    SDL_GL_ACCUM_GREEN_SIZE = 9;
+    SDL_GL_ACCUM_BLUE_SIZE = 10;
+    SDL_GL_ACCUM_ALPHA_SIZE = 11;
+    SDL_GL_STEREO = 12;
+    SDL_GL_MULTISAMPLEBUFFERS = 13;
+    SDL_GL_MULTISAMPLESAMPLES = 14;
+    SDL_GL_ACCELERATED_VISUAL = 15;
+    SDL_GL_RETAINED_BACKING = 16;
+    SDL_GL_CONTEXT_MAJOR_VERSION = 17;
+    SDL_GL_CONTEXT_MINOR_VERSION = 18;
+    SDL_GL_CONTEXT_EGL = 19;
+    SDL_GL_CONTEXT_FLAGS = 20;
+    SDL_GL_CONTEXT_PROFILE_MASK = 21;
+    SDL_GL_SHARE_WITH_CURRENT_CONTEXT = 22;
+    SDL_GL_FRAMEBUFFER_SRGB_CAPABLE = 23;
+
+  type
+    TSDL_GLattr = DWord;
+
+  const
+    SDL_INIT_TIMER          = $00000001;
+    SDL_INIT_AUDIO          = $00000010;
+    SDL_INIT_VIDEO          = $00000020;
+    SDL_INIT_JOYSTICK       = $00000200;
+    SDL_INIT_HAPTIC         = $00001000;
+    SDL_INIT_GAMECONTROLLER = $00002000;  //turn on game controller also implicitly does JOYSTICK
+    SDL_INIT_NOPARACHUTE    = $00100000;  //Don't catch fatal signals
+    SDL_INIT_EVERYTHING     = SDL_INIT_TIMER or SDL_INIT_AUDIO or
+                              SDL_INIT_VIDEO or SDL_INIT_JOYSTICK or
+                              SDL_INIT_HAPTIC or SDL_INIT_GAMECONTROLLER;
+
+    SDL_HINT_ACCELEROMETER_AS_JOYSTICK = 'SDL_ACCELEROMETER_AS_JOYSTICK';
+
+  var
+    sdl2allegro_screen: PBITMAP;
+
+  /// FUNCTIONS ///
+
+  function SDL_SetWindowGammaRamp(window: PSDL_Window; const red: PUInt16; const green: PUInt16; const blue: PUInt16): SInt32;
+  function SDL_GetWindowGammaRamp(window: PSDL_Window; red: PUInt16; green: PUInt16; blue: PUInt16): SInt32;
+
+  function SDL_NumJoysticks: SInt32;
+  function SDL_JoystickOpen(device_index: SInt32): PSDL_Joystick;
+  function SDL_JoystickName(joystick: PSDL_Joystick): PAnsiChar;
+  function SDL_JoystickNumAxes(joystick: PSDL_Joystick): SInt32;
+  function SDL_JoystickNumButtons(joystick: PSDL_Joystick): SInt32;
+  function SDL_JoystickNumHats(joystick: PSDL_Joystick): SInt32;
+  procedure SDL_JoystickClose(joystick: PSDL_Joystick);
+  procedure SDL_JoystickUpdate;
+  function SDL_JoystickGetButton(joystick: PSDL_Joystick; button: SInt32): UInt8;
+  function SDL_JoystickGetAxis(joystick: PSDL_Joystick; axis: SInt32): SInt16;
+  function SDL_JoystickGetHat(joystick: PSDL_Joystick; hat: SInt32): UInt8;
+  
+  function SDL_GetScancodeName(scancode: TSDL_ScanCode): PAnsiChar;
+
+  function SDL_GetPerformanceCounter: UInt64;
+  function SDL_GetPerformanceFrequency: UInt64;
+  
+  function SDL_RWFromFile(const _file: PAnsiChar; const mode: PAnsiChar): PSDL_RWops;
+  function SDL_RWFromConstMem(const mem: Pointer; size: SInt32): PSDL_RWops;
+
+  function SDL_GetDisplayDPI(displayIndex: SInt32; ddpi, hdpi, vdpi: PFloat): SInt32;
+  function SDL_IsTextInputActive: TSDL_Bool;
+  procedure SDL_StartTextInput;
+  procedure SDL_StopTextInput;
+  function SDL_GetNumTouchDevices: SInt32;
+
+  function SDL_GetDesktopDisplayMode(displayIndex: SInt32; mode: PSDL_DisplayMode): SInt32;
+  function SDL_GetClosestDisplayMode(displayIndex: SInt32; const mode: PSDL_DisplayMode; closest: PSDL_DisplayMode): PSDL_DisplayMode;
+
+  procedure SDL_DestroyWindow(window: PSDL_Window);
+  procedure SDL_GL_DeleteContext(context: TSDL_GLContext);
+  procedure SDL_RestoreWindow(window: PSDL_Window);
+  procedure SDL_SetWindowSize(window: PSDL_Window; w: SInt32; h: SInt32);
+  function SDL_CreateWindow(const title: PAnsiChar; x: SInt32; y: SInt32; w: SInt32; h: SInt32; flags: UInt32): PSDL_Window;
+  function SDL_SetWindowFullscreen(window: PSDL_Window; flags: UInt32): SInt32;
+  function SDL_GL_MakeCurrent(window: PSDL_Window; context: TSDL_GLContext): SInt32;
+  procedure SDL_GetWindowSize(window: PSDL_Window; w: PInt; h: PInt);
+  function SDL_GetNumDisplayModes(displayIndex: SInt32): SInt32;
+  function SDL_GetDisplayMode(displayIndex: SInt32; modeIndex: SInt32; mode: PSDL_DisplayMode): SInt32;
+
+  function SDL_ShowCursor(toggle: SInt32): SInt32;
+  procedure SDL_Delay(ms: UInt32);
+  procedure SDL_GL_SwapWindow(window: PSDL_Window);
+
+  function SDL_GL_CreateContext(window: PSDL_Window): TSDL_GLContext;
+  function SDL_GetTicks: UInt32;
+
+  function SDL_PushEvent(event: PSDL_Event): SInt32;
+  function SDL_PollEvent(event: PSDL_Event): SInt32;
+  function SDL_GL_SetSwapInterval(interval: SInt32): SInt32;
+  function SDL_GL_SetAttribute(attr: TSDL_GLattr; value: SInt32): SInt32;
+  function SDL_GL_GetAttribute(attr: TSDL_GLattr; value: PInt): SInt32;
+
+  function SDL_GetError: PAnsiChar;
+
+  function SDL_Init(flags: UInt32): SInt32;
+  procedure SDL_Quit();
+  function SDL_SetHint( const name: PChar; const value: PChar) : boolean;
+
+implementation
+
+  uses e_Log, SysUtils;
+
+  const
+    maxKeyBuffer = 64;
+
+  var
+    __crt0_argv: PPchar; cvar; external;
+    myargv: array [0..255] of Pchar;
+    keyring: array [0..maxKeyBuffer - 1] of Integer;
+    keybeg, keyend: Integer;
+
+  function IsEmptyKeyboard: Boolean;
+  begin
+    result := keybeg = keyend
+  end;
+
+  function IsFullKeyboard: Boolean;
+  begin
+    result := (keybeg - 1) mod maxKeyBuffer = keyend
+  end;
+
+  function NextScancode: Integer;
+  begin
+    result := 0;
+    if not IsEmptyKeyboard then
+    begin
+      result := keyring[keybeg];
+      keybeg := (keybeg + 1) mod maxKeyBuffer
+    end
+  end;
+
+  procedure KeyboardWatcher (scancode: Integer); cdecl;
+  begin
+    if not IsFullKeyboard then
+    begin
+      keyring[keyend] := scancode;
+      keyend := (keyend + 1) mod maxKeyBuffer
+    end
+  end;
+
+  /// MACRO ///
+
+//from "sdl_pixels.h"
+
+  function SDL_PIXELFLAG(X: Cardinal): Cardinal;
+  begin
+    Result := (X shr 28) and $0F;
+  end;
+
+  function SDL_PIXELTYPE(X: Cardinal): Cardinal;
+  begin
+    Result := (X shr 24) and $0F;
+  end;
+
+  function SDL_PIXELORDER(X: Cardinal): Cardinal;
+  begin
+    Result := (X shr 20) and $0F;
+  end;
+
+  function SDL_PIXELLAYOUT(X: Cardinal): Cardinal;
+  begin
+    Result := (X shr 16) and $0F;
+  end;
+
+  function SDL_BITSPERPIXEL(X: Cardinal): Cardinal;
+  begin
+    Result := (X shr 8) and $FF;
+  end;
+
+  function SDL_IsPixelFormat_FOURCC(format: Variant): Boolean;
+  begin
+    Result := format and SDL_PIXELFLAG(format) <> 1;
+  end;
+
+  /// FUNCTIONS ////
+
+(********** FILES **********)
+
+  function SDL_RWFromFile(const _file: PAnsiChar; const mode: PAnsiChar): PSDL_RWops;
+  begin
+    result := nil
+  end;
+
+  function SDL_RWFromConstMem(const mem: Pointer; size: SInt32): PSDL_RWops;
+  begin
+    result := nil
+  end;
+
+(********** KEYBOARD **********)
+
+  function SDL_GetScancodeName(scancode: TSDL_ScanCode): PAnsiChar;
+  begin
+    result := ''
+  end;
+
+  function SDL_IsTextInputActive: TSDL_Bool;
+  begin
+    result := SDL_FALSE
+  end;
+
+  procedure SDL_StartTextInput;
+  begin
+  end;
+
+  procedure SDL_StopTextInput;
+  begin
+  end;
+
+(********** JOYSTICK **********)
+
+  function SDL_NumJoysticks: SInt32;
+  begin
+    result := 0
+  end;
+
+  function SDL_JoystickOpen(device_index: SInt32): PSDL_Joystick;
+  begin
+    result := nil
+  end;
+
+  function SDL_JoystickName(joystick: PSDL_Joystick): PAnsiChar;
+  begin
+    result := ''
+  end;
+
+  function SDL_JoystickNumAxes(joystick: PSDL_Joystick): SInt32;
+  begin
+    result := 0
+  end;
+
+  function SDL_JoystickNumButtons(joystick: PSDL_Joystick): SInt32;
+  begin
+    result := 0
+  end;
+
+  function SDL_JoystickNumHats(joystick: PSDL_Joystick): SInt32;
+  begin
+    result := 0
+  end;
+
+  procedure SDL_JoystickClose(joystick: PSDL_Joystick);
+  begin
+  end;
+
+  procedure SDL_JoystickUpdate;
+  begin
+  end;
+
+  function SDL_JoystickGetButton(joystick: PSDL_Joystick; button: SInt32): UInt8;
+  begin
+    result := 0
+  end;
+
+  function SDL_JoystickGetAxis(joystick: PSDL_Joystick; axis: SInt32): SInt16;
+  begin
+    result := 0
+  end;
+
+  function SDL_JoystickGetHat(joystick: PSDL_Joystick; hat: SInt32): UInt8;
+  begin
+    result := 0
+  end;  
+
+(********** TOUCH **********)
+
+  function SDL_GetNumTouchDevices: SInt32;
+  begin
+    result := 0
+  end;
+
+(********** TIMERS **********)
+
+  function SDL_GetPerformanceCounter: UInt64;
+  begin
+    e_LogWriteln('SDL_GetPerformanceCounter');
+    result := 1
+  end;
+
+  function SDL_GetPerformanceFrequency: UInt64;
+  begin
+    e_LogWriteln('SDL_GetPerformanceFrequency');
+    result := 1
+  end;
+
+  procedure SDL_Delay(ms: UInt32);
+  begin
+    e_LogWriteln('SDL_Delay');
+    //allegro_rest(ms)
+  end;
+
+  function SDL_GetTicks: UInt32;
+  begin
+    e_LogWriteln('SDL_GetTicks');
+    result := 1
+  end;
+
+(********** DISPLAY MODES **********)
+
+  function SDL_GetDesktopDisplayMode(displayIndex: SInt32; mode: PSDL_DisplayMode): SInt32;
+  begin
+    e_LogWritefln('SDL_GetDesktopDisplayMode %s', [displayIndex]);
+    result := -1;
+    mode.format := SDL_PIXELFORMAT_UNKNOWN; (* FIXIT *)
+    mode.refresh_rate := 0;
+    mode.driverdata := nil;
+    if get_desktop_resolution(@mode.w, @mode.h) = 0 then
+      result := 0
+  end;
+
+  function SDL_GetClosestDisplayMode(displayIndex: SInt32; const mode: PSDL_DisplayMode; closest: PSDL_DisplayMode): PSDL_DisplayMode;
+  begin
+    e_LogWritefln('SDL_GetClosestDisplayMode %s', [displayIndex]);
+    result := nil;
+  end;
+
+  function SDL_GetNumDisplayModes(displayIndex: SInt32): SInt32;
+    var m: PGFX_MODE_LIST;
+  begin
+    e_LogWritefln('SDL_GetNumDisplayModes %s', [displayIndex]);
+    result := -1;
+    m := get_gfx_mode_list(GFX_AUTODETECT);
+    if m <> nil then
+    begin
+      result := m.num_modes;
+      destroy_gfx_mode_list(m);
+    end
+  end;
+
+  function SDL_GetDisplayMode(displayIndex: SInt32; modeIndex: SInt32; mode: PSDL_DisplayMode): SInt32;
+    var m: PGFX_MODE_LIST;
+  begin
+    e_LogWritefln('SDL_GetDisplayMode %s %s', [displayIndex, modeIndex]);
+    result := -1;
+    m := get_gfx_mode_list(GFX_AUTODETECT);
+    if (m <> nil) and (modeIndex >= 0) and (modeIndex < m.num_modes) then
+    begin
+      mode.format := SDL_PIXELFORMAT_UNKNOWN; (* FIX IT *)
+      mode.w := m.mode[modeIndex].width;
+      mode.h := m.mode[modeIndex].height;
+      mode.refresh_rate := 0;
+      mode.driverdata := nil;
+      destroy_gfx_mode_list(m);
+      result := 0
+    end
+  end;
+
+  function SDL_GetDisplayDPI(displayIndex: SInt32; ddpi, hdpi, vdpi: PFloat): SInt32;
+  begin
+    result := -1
+  end;
+
+(*********** WINDOW MANAGEMENT **********)
+
+  function SDL_CreateWindow(const title: PAnsiChar; x: SInt32; y: SInt32; w: SInt32; h: SInt32; flags: UInt32): PSDL_Window;
+    var window: PSDL_Window; mode: Integer;
+  begin
+    e_LogWritefln('SDL_CreateWindow %s %s %s %s %s %u', [title, x, y, w, h, flags]);
+    result := nil;
+
+    if (flags and (SDL_WINDOW_FULLSCREEN or SDL_WINDOW_FULLSCREEN_DESKTOP)) <> 0 then
+      mode := GFX_AUTODETECT_FULLSCREEN
+    else
+      mode := GFX_AUTODETECT_WINDOWED;
+    mode := GFX_SAFE;
+
+    if set_gfx_mode(mode, w, h, 0, 0) = 0 then
+    begin
+      new(window);
+      set_window_title(title);
+      if sdl2allegro_screen <> nil then
+        destroy_bitmap(sdl2allegro_screen);
+      sdl2allegro_screen := create_video_bitmap(w, h);
+      if sdl2allegro_screen = nil then
+        sdl2allegro_screen := create_system_bitmap(w, h);
+      if sdl2allegro_screen = nil then
+        sdl2allegro_screen := create_bitmap(w, h);
+      assert(sdl2allegro_screen <> nil);
+      window.w := w;
+      window.h := h;
+      window.mode := mode;
+      result := window
+    end
+  end;
+
+  function SDL_SetWindowFullscreen(window: PSDL_Window; flags: UInt32): SInt32;
+    var mode: Integer;
+  begin
+    e_LogWritefln('SDL_SetWindowFullscreen %u', [flags]);
+    result := -1;
+    if window = nil then exit;
+
+    if (flags and (SDL_WINDOW_FULLSCREEN or SDL_WINDOW_FULLSCREEN_DESKTOP)) <> 0 then
+      mode := GFX_AUTODETECT_FULLSCREEN
+    else
+      mode := GFX_AUTODETECT_WINDOWED;
+    mode := GFX_SAFE;
+
+    if set_gfx_mode(mode, window.w, window.h, 0, 0) = 0 then
+    begin
+(* 
+     if sdl2allegro_screen <> nil then
+        destroy_bitmap(sdl2allegro_screen);
+*)
+      sdl2allegro_screen := create_video_bitmap(window.w, window.h);
+      if sdl2allegro_screen = nil then
+        sdl2allegro_screen := create_system_bitmap(window.w, window.h);
+      if sdl2allegro_screen = nil then
+        sdl2allegro_screen := create_bitmap(window.w, window.h);
+      assert(sdl2allegro_screen <> nil);
+      window.mode := mode;
+      result := 0
+    end
+  end;
+
+  procedure SDL_SetWindowSize(window: PSDL_Window; w: SInt32; h: SInt32);
+  begin
+    e_LogWritefln('SDL_SetWindowSize %s %s', [w, h]);
+    if window = nil then exit;
+    if set_gfx_mode(window.mode, w, h, 0, 0) = 0 then
+    begin
+      if sdl2allegro_screen <> nil then
+        destroy_bitmap(sdl2allegro_screen);
+      if sdl2allegro_screen = nil then
+        sdl2allegro_screen := create_system_bitmap(w, h);
+      if sdl2allegro_screen = nil then
+        sdl2allegro_screen := create_bitmap(w, h);
+      sdl2allegro_screen := create_video_bitmap(w, h);
+      assert(sdl2allegro_screen <> nil);
+      window.w := w;
+      window.h := h;
+    end
+  end;
+
+  procedure SDL_DestroyWindow(window: PSDL_Window);
+  begin
+    e_LogWriteln('SDL_DestroyWindow');
+    if window = nil then exit;
+    if sdl2allegro_screen <> nil then
+      destroy_bitmap(sdl2allegro_screen);
+    sdl2allegro_screen := nil;
+    dispose(window)
+  end;
+
+  procedure SDL_GetWindowSize(window: PSDL_Window; w: PInt; h: PInt);
+  begin
+    e_LogWriteln('SDL_GetWindowSize');
+    if window = nil then exit;
+    if w <> nil then
+      w^ := window.w;
+    if h <> nil then
+      h^ := window.h;
+  end;
+
+  procedure SDL_RestoreWindow(window: PSDL_Window);
+  begin
+    e_LogWriteln('SDL_RestoreWindow');
+    if window = nil then exit;
+    (* stub *)
+  end;
+
+  function SDL_SetWindowGammaRamp(window: PSDL_Window; const red: PUInt16; const green: PUInt16; const blue: PUInt16): SInt32;
+  begin
+    e_LogWriteln('SDL_SetWindowGammaRamp');
+    result := -1;
+    if window = nil then exit;
+    result := 0
+  end;
+
+  function SDL_GetWindowGammaRamp(window: PSDL_Window; red: PUInt16; green: PUInt16; blue: PUInt16): SInt32;
+  begin
+    e_LogWriteln('SDL_GetWindowGammaRamp');
+    result := -1;
+    if window = nil then exit;
+    result := 0
+  end;
+
+(********** OPENGL MANAGEMENT **********)
+
+  function SDL_GL_MakeCurrent(window: PSDL_Window; context: TSDL_GLContext): SInt32;
+  begin
+    e_LogWriteln('SDL_GL_MakeCurrent');
+    result := 0
+  end;
+
+  procedure SDL_GL_DeleteContext(context: TSDL_GLContext);
+  begin
+    e_LogWriteln('SDL_GL_DeleteContext');
+  end;
+
+  procedure SDL_GL_SwapWindow(window: PSDL_Window);
+  begin
+    e_LogWriteln('SDL_GL_SwapWindow');
+    assert(sdl2allegro_screen <> nil);
+    show_video_bitmap(sdl2allegro_screen);
+  end;
+
+  function SDL_GL_CreateContext(window: PSDL_Window): TSDL_GLContext;
+  begin
+    e_LogWriteln('SDL_GL_CreateContext');
+    result := window
+  end;
+
+  function SDL_GL_SetSwapInterval(interval: SInt32): SInt32;
+  begin
+    e_LogWritefln('SDL_GL_SetSwapInterval %s', [interval]);
+    result := 0
+  end;
+
+  function SDL_GL_SetAttribute(attr: TSDL_GLattr; value: SInt32): SInt32;
+  begin
+    e_LogWritefln('SDL_GL_SetAttribute %s %s', [attr, value]);
+    result := -1;
+  end;
+
+  function SDL_GL_GetAttribute(attr: TSDL_GLattr; value: PInt): SInt32;
+  begin
+    e_LogWritefln('SDL_GL_GetAttribute %s', [attr]);
+    value^ := 0; result := -1
+  end;
+
+(********** EVENTS **********)
+
+  function SDL_PushEvent(event: PSDL_Event): SInt32;
+  begin
+    e_LogWriteln('SDL_PushEvent');
+    result := 0
+  end;
+
+  function allegro_to_sdl_scancode (x: Integer): Integer;
+  begin
+    x := x and $7F;
+    case x of
+      KEY_A..KEY_Z: result := SDL_SCANCODE_A + (x - KEY_A);
+      KEY_0..KEY_0: result := SDL_SCANCODE_0 + (x - KEY_0);
+      KEY_0_PAD: result := SDL_SCANCODE_KP_0;
+      KEY_1_PAD..KEY_9_PAD: result := SDL_SCANCODE_KP_1 + (x - KEY_1_PAD);
+      KEY_F1..KEY_F12: result := SDL_SCANCODE_F1 + (x - KEY_F1);
+      KEY_ESC: result := SDL_SCANCODE_ESCAPE;
+      KEY_TILDE: result := SDL_SCANCODE_GRAVE;
+      KEY_MINUS: result := SDL_SCANCODE_MINUS;
+      KEY_EQUALS: result := SDL_SCANCODE_EQUALS;
+      KEY_BACKSPACE: result := SDL_SCANCODE_BACKSPACE;
+      KEY_TAB: result := SDL_SCANCODE_TAB;
+      KEY_OPENBRACE: result := SDL_SCANCODE_LEFTBRACKET;
+      KEY_CLOSEBRACE: result := SDL_SCANCODE_RIGHTBRACKET;
+      KEY_ENTER: result := SDL_SCANCODE_RETURN;
+      KEY_COLON: result := SDL_SCANCODE_SEMICOLON;
+      KEY_QUOTE: result := SDL_SCANCODE_APOSTROPHE;
+      KEY_BACKSLASH: result := SDL_SCANCODE_BACKSLASH;
+      KEY_BACKSLASH2: result := SDL_SCANCODE_NONUSHASH; (* ??? *)
+      KEY_COMMA: result := SDL_SCANCODE_COMMA;
+      (*KEY_STOP: result :=;*) (* ??? *)
+      KEY_SLASH: result := SDL_SCANCODE_SLASH;
+      KEY_SPACE: result := SDL_SCANCODE_SPACE;
+      KEY_INSERT: result := SDL_SCANCODE_INSERT;
+      KEY_DEL: result := SDL_SCANCODE_DELETE;
+      KEY_HOME: result := SDL_SCANCODE_HOME;
+      KEY_END: result := SDL_SCANCODE_END;
+      KEY_PGUP: result := SDL_SCANCODE_PAGEUP;
+      KEY_PGDN: result := SDL_SCANCODE_PAGEDOWN;
+      KEY_LEFT: result := SDL_SCANCODE_LEFT;
+      KEY_RIGHT: result := SDL_SCANCODE_RIGHT;
+      KEY_UP: result := SDL_SCANCODE_UP;
+      KEY_DOWN: result := SDL_SCANCODE_DOWN;
+      KEY_SLASH_PAD: result := SDL_SCANCODE_KP_DIVIDE;
+      KEY_ASTERISK: result := SDL_SCANCODE_KP_MULTIPLY;
+      KEY_MINUS_PAD: result := SDL_SCANCODE_KP_MINUS;
+      KEY_PLUS_PAD: result := SDL_SCANCODE_KP_PLUS;
+      KEY_DEL_PAD: result := SDL_SCANCODE_KP_PERIOD;
+      KEY_ENTER_PAD: result := SDL_SCANCODE_KP_ENTER;
+      KEY_PRTSCR: result := SDL_SCANCODE_PRINTSCREEN;
+      KEY_PAUSE: result := SDL_SCANCODE_PAUSE;
+      (*KEY_ABNT_C1: result :=;*) (* ??? *)
+      KEY_YEN: result := SDL_SCANCODE_INTERNATIONAL3;
+      KEY_KANA: result := SDL_SCANCODE_LANG3; (* ??? *)
+      (*KEY_CONVERT: result :=;*) (* ??? *)
+      (*KEY_NOCONVERT: result := ;*) (* ??? *)
+      KEY_AT: result := SDL_SCANCODE_KP_AT;
+      (*KEY_CIRCUMFLEX: result :=;*) (* ??? *)
+      KEY_COLON2: result := SDL_SCANCODE_KP_COLON;
+      (*KEY_KANJI: result :=;*) (* ??? *)
+      KEY_EQUALS_PAD: result := SDL_SCANCODE_KP_EQUALS;
+      (*KEY_BACKQUOTE: result :=;*) (* ??? *)
+      KEY_SEMICOLON: result := SDL_SCANCODE_SEMICOLON;
+      KEY_COMMAND: result := SDL_SCANCODE_LGUI;
+      (*KEY_UNKNOWN1: result :=;*)
+      (*KEY_UNKNOWN2: result :=;*)
+      (*KEY_UNKNOWN3: result :=;*)
+      (*KEY_UNKNOWN4: result :=;*)
+      (*KEY_UNKNOWN5: result :=;*)
+      (*KEY_UNKNOWN6: result :=;*)
+      (*KEY_UNKNOWN7: result :=;*)
+      (*KEY_UNKNOWN8: result :=;*)
+      KEY_LSHIFT: result := SDL_SCANCODE_LSHIFT;
+      KEY_RSHIFT: result := SDL_SCANCODE_RSHIFT;
+      KEY_LCONTROL: result := SDL_SCANCODE_LCTRL;
+      KEY_RCONTROL: result := SDL_SCANCODE_RCTRL;
+      KEY_ALT: result := SDL_SCANCODE_LALT;
+      KEY_ALTGR: result := SDL_SCANCODE_RALT;
+      KEY_LWIN: result := SDL_SCANCODE_LGUI;
+      KEY_RWIN: result := SDL_SCANCODE_RGUI;
+      KEY_MENU: result := SDL_SCANCODE_MODE; (* ??? *)
+      KEY_SCRLOCK: result := SDL_SCANCODE_SCROLLLOCK;
+      KEY_NUMLOCK: result := SDL_SCANCODE_NUMLOCKCLEAR;
+      KEY_CAPSLOCK: result := SDL_SCANCODE_CAPSLOCK;
+    else result := SDL_SCANCODE_UNKNOWN
+    end
+  end;
+
+  function SDL_PollEvent(event: PSDL_Event): SInt32;
+    var alscan: Integer;
+  begin
+    e_LogWriteln('SDL_PollEvent');
+    poll_keyboard;
+    result := 0;
+    if not IsEmptyKeyboard then
+    begin
+      alscan := NextScancode;
+      if alscan and $80 = 0 then
+        event.type_ := SDL_KEYDOWN
+      else
+        event.type_ := SDL_KEYDOWN;
+      event.key.timestamp := 0;
+      event.key.windowID := 0;
+      (* df not use it?
+      if alscan and $80 = 0 then
+        event.key.state := SDL_PRESSED
+      else
+        event.key.state := SDL_RELEASED;
+      *)
+      event.key.keysym.scancode := allegro_to_sdl_scancode(alscan);
+      event.key.keysym.sym := 0; (* df not use it? *)
+      event.key.keysym._mod := 0; (* df not use it? *)
+      result := 1
+    end
+  end;
+
+(********** MOUSE **********)
+
+  function SDL_ShowCursor(toggle: SInt32): SInt32;
+  begin
+    e_LogWritefln('SDL_ShowCursor %s', [toggle]);
+    result := 0
+  end;
+
+(********** SDL **********)
+
+  function SDL_SetHint( const name: PChar; const value: PChar) : boolean;
+  begin
+    e_LogWritefln('SDL_SetHint %s %s', [name, value]);
+    result := false
+  end;
+
+  function SDL_GetError: PAnsiChar;
+  begin
+    e_LogWritefln('SDL_GetError => %s', [allegro_error]);
+    result := allegro_error;
+  end;
+
+  function TestGet: AnsiString;
+  begin
+    result := '+++ Test concat qwertyiop!'
+  end;
+
+  procedure Test;
+  begin
+    // WTF? when 'Test concat qwertyio! ' it not messed!
+    //e_LogWriteln('Test concat qwertyiop! ' + ParamStr(0));
+    e_LogWriteln('Test concat qwertyiop! ' + TestGet);
+  end;
+
+  function SDL_Init(flags: UInt32): SInt32;
+  begin
+    Test;
+    e_LogWritefln('SDL_Init %u', [flags]);
+    result := -1;
+    __crt0_argv := @myargv[0];
+    myargv[0] := PChar(ParamStr(0));
+    e_LogWritefln('argv[0] = %s', [myargv[0]]);
+    if allegro_init = 0 then
+    begin
+      e_LogWriteln('SDL_Init inited! ' + ParamStr(0) + ' ');
+      install_timer;
+      install_keyboard;
+      keyboard_lowlevel_callback := KeyboardWatcher;
+      set_keyboard_rate(0, 0);
+      result := 0
+    end
+  end;
+
+  procedure SDL_Quit;
+  begin
+    e_LogWriteln('SDL_Quit');
+    remove_keyboard;
+    remove_timer;
+    allegro_exit
+  end;
diff --git a/src/wrappers/sdl2/sdl2stub.inc b/src/wrappers/sdl2/sdl2stub.inc
new file mode 100644 (file)
index 0000000..05771cb
--- /dev/null
@@ -0,0 +1,613 @@
+{$INCLUDE ../shared/a_modes.inc}
+{$SCOPEDENUMS OFF}
+
+interface
+
+  {$I sdltype.inc}
+  {$I sdlscancode.inc}
+
+  const
+    SDL_HAT_CENTERED  = $00;
+    SDL_HAT_UP        = $01;
+    SDL_HAT_RIGHT     = $02;
+    SDL_HAT_DOWN      = $04;
+    SDL_HAT_LEFT      = $08;
+    SDL_HAT_RIGHTUP   = SDL_HAT_RIGHT or SDL_HAT_UP;
+    SDL_HAT_RIGHTDOWN = SDL_HAT_RIGHT or SDL_HAT_DOWN;
+    SDL_HAT_LEFTUP    = SDL_HAT_LEFT or SDL_HAT_UP;
+    SDL_HAT_LEFTDOWN  = SDL_HAT_LEFT or SDL_HAT_DOWN;
+
+  const
+    AUDIO_U8      = $0008;
+    AUDIO_S8      = $8008;
+    AUDIO_U16LSB  = $0010;
+    AUDIO_S16LSB  = $8010;
+    AUDIO_U16MSB  = $1010;
+    AUDIO_S16MSB  = $9010;
+    AUDIO_U16     = AUDIO_U16LSB;
+    AUDIO_S16     = AUDIO_S16LSB;
+
+  const
+    SDL_TOUCH_MOUSEID = UInt32(-1);
+
+  type
+    PSDL_Window = ^TSDL_Window;
+    TSDL_Window = record end;
+
+    PSDL_Joystick = Pointer;
+    TSDL_JoystickGUID = record
+      data: array[0..15] of UInt8;
+    end;
+    TSDL_JoystickID = SInt32;
+
+    PSDL_RWops = ^TSDL_RWops;
+
+    TSize = function(context: PSDL_RWops): SInt64; cdecl;
+    TSeek = function(context: PSDL_RWops; offset: SInt64; whence: SInt32): SInt64; cdecl;
+    TRead = function(context: PSDL_RWops; ptr: Pointer; size: size_t; maxnum: size_t): size_t; cdecl;
+    TWrite = function(context: PSDL_RWops; const ptr: Pointer; size: size_t; num: size_t): size_t; cdecl;
+    TClose = function(context: PSDL_RWops): SInt32; cdecl;
+
+    TStdio = record
+      autoclose: TSDL_Bool;
+      fp: file;
+    end;
+
+    TMem = record
+      base: PUInt8;
+      here: PUInt8;
+      stop: PUInt8;
+    end;
+
+    TUnknown = record
+      data1: Pointer;
+    end;
+
+    TSDL_RWops = packed record
+      size: TSize;
+      seek: TSeek;
+      read: TRead;
+      write: TWrite;
+      close: TClose;
+      _type: UInt32;
+    case Integer of
+      0: (stdio: TStdio);
+      1: (mem: TMem);
+      2: (unknown: TUnknown);
+      {$IFDEF ANDROID}
+      3: (androidio: TAndroidIO);
+      {$ENDIF}
+      {$IFDEF WINDOWS}
+      3: (windowsio: TWindowsIO);
+      {$ENDIF}
+    end;
+
+    PSDL_TouchID  = ^TSDL_TouchID;
+    TSDL_TouchID  = SInt64;
+
+    PSDL_FingerID = ^TSDL_FingerID;
+    TSDL_FingerID = SInt64;
+
+
+  const
+    { Touch events }
+    SDL_FINGERDOWN      = $700;
+    SDL_FINGERUP        = $701;
+    SDL_FINGERMOTION    = $702;
+
+  type
+    TSDL_TouchFingerEvent = record
+      type_: UInt32;
+      timestamp: UInt32;
+      touchId: TSDL_TouchID;
+      fingerId: TSDL_FingerID;
+      x, y, dx, dy: Float;
+      pressure: Float;
+    end;
+
+
+  const
+    SDL_WINDOWPOS_CENTERED_MASK = $2FFF0000;
+    SDL_WINDOWPOS_CENTERED = SDL_WINDOWPOS_CENTERED_MASK or 0;
+
+  type
+    PSDL_DisplayMode = ^TSDL_DisplayMode;
+    TSDL_DisplayMode = record
+      format: UInt32;
+      w: SInt32;
+      h: SInt32;
+      refresh_rate: SInt32;
+      driverdata: Pointer;
+    end;
+
+    TSDL_GLContext = Pointer;
+
+  const
+    SDL_WINDOW_FULLSCREEN = $00000001;
+    SDL_WINDOW_OPENGL = $00000002;
+    SDL_WINDOW_SHOWN = $00000004;
+    SDL_WINDOW_HIDDEN = $00000008;
+    SDL_WINDOW_BORDERLESS = $00000010;
+    SDL_WINDOW_RESIZABLE = $00000020;
+    SDL_WINDOW_MINIMIZED = $00000040;
+    SDL_WINDOW_MAXIMIZED = $00000080;
+    SDL_WINDOW_INPUT_GRABBED = $00000100;
+    SDL_WINDOW_INPUT_FOCUS = $00000200;
+    SDL_WINDOW_MOUSE_FOCUS = $00000400;
+    SDL_WINDOW_FULLSCREEN_DESKTOP = SDL_WINDOW_FULLSCREEN or $00001000;
+    SDL_WINDOW_FOREIGN = $00000800;
+    SDL_WINDOW_ALLOW_HIGHDPI = $00002000;
+
+    SDL_WINDOWEVENT_EXPOSED = 3;
+    SDL_WINDOWEVENT_MOVED = 4;
+    SDL_WINDOWEVENT_RESIZED = 5;
+    SDL_WINDOWEVENT_MINIMIZED = 7;
+    SDL_WINDOWEVENT_MAXIMIZED = 8;
+    SDL_WINDOWEVENT_RESTORED = 9;
+    SDL_WINDOWEVENT_FOCUS_GAINED = 12;
+    SDL_WINDOWEVENT_FOCUS_LOST = 13;
+
+    SDL_DISABLE = 0;
+    SDL_ENABLE = 1;
+
+    SDL_TEXTINPUTEVENT_TEXT_SIZE = 32;
+
+    SDL_FIRSTEVENT       = 0;
+    SDL_COMMONEVENT      = 1;
+    SDL_QUITEV           = $100;
+    SDL_WINDOWEVENT      = $200;
+    SDL_KEYDOWN          = $300;
+    SDL_KEYUP            = $301;
+    //SDL_TEXTEDITING      = $302;
+    SDL_TEXTINPUT        = $303;
+
+  type
+    TSDL_WindowEvent = record
+      type_: UInt32;       // SDL_WINDOWEVENT
+      timestamp: UInt32;
+      windowID: UInt32;    // The associated window
+      event: UInt8;        // SDL_WindowEventID
+      padding1: UInt8;
+      padding2: UInt8;
+      padding3: UInt8;
+      data1: SInt32;       // event dependent data
+      data2: SInt32;       // event dependent data
+    end;
+
+    PSDL_Keysym = ^TSDL_Keysym;
+    TSDL_Keysym = record
+      scancode: TSDL_ScanCode;      // SDL physical key code - see SDL_Scancode for details
+      sym: TSDL_KeyCode;            // SDL virtual key code - see SDL_Keycode for details
+      _mod: UInt16;                 // current key modifiers
+      unicode: UInt32;              // (deprecated) use SDL_TextInputEvent instead
+    end;
+
+    TSDL_KeyboardEvent = record
+      type_: UInt32;        // SDL_KEYDOWN or SDL_KEYUP
+      timestamp: UInt32;
+      windowID: UInt32;     // The window with keyboard focus, if any
+      state: UInt8;         // SDL_PRESSED or SDL_RELEASED
+      _repeat: UInt8;       // Non-zero if this is a key repeat
+      padding2: UInt8;
+      padding3: UInt8;
+      keysym: TSDL_KeySym;  // The key that was pressed or released
+    end;
+
+    TSDL_TextInputEvent = record
+      type_: UInt32;                                          // SDL_TEXTINPUT
+      timestamp: UInt32;
+      windowID: UInt32;                                       // The window with keyboard focus, if any
+      text: array[0..SDL_TEXTINPUTEVENT_TEXT_SIZE] of Char;   // The input text
+    end;
+
+    TSDL_QuitEvent = record
+      type_: UInt32;        // SDL_QUIT
+      timestamp: UInt32;
+    end;
+
+    PSDL_Event = ^TSDL_Event;
+    TSDL_Event = record
+      case Integer of
+      0:  (type_: UInt32);
+      //SDL_COMMONEVENT:  (common: TSDL_CommonEvent);
+      SDL_WINDOWEVENT:  (window: TSDL_WindowEvent);
+      SDL_KEYUP,
+      SDL_KEYDOWN:  (key: TSDL_KeyboardEvent);
+      //SDL_TEXTEDITING:  (edit: TSDL_TextEditingEvent);
+      SDL_TEXTINPUT:  (text: TSDL_TextInputEvent);
+      //SDL_MOUSEMOTION:  (motion: TSDL_MouseMotionEvent);
+      //SDL_MOUSEBUTTONUP,
+      //SDL_MOUSEBUTTONDOWN:  (button: TSDL_MouseButtonEvent);
+      //SDL_MOUSEWHEEL:  (wheel: TSDL_MouseWheelEvent);
+      //SDL_JOYAXISMOTION:  (jaxis: TSDL_JoyAxisEvent);
+      //SDL_JOYBALLMOTION: (jball: TSDL_JoyBallEvent);
+      //SDL_JOYHATMOTION: (jhat: TSDL_JoyHatEvent);
+      //SDL_JOYBUTTONDOWN,
+      //SDL_JOYBUTTONUP: (jbutton: TSDL_JoyButtonEvent);
+      //SDL_JOYDEVICEADDED,
+      //SDL_JOYDEVICEREMOVED: (jdevice: TSDL_JoyDeviceEvent);
+      //SDL_CONTROLLERAXISMOTION: (caxis: TSDL_ControllerAxisEvent);
+      //SDL_CONTROLLERBUTTONUP,
+      //SDL_CONTROLLERBUTTONDOWN: (cbutton: TSDL_ControllerButtonEvent);
+      //SDL_CONTROLLERDEVICEADDED,
+      //SDL_CONTROLLERDEVICEREMOVED,
+      //SDL_CONTROLLERDEVICEREMAPPED: (cdevice: TSDL_ControllerDeviceEvent);
+      //SDL_AUDIODEVICEADDED,
+      //SDL_AUDIODEVICEREMOVED: (adevice: TSDL_AudioDeviceEvent);
+      SDL_QUITEV: (quit: TSDL_QuitEvent);
+      //SDL_USEREVENT: (user: TSDL_UserEvent);
+      //SDL_SYSWMEVENT: (syswm: TSDL_SysWMEvent);
+      SDL_FINGERDOWN,
+      SDL_FINGERUP,
+      SDL_FINGERMOTION: (tfinger: TSDL_TouchFingerEvent);
+      //SDL_MULTIGESTURE: (mgesture: TSDL_MultiGestureEvent);
+      //SDL_DOLLARGESTURE,SDL_DOLLARRECORD: (dgesture: TSDL_DollarGestureEvent);
+      //SDL_DROPFILE: (drop: TSDL_DropEvent);
+    end;
+
+  const
+    SDL_GL_RED_SIZE = 0;
+    SDL_GL_GREEN_SIZE = 1;
+    SDL_GL_BLUE_SIZE = 2;
+    SDL_GL_ALPHA_SIZE = 3;
+    SDL_GL_BUFFER_SIZE = 4;
+    SDL_GL_DOUBLEBUFFER = 5;
+    SDL_GL_DEPTH_SIZE = 6;
+    SDL_GL_STENCIL_SIZE = 7;
+    SDL_GL_ACCUM_RED_SIZE = 8;
+    SDL_GL_ACCUM_GREEN_SIZE = 9;
+    SDL_GL_ACCUM_BLUE_SIZE = 10;
+    SDL_GL_ACCUM_ALPHA_SIZE = 11;
+    SDL_GL_STEREO = 12;
+    SDL_GL_MULTISAMPLEBUFFERS = 13;
+    SDL_GL_MULTISAMPLESAMPLES = 14;
+    SDL_GL_ACCELERATED_VISUAL = 15;
+    SDL_GL_RETAINED_BACKING = 16;
+    SDL_GL_CONTEXT_MAJOR_VERSION = 17;
+    SDL_GL_CONTEXT_MINOR_VERSION = 18;
+    SDL_GL_CONTEXT_EGL = 19;
+    SDL_GL_CONTEXT_FLAGS = 20;
+    SDL_GL_CONTEXT_PROFILE_MASK = 21;
+    SDL_GL_SHARE_WITH_CURRENT_CONTEXT = 22;
+    SDL_GL_FRAMEBUFFER_SRGB_CAPABLE = 23;
+
+  type
+    TSDL_GLattr = DWord;
+
+  const
+    SDL_INIT_TIMER          = $00000001;
+    SDL_INIT_AUDIO          = $00000010;
+    SDL_INIT_VIDEO          = $00000020;
+    SDL_INIT_JOYSTICK       = $00000200;
+    SDL_INIT_HAPTIC         = $00001000;
+    SDL_INIT_GAMECONTROLLER = $00002000;  //turn on game controller also implicitly does JOYSTICK
+    SDL_INIT_NOPARACHUTE    = $00100000;  //Don't catch fatal signals
+    SDL_INIT_EVERYTHING     = SDL_INIT_TIMER or SDL_INIT_AUDIO or
+                              SDL_INIT_VIDEO or SDL_INIT_JOYSTICK or
+                              SDL_INIT_HAPTIC or SDL_INIT_GAMECONTROLLER;
+
+    SDL_HINT_ACCELEROMETER_AS_JOYSTICK = 'SDL_ACCELEROMETER_AS_JOYSTICK';
+
+  /// MACRO ///
+  function SDL_BITSPERPIXEL(X: Cardinal): Cardinal;
+
+  /// FUNCTIONS ///
+
+  function SDL_SetWindowGammaRamp(window: PSDL_Window; const red: PUInt16; const green: PUInt16; const blue: PUInt16): SInt32;
+  function SDL_GetWindowGammaRamp(window: PSDL_Window; red: PUInt16; green: PUInt16; blue: PUInt16): SInt32;
+
+  function SDL_NumJoysticks: SInt32;
+  function SDL_JoystickOpen(device_index: SInt32): PSDL_Joystick;
+  function SDL_JoystickName(joystick: PSDL_Joystick): PAnsiChar;
+  function SDL_JoystickNumAxes(joystick: PSDL_Joystick): SInt32;
+  function SDL_JoystickNumButtons(joystick: PSDL_Joystick): SInt32;
+  function SDL_JoystickNumHats(joystick: PSDL_Joystick): SInt32;
+  procedure SDL_JoystickClose(joystick: PSDL_Joystick);
+  procedure SDL_JoystickUpdate;
+  function SDL_JoystickGetButton(joystick: PSDL_Joystick; button: SInt32): UInt8;
+  function SDL_JoystickGetAxis(joystick: PSDL_Joystick; axis: SInt32): SInt16;
+  function SDL_JoystickGetHat(joystick: PSDL_Joystick; hat: SInt32): UInt8;
+  
+  function SDL_GetScancodeName(scancode: TSDL_ScanCode): PAnsiChar;
+
+  function SDL_GetPerformanceCounter: UInt64;
+  function SDL_GetPerformanceFrequency: UInt64;
+  
+  function SDL_RWFromFile(const _file: PAnsiChar; const mode: PAnsiChar): PSDL_RWops;
+  function SDL_RWFromConstMem(const mem: Pointer; size: SInt32): PSDL_RWops;
+
+  function SDL_GetDisplayDPI(displayIndex: SInt32; ddpi, hdpi, vdpi: PFloat): SInt32;
+  function SDL_IsTextInputActive: TSDL_Bool;
+  procedure SDL_StartTextInput;
+  procedure SDL_StopTextInput;
+  function SDL_GetNumTouchDevices: SInt32;
+
+  function SDL_GetDesktopDisplayMode(displayIndex: SInt32; mode: PSDL_DisplayMode): SInt32;
+  function SDL_GetClosestDisplayMode(displayIndex: SInt32; const mode: PSDL_DisplayMode; closest: PSDL_DisplayMode): PSDL_DisplayMode;
+
+  procedure SDL_DestroyWindow(window: PSDL_Window);
+  procedure SDL_GL_DeleteContext(context: TSDL_GLContext);
+  procedure SDL_RestoreWindow(window: PSDL_Window);
+  procedure SDL_SetWindowSize(window: PSDL_Window; w: SInt32; h: SInt32);
+  function SDL_CreateWindow(const title: PAnsiChar; x: SInt32; y: SInt32; w: SInt32; h: SInt32; flags: UInt32): PSDL_Window;
+  function SDL_SetWindowFullscreen(window: PSDL_Window; flags: UInt32): SInt32;
+  function SDL_GL_MakeCurrent(window: PSDL_Window; context: TSDL_GLContext): SInt32;
+  procedure SDL_GetWindowSize(window: PSDL_Window; w: PInt; h: PInt);
+  function SDL_GetNumDisplayModes(displayIndex: SInt32): SInt32;
+  function SDL_GetDisplayMode(displayIndex: SInt32; modeIndex: SInt32; mode: PSDL_DisplayMode): SInt32;
+
+  function SDL_ShowCursor(toggle: SInt32): SInt32;
+  procedure SDL_Delay(ms: UInt32);
+  procedure SDL_GL_SwapWindow(window: PSDL_Window);
+
+  function SDL_GL_CreateContext(window: PSDL_Window): TSDL_GLContext;
+  function SDL_GetTicks: UInt32;
+
+  function SDL_PushEvent(event: PSDL_Event): SInt32;
+  function SDL_PollEvent(event: PSDL_Event): SInt32;
+  function SDL_GL_SetSwapInterval(interval: SInt32): SInt32;
+  function SDL_GL_SetAttribute(attr: TSDL_GLattr; value: SInt32): SInt32;
+  function SDL_GL_GetAttribute(attr: TSDL_GLattr; value: PInt): SInt32;
+
+  function SDL_GetError: PAnsiChar;
+
+  function SDL_Init(flags: UInt32): SInt32;
+  procedure SDL_Quit();
+  function SDL_SetHint( const name: PChar; const value: PChar) : boolean;
+
+implementation
+  /// MACRO ///
+
+  function SDL_BITSPERPIXEL(X: Cardinal): Cardinal;
+  begin
+    Result := (X shr 8) and $FF;
+  end;
+
+  /// FUNCTIONS ////
+
+  function SDL_SetWindowGammaRamp(window: PSDL_Window; const red: PUInt16; const green: PUInt16; const blue: PUInt16): SInt32;
+  begin
+    result := 0
+  end;
+
+  function SDL_GetWindowGammaRamp(window: PSDL_Window; red: PUInt16; green: PUInt16; blue: PUInt16): SInt32;
+  begin
+    result := 0
+  end;
+
+
+  function SDL_NumJoysticks: SInt32;
+  begin
+    result := 0
+  end;
+
+  function SDL_JoystickOpen(device_index: SInt32): PSDL_Joystick;
+  begin
+    result := nil
+  end;
+
+  function SDL_JoystickName(joystick: PSDL_Joystick): PAnsiChar;
+  begin
+    result := ''
+  end;
+
+  function SDL_JoystickNumAxes(joystick: PSDL_Joystick): SInt32;
+  begin
+    result := 0
+  end;
+
+  function SDL_JoystickNumButtons(joystick: PSDL_Joystick): SInt32;
+  begin
+    result := 0
+  end;
+
+  function SDL_JoystickNumHats(joystick: PSDL_Joystick): SInt32;
+  begin
+    result := 0
+  end;
+
+  procedure SDL_JoystickClose(joystick: PSDL_Joystick);
+  begin
+  end;
+
+  procedure SDL_JoystickUpdate;
+  begin
+  end;
+
+  function SDL_JoystickGetButton(joystick: PSDL_Joystick; button: SInt32): UInt8;
+  begin
+    result := 0
+  end;
+
+  function SDL_JoystickGetAxis(joystick: PSDL_Joystick; axis: SInt32): SInt16;
+  begin
+    result := 0
+  end;
+
+  function SDL_JoystickGetHat(joystick: PSDL_Joystick; hat: SInt32): UInt8;
+  begin
+    result := 0
+  end;
+  
+
+
+
+  function SDL_GetScancodeName(scancode: TSDL_ScanCode): PAnsiChar;
+  begin
+    result := ''
+  end;
+
+
+
+
+  function SDL_GetPerformanceCounter: UInt64;
+  begin
+    result := 0
+  end;
+
+  function SDL_GetPerformanceFrequency: UInt64;
+  begin
+    result := 0
+  end;
+
+
+
+  function SDL_RWFromFile(const _file: PAnsiChar; const mode: PAnsiChar): PSDL_RWops;
+  begin
+    result := nil
+  end;
+
+  function SDL_RWFromConstMem(const mem: Pointer; size: SInt32): PSDL_RWops;
+  begin
+    result := nil
+  end;
+
+
+
+
+  function SDL_GetDisplayDPI(displayIndex: SInt32; ddpi, hdpi, vdpi: PFloat): SInt32;
+  begin
+    result := 0
+  end;
+
+  function SDL_IsTextInputActive: TSDL_Bool;
+  begin
+    result := SDL_FALSE
+  end;
+
+  procedure SDL_StartTextInput;
+  begin
+  end;
+
+  procedure SDL_StopTextInput;
+  begin
+  end;
+
+  function SDL_GetNumTouchDevices: SInt32;
+  begin
+    result := 0
+  end;
+
+
+
+  function SDL_GetDesktopDisplayMode(displayIndex: SInt32; mode: PSDL_DisplayMode): SInt32;
+  begin
+    result := 0
+  end;
+
+  function SDL_GetClosestDisplayMode(displayIndex: SInt32; const mode: PSDL_DisplayMode; closest: PSDL_DisplayMode): PSDL_DisplayMode;
+  begin
+    result := nil
+  end;
+
+  procedure SDL_DestroyWindow(window: PSDL_Window);
+  begin
+  end;
+
+  procedure SDL_GL_DeleteContext(context: TSDL_GLContext);
+  begin
+  end;
+
+  procedure SDL_RestoreWindow(window: PSDL_Window);
+  begin
+  end;
+
+  procedure SDL_SetWindowSize(window: PSDL_Window; w: SInt32; h: SInt32);
+  begin
+  end;
+
+  function SDL_CreateWindow(const title: PAnsiChar; x: SInt32; y: SInt32; w: SInt32; h: SInt32; flags: UInt32): PSDL_Window;
+  begin
+    result := nil
+  end;
+
+  function SDL_SetWindowFullscreen(window: PSDL_Window; flags: UInt32): SInt32;
+  begin
+    result := 0
+  end;
+
+  function SDL_GL_MakeCurrent(window: PSDL_Window; context: TSDL_GLContext): SInt32;
+  begin
+    result := 0
+  end;
+
+  procedure SDL_GetWindowSize(window: PSDL_Window; w: PInt; h: PInt);
+  begin
+  end;
+
+  function SDL_GetNumDisplayModes(displayIndex: SInt32): SInt32;
+  begin
+    result := 0
+  end;
+
+  function SDL_GetDisplayMode(displayIndex: SInt32; modeIndex: SInt32; mode: PSDL_DisplayMode): SInt32;
+  begin
+    result := 0
+  end;
+
+  function SDL_ShowCursor(toggle: SInt32): SInt32;
+  begin
+    result := 0
+  end;
+
+  procedure SDL_Delay(ms: UInt32);
+  begin
+  end;
+
+  procedure SDL_GL_SwapWindow(window: PSDL_Window);
+  begin
+  end;
+
+  function SDL_GL_CreateContext(window: PSDL_Window): TSDL_GLContext;
+  begin
+    result := nil
+  end;
+
+  function SDL_GetTicks: UInt32;
+  begin
+    result := 0
+  end;
+
+  function SDL_PushEvent(event: PSDL_Event): SInt32;
+  begin
+    result := 0
+  end;
+
+  function SDL_PollEvent(event: PSDL_Event): SInt32;
+  begin
+    result := 0
+  end;
+
+  function SDL_GL_SetSwapInterval(interval: SInt32): SInt32;
+  begin
+    result := 0
+  end;
+
+  function SDL_GL_SetAttribute(attr: TSDL_GLattr; value: SInt32): SInt32;
+  begin
+    result := 0
+  end;
+
+  function SDL_GL_GetAttribute(attr: TSDL_GLattr; value: PInt): SInt32;
+  begin
+    result := 0
+  end;
+
+  function SDL_GetError: PAnsiChar;
+  begin
+    result := ''
+  end;
+
+  function SDL_Init(flags: UInt32): SInt32;
+  begin
+    result := 0
+  end;
+
+  procedure SDL_Quit();
+  begin
+  end;
+
+  function SDL_SetHint( const name: PChar; const value: PChar) : boolean;
+  begin
+    result := false
+  end;
diff --git a/src/wrappers/sdl2/sdl2stub_mixer.inc b/src/wrappers/sdl2/sdl2stub_mixer.inc
new file mode 100644 (file)
index 0000000..5fc58c7
--- /dev/null
@@ -0,0 +1,248 @@
+{$INCLUDE ../shared/a_modes.inc}
+{$SCOPEDENUMS OFF}
+
+interface
+
+  uses SDL2;
+
+  const
+    MIX_INIT_FLAC        = $00000001;
+    MIX_INIT_MOD         = $00000002;
+    MIX_INIT_MODPLUG     = $00000004;
+    MIX_INIT_MP3         = $00000008;
+    MIX_INIT_OGG         = $00000010;
+    MIX_INIT_FLUIDSYNTH  = $00000020;
+
+    MIX_DEFAULT_FREQUENCY = 22050;
+    MIX_DEFAULT_CHANNELS = 2;
+    MIX_MAX_VOLUME       = 128;
+
+{$IFDEF FPC}
+   {$IF DEFINED(ENDIAN_LITTLE)}
+      MIX_DEFAULT_FORMAT = AUDIO_S16LSB;
+   {$ELSEIF DEFINED(ENDIAN_BIG)}
+      MIX_DEFAULT_FORMAT = AUDIO_S16MSB;
+   {$ELSE}
+      {$FATAL Unable to determine endianness.}
+   {$IFEND}
+{$ENDIF}
+
+  type
+    PMix_Chunk = ^TMix_Chunk;
+    TMix_Chunk = record
+      allocated: Integer;
+      abuf: PUInt8;
+      alen: UInt32;
+      volume: UInt8;
+    end;
+
+    PMix_Music = ^TMix_Music;
+    TMix_Music = record end;
+
+    TMix_Fading = (MIX_NO_FADING, MIX_FADING_OUT, MIX_FADING_IN);
+
+    TMix_MusicType = (MUS_NONE,
+                    MUS_CMD,
+                    MUS_WAV,
+                    MUS_MOD,
+                    MUS_MID,
+                    MUS_OGG,
+                    MUS_MP3,
+                    MUS_MP3_MAD,
+                    MUS_FLAC,
+                    MUS_MODPLUG);
+
+  TMix_Channel_Finished = procedure(channel: Integer); cdecl;
+
+  (** procedures **)
+
+  function Mix_GetMusicType(music: TMix_Music): TMix_MusicType;
+  function Mix_Init(flags: Integer): Integer;
+  function Mix_OpenAudio(frequency: Integer; format: UInt16; channels: Integer; chunksize: Integer): Integer;
+  function Mix_GetError: PAnsiChar;
+  function Mix_QuerySpec(frequency: PInt; format: PUInt16; channels: PInt): Integer;
+  function Mix_GetNumChunkDecoders: Integer;
+  function Mix_GetChunkDecoder(index: Integer): PAnsiChar;
+  function Mix_GetNumMusicDecoders: Integer;
+  function Mix_GetMusicDecoder(index: Integer): PAnsiChar;
+  function Mix_AllocateChannels(numchans: Integer): Integer;
+  procedure Mix_ChannelFinished(channel_finished: TMix_Channel_Finished);
+  function Mix_LoadMUS(_file: PAnsiChar): PMix_Music;
+  function Mix_LoadMUS_RW(src: PSDL_RWops; freesrc: Integer): PMix_Music;
+  function Mix_LoadWAV(_file: PAnsiChar): PMix_Chunk;
+  function Mix_LoadWAV_RW(src: PSDL_RWops; freesrc: Integer): PMix_Chunk;
+
+  function Mix_PlayChannel(channel: Integer; chunk: PMix_Chunk; loops: Integer): Integer;
+  function Mix_Volume(channel: Integer; volume: Integer): Integer;
+  function Mix_HaltMusic: Integer;
+  function Mix_PlayMusic(music: PMix_Music; loops: Integer): Integer;
+  function Mix_SetPanning(channel: Integer; left: UInt8; right: UInt8): Integer;
+  procedure Mix_FreeChunk(chunk: PMix_Chunk);
+  procedure Mix_FreeMusic(music: PMix_Music);
+
+  function Mix_VolumeMusic(volume: Integer): Integer;
+  function Mix_HaltChannel(channel: Integer): Integer;
+  procedure Mix_CloseAudio;
+  function Mix_PlayingMusic: Integer;
+  function Mix_Paused(channel: Integer): Integer;
+  procedure Mix_Pause(channel: Integer);
+  procedure Mix_Resume(channel: Integer);
+
+  procedure Mix_PauseMusic;
+  function Mix_PausedMusic: Integer;
+  procedure Mix_ResumeMusic;
+
+implementation
+
+  function Mix_GetMusicType(music: TMix_Music): TMix_MusicType;
+  begin
+    result := TMix_MusicType.MUS_NONE
+  end;
+
+  function Mix_Init(flags: Integer): Integer;
+  begin
+    result := 0
+  end;
+
+  function Mix_OpenAudio(frequency: Integer; format: UInt16; channels: Integer; chunksize: Integer): Integer;
+  begin
+    result := 0
+  end;
+
+  function Mix_GetError: PAnsiChar;
+  begin
+    result := ''
+  end;
+
+  function Mix_QuerySpec(frequency: PInt; format: PUInt16; channels: PInt): Integer;
+  begin
+    result := 0
+  end;
+
+  function Mix_GetNumChunkDecoders: Integer;
+  begin
+    result := 0
+  end;
+
+  function Mix_GetChunkDecoder(index: Integer): PAnsiChar;
+  begin
+    result := ''
+  end;
+
+  function Mix_GetNumMusicDecoders: Integer;
+  begin
+    result := 0
+  end;
+
+  function Mix_GetMusicDecoder(index: Integer): PAnsiChar;
+  begin
+    result := ''
+  end;
+
+  function Mix_AllocateChannels(numchans: Integer): Integer;
+  begin
+    result := 0
+  end;
+
+  procedure Mix_ChannelFinished(channel_finished: TMix_Channel_Finished);
+  begin
+  end;
+
+  function Mix_LoadMUS(_file: PAnsiChar): PMix_Music;
+  begin
+    result := nil
+  end;
+
+  function Mix_LoadMUS_RW(src: PSDL_RWops; freesrc: Integer): PMix_Music;
+  begin
+    result := nil
+  end;
+
+  function Mix_LoadWAV(_file: PAnsiChar): PMix_Chunk;
+  begin
+    Result := Mix_LoadWAV_RW(SDL_RWFromFile(_file, 'rb'), 1);
+  end;
+
+  function Mix_LoadWAV_RW(src: PSDL_RWops; freesrc: Integer): PMix_Chunk;
+  begin
+    result := nil
+  end;
+
+  function Mix_PlayChannel(channel: Integer; chunk: PMix_Chunk; loops: Integer): Integer;
+  begin
+    result := 0
+  end;
+
+  function Mix_Volume(channel: Integer; volume: Integer): Integer;
+  begin
+    result := 0
+  end;
+
+  function Mix_HaltMusic: Integer;
+  begin
+    result := 0
+  end;
+
+  function Mix_PlayMusic(music: PMix_Music; loops: Integer): Integer;
+  begin
+    result := 0
+  end;
+
+  function Mix_SetPanning(channel: Integer; left: UInt8; right: UInt8): Integer;
+  begin
+    result := 0
+  end;
+
+  procedure Mix_FreeChunk(chunk: PMix_Chunk);
+  begin
+  end;
+
+  procedure Mix_FreeMusic(music: PMix_Music);
+  begin
+  end;
+
+  function Mix_VolumeMusic(volume: Integer): Integer;
+  begin
+    result := 0
+  end;
+
+  function Mix_HaltChannel(channel: Integer): Integer;
+  begin
+    result := 0
+  end;
+
+  procedure Mix_CloseAudio;
+  begin
+  end;
+
+  function Mix_PlayingMusic: Integer;
+  begin
+    result := 0
+  end;
+
+  function Mix_Paused(channel: Integer): Integer;
+  begin
+    result := 0
+  end;
+
+  procedure Mix_Pause(channel: Integer);
+  begin
+  end;
+
+  procedure Mix_Resume(channel: Integer);
+  begin
+  end;
+
+  procedure Mix_PauseMusic;
+  begin
+  end;
+
+  function Mix_PausedMusic: Integer;
+  begin
+    result := 0
+  end;
+
+  procedure Mix_ResumeMusic;
+  begin
+  end;
+
diff --git a/src/wrappers/sdl2/sdlpixels.inc b/src/wrappers/sdl2/sdlpixels.inc
new file mode 100644 (file)
index 0000000..8c72d51
--- /dev/null
@@ -0,0 +1,387 @@
+//from "sdl_pixels.h"
+
+  {**
+   *  Transparency definitions
+   *
+   *  These define alpha as the opacity of a surface.
+   *}
+
+  const
+    SDL_ALPHA_OPAQUE = 255;
+    SDL_ALPHA_TRANSPARENT = 0;
+
+    {** Pixel type. *}
+    SDL_PIXELTYPE_UNKNOWN = 0;
+    SDL_PIXELTYPE_INDEX1 = 1;
+    SDL_PIXELTYPE_INDEX4 = 2;
+    SDL_PIXELTYPE_INDEX8 = 3;
+    SDL_PIXELTYPE_PACKED8 = 4;
+    SDL_PIXELTYPE_PACKED16 = 5;
+    SDL_PIXELTYPE_PACKED32 = 6;
+    SDL_PIXELTYPE_ARRAYU8 = 7;
+    SDL_PIXELTYPE_ARRAYU16 = 8;
+    SDL_PIXELTYPE_ARRAYU32 = 9;
+    SDL_PIXELTYPE_ARRAYF16 = 10;
+    SDL_PIXELTYPE_ARRAYF32 = 11;
+
+    {** Bitmap pixel order, high bit -> low bit. *}
+    SDL_BITMAPORDER_NONE = 0;
+    SDL_BITMAPORDER_4321 = 1;
+    SDL_BITMAPORDER_1234 = 2;
+
+    {** Packed component order, high bit -> low bit. *}
+
+    SDL_PACKEDORDER_NONE = 0;
+    SDL_PACKEDORDER_XRGB = 1;
+    SDL_PACKEDORDER_RGBX = 2;
+    SDL_PACKEDORDER_ARGB = 3;
+    SDL_PACKEDORDER_RGBA = 4;
+    SDL_PACKEDORDER_XBGR = 5;
+    SDL_PACKEDORDER_BGRX = 6;
+    SDL_PACKEDORDER_ABGR = 7;
+    SDL_PACKEDORDER_BGRA = 8;
+
+    {** Array component order, low byte -> high byte. *}
+    SDL_ARRAYORDER_NONE = 0;
+    SDL_ARRAYORDER_RGB  = 1;
+    SDL_ARRAYORDER_RGBA = 2;
+    SDL_ARRAYORDER_ARGB = 3;
+    SDL_ARRAYORDER_BGR  = 4;
+    SDL_ARRAYORDER_BGRA = 5;
+    SDL_ARRAYORDER_ABGR = 6;
+
+    {** Packed component layout. *}
+    SDL_PACKEDLAYOUT_NONE = 0;
+    SDL_PACKEDLAYOUT_332  = 1;
+    SDL_PACKEDLAYOUT_4444 = 2;
+    SDL_PACKEDLAYOUT_1555 = 3;
+    SDL_PACKEDLAYOUT_5551 = 4;
+    SDL_PACKEDLAYOUT_565  = 5;
+    SDL_PACKEDLAYOUT_8888 = 6;
+    SDL_PACKEDLAYOUT_2101010 = 7;
+    SDL_PACKEDLAYOUT_1010102 = 8;
+
+    {
+        //todo!!
+function SDL_DEFINE_PIXELFORMAT(type, order, layour, bit, bytes: UInt32): Result;
+
+function SDL_DEFINE_PIXELFOURCC(A,B,C,D: Variant): Variant;
+
+#define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \
+    ((1 << 28) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \
+     ((bits) << 8) | ((bytes) << 0))
+       }
+
+function SDL_PIXELFLAG(X: Cardinal): Cardinal;
+function SDL_PIXELTYPE(X: Cardinal): Cardinal;
+function SDL_PIXELORDER(X: Cardinal): Cardinal;
+function SDL_PIXELLAYOUT(X: Cardinal): Cardinal;
+function SDL_BITSPERPIXEL(X: Cardinal): Cardinal;
+     {
+#define SDL_BYTESPERPIXEL(X) \
+    (SDL_ISPIXELFORMAT_FOURCC(X) ? \
+        ((((X) == SDL_PIXELFORMAT_YUY2) || \
+          ((X) == SDL_PIXELFORMAT_UYVY) || \
+          ((X) == SDL_PIXELFORMAT_YVYU)) ? 2 : 1) : (((X) >> 0) & 0xFF))
+
+#define SDL_ISPIXELFORMAT_INDEXED(format)   \
+    (!SDL_ISPIXELFORMAT_FOURCC(format) && \
+     ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX1) || \
+      (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX4) || \
+      (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX8)))
+
+#define SDL_ISPIXELFORMAT_ALPHA(format)   \
+    (!SDL_ISPIXELFORMAT_FOURCC(format) && \
+     ((SDL_PIXELORDER(format) == SDL_PACKEDORDER_ARGB) || \
+      (SDL_PIXELORDER(format) == SDL_PACKEDORDER_RGBA) || \
+      (SDL_PIXELORDER(format) == SDL_PACKEDORDER_ABGR) || \
+      (SDL_PIXELORDER(format) == SDL_PACKEDORDER_BGRA)))
+
+  function SDL_IsPixelFormat_FOURCC(format: Variant);
+
+  {* Note: If you modify this list, update SDL_GetPixelFormatName() *}
+
+const
+    SDL_PIXELFORMAT_UNKNOWN = 0;
+    SDL_PIXELFORMAT_INDEX1LSB = (1 shl 28)                    or
+                                (SDL_PIXELTYPE_INDEX1 shl 24) or
+                                (SDL_BITMAPORDER_4321 shl 20) or
+                                (0 shl 16)                    or
+                                (1 shl 8)                     or
+                                (0 shl 0);
+
+    SDL_PIXELFORMAT_INDEX1MSB = (1 shl 28)                    or
+                                (SDL_PIXELTYPE_INDEX1 shl 24) or
+                                (SDL_BITMAPORDER_1234 shl 20) or
+                                (0 shl 16)                    or
+                                (1 shl 8)                     or
+                                (0 shl 0);
+
+    SDL_PIXELFORMAT_INDEX4LSB = (1 shl 28)                    or
+                                (SDL_PIXELTYPE_INDEX4 shl 24) or
+                                (SDL_BITMAPORDER_4321 shl 20) or
+                                (0 shl 16)                    or
+                                (4 shl 8)                     or
+                                (0 shl 0);
+
+    SDL_PIXELFORMAT_INDEX4MSB = (1 shl 28)                    or
+                                (SDL_PIXELTYPE_INDEX4 shl 24) or
+                                (SDL_BITMAPORDER_1234 shl 20) or
+                                (0 shl 16)                    or
+                                (4 shl 8)                     or
+                                (0 shl 0);
+
+    SDL_PIXELFORMAT_INDEX8 =    (1 shl 28)                      or
+                                (SDL_PIXELTYPE_PACKED8 shl 24)  or
+                                (0 shl 20)                      or
+                                (0 shl 16)                      or
+                                (8 shl 8)                       or
+                                (1 shl 0);
+
+    SDL_PIXELFORMAT_RGB332 =    (1 shl 28)                      or
+                                (SDL_PIXELTYPE_PACKED8 shl 24)  or
+                                (SDL_PACKEDORDER_XRGB shl 20)   or
+                                (SDL_PACKEDLAYOUT_332 shl 16)   or
+                                (8 shl 8)                       or
+                                (1 shl 0);
+
+    SDL_PIXELFORMAT_RGB444 =    (1 shl 28)                      or
+                                (SDL_PIXELTYPE_PACKED16 shl 24) or
+                                (SDL_PACKEDORDER_XRGB shl 20)   or
+                                (SDL_PACKEDLAYOUT_4444 shl 16)  or
+                                (12 shl 8)                      or
+                                (2 shl 0);
+
+    SDL_PIXELFORMAT_RGB555 =    (1 shl 28)                      or
+                                (SDL_PIXELTYPE_PACKED16 shl 24) or
+                                (SDL_PACKEDORDER_XRGB shl 20)   or
+                                (SDL_PACKEDLAYOUT_1555 shl 16)  or
+                                (15 shl 8)                      or
+                                (2 shl 0);
+
+    SDL_PIXELFORMAT_BGR555 =    (1 shl 28)                      or
+                                (SDL_PIXELTYPE_PACKED16 shl 24) or
+                                (SDL_PACKEDORDER_XBGR shl 20)   or
+                                (SDL_PACKEDLAYOUT_1555 shl 16)  or
+                                (15 shl 8)                      or
+                                (2 shl 0);
+
+    SDL_PIXELFORMAT_ARGB4444 =  (1 shl 28)                      or
+                                (SDL_PIXELTYPE_PACKED16 shl 24) or
+                                (SDL_PACKEDORDER_ARGB shl 20)   or
+                                (SDL_PACKEDLAYOUT_4444 shl 16)  or
+                                (16 shl 8)                      or
+                                (2 shl 0);
+
+    SDL_PIXELFORMAT_RGBA4444 =  (1 shl 28)                      or
+                                (SDL_PIXELTYPE_PACKED16 shl 24) or
+                                (SDL_PACKEDORDER_RGBA shl 20)   or
+                                (SDL_PACKEDLAYOUT_4444 shl 16)  or
+                                (16 shl 8)                      or
+                                (2 shl 0);
+
+    SDL_PIXELFORMAT_ABGR4444 =  (1 shl 28)                      or
+                                (SDL_PIXELTYPE_PACKED16 shl 24) or
+                                (SDL_PACKEDORDER_ABGR shl 20)   or
+                                (SDL_PACKEDLAYOUT_4444 shl 16)  or
+                                (16 shl 8)                      or
+                                (2 shl 0);
+
+    SDL_PIXELFORMAT_BGRA4444 =  (1 shl 28)                      or
+                                (SDL_PIXELTYPE_PACKED16 shl 24) or
+                                (SDL_PACKEDORDER_BGRA shl 20)   or
+                                (SDL_PACKEDLAYOUT_4444 shl 16)  or
+                                (16 shl 8)                      or
+                                (2 shl 0);
+
+    SDL_PIXELFORMAT_ARGB1555 =  (1 shl 28)                      or
+                                (SDL_PIXELTYPE_PACKED16 shl 24) or
+                                (SDL_PACKEDORDER_ARGB shl 20)   or
+                                (SDL_PACKEDLAYOUT_1555 shl 16)  or
+                                (16 shl 8)                      or
+                                (2 shl 0);
+
+    SDL_PIXELFORMAT_RGBA5551 =  (1 shl 28)                      or
+                                (SDL_PIXELTYPE_PACKED16 shl 24) or
+                                (SDL_PACKEDORDER_RGBA shl 20)   or
+                                (SDL_PACKEDLAYOUT_5551 shl 16)  or
+                                (16 shl 8)                      or
+                                (2 shl 0);
+
+    SDL_PIXELFORMAT_ABGR1555 =  (1 shl 28)                      or
+                                (SDL_PIXELTYPE_PACKED16 shl 24) or
+                                (SDL_PACKEDORDER_ABGR shl 20)   or
+                                (SDL_PACKEDLAYOUT_1555 shl 16)  or
+                                (16 shl 8)                      or
+                                (2 shl 0);
+
+    SDL_PIXELFORMAT_BGRA5551 =  (1 shl 28)                      or
+                                (SDL_PIXELTYPE_PACKED16 shl 24) or
+                                (SDL_PACKEDORDER_BGRA shl 20)   or
+                                (SDL_PACKEDLAYOUT_5551 shl 16)  or
+                                (16 shl 8)                      or
+                                (2 shl 0);
+
+    SDL_PIXELFORMAT_RGB565 =    (1 shl 28)                      or
+                                (SDL_PIXELTYPE_PACKED16 shl 24) or
+                                (SDL_PACKEDORDER_XRGB shl 20)   or
+                                (SDL_PACKEDLAYOUT_565 shl 16)   or
+                                (16 shl 8)                      or
+                                (2 shl 0);
+
+    SDL_PIXELFORMAT_BGR565 =    (1 shl 28)                      or
+                                (SDL_PIXELTYPE_PACKED16 shl 24) or
+                                (SDL_PACKEDORDER_XBGR shl 20)   or
+                                (SDL_PACKEDLAYOUT_1555 shl 16)  or
+                                (16 shl 8)                      or
+                                (2 shl 0);
+
+    SDL_PIXELFORMAT_RGB24 =     (1 shl 28)                      or
+                                (SDL_PIXELTYPE_ARRAYU8 shl 24)  or
+                                (SDL_ARRAYORDER_RGB shl 20)     or
+                                (0 shl 16)                      or
+                                (24 shl 8)                      or
+                                (3 shl 0);
+
+    SDL_PIXELFORMAT_BGR24 =     (1 shl 28)                      or
+                                (SDL_PIXELTYPE_ARRAYU8 shl 24)  or
+                                (SDL_ARRAYORDER_BGR shl 20)     or
+                                (0 shl 16)                      or
+                                (24 shl 8)                      or
+                                (3 shl 0);
+
+    SDL_PIXELFORMAT_RGB888 =    (1 shl 28)                      or
+                                (SDL_PIXELTYPE_PACKED32 shl 24) or
+                                (SDL_PACKEDORDER_XRGB shl 20)   or
+                                (SDL_PACKEDLAYOUT_8888 shl 16)  or
+                                (24 shl 8)                      or
+                                (4 shl 0);
+
+    SDL_PIXELFORMAT_RGBX8888 =  (1 shl 28)                      or
+                                (SDL_PIXELTYPE_PACKED32 shl 24) or
+                                (SDL_PACKEDORDER_RGBX shl 20)   or
+                                (SDL_PACKEDLAYOUT_8888 shl 16)  or
+                                (24 shl 8)                      or
+                                (4 shl 0);
+
+    SDL_PIXELFORMAT_BGR888 =    (1 shl 28)                      or
+                                (SDL_PIXELTYPE_PACKED32 shl 24) or
+                                (SDL_PACKEDORDER_XBGR shl 20)   or
+                                (SDL_PACKEDLAYOUT_8888 shl 16)  or
+                                (24 shl 8)                      or
+                                (4 shl 0);
+
+    SDL_PIXELFORMAT_BGRX8888 =  (1 shl 28)                      or
+                                (SDL_PIXELTYPE_PACKED32 shl 24) or
+                                (SDL_PACKEDORDER_BGRX shl 20)   or
+                                (SDL_PACKEDLAYOUT_8888 shl 16)  or
+                                (24 shl 8)                      or
+                                (4 shl 0);
+
+    SDL_PIXELFORMAT_ARGB8888 =  (1 shl 28)                      or
+                                (SDL_PIXELTYPE_PACKED32 shl 24) or
+                                (SDL_PACKEDORDER_ARGB shl 20)   or
+                                (SDL_PACKEDLAYOUT_8888 shl 16)  or
+                                (32 shl 8)                      or
+                                (4 shl 0);
+
+    SDL_PIXELFORMAT_RGBA8888 =  (1 shl 28)                      or
+                                (SDL_PIXELTYPE_PACKED32 shl 24) or
+                                (SDL_PACKEDORDER_RGBA shl 20)   or
+                                (SDL_PACKEDLAYOUT_8888 shl 16)  or
+                                (32 shl 8)                      or
+                                (4 shl 0);
+
+    SDL_PIXELFORMAT_ABGR8888 =  (1 shl 28)                      or
+                                (SDL_PIXELTYPE_PACKED32 shl 24) or
+                                (SDL_PACKEDORDER_ABGR shl 20)   or
+                                (SDL_PACKEDLAYOUT_8888 shl 16)  or
+                                (32 shl 8)                      or
+                                (4 shl 0);
+
+    SDL_PIXELFORMAT_BGRA8888 =  (1 shl 28)                      or
+                                (SDL_PIXELTYPE_PACKED32 shl 24) or
+                                (SDL_PACKEDORDER_RGBX shl 20)   or
+                                (SDL_PACKEDLAYOUT_8888 shl 16)  or
+                                (32 shl 8)                      or
+                                (4 shl 0);
+
+    SDL_PIXELFORMAT_ARGB2101010 = (1 shl 28)                       or
+                                  (SDL_PIXELTYPE_PACKED32 shl 24)  or
+                                  (SDL_PACKEDORDER_ARGB shl 20)    or
+                                  (SDL_PACKEDLAYOUT_2101010 shl 16)or
+                                  (32 shl 8)                       or
+                                  (4 shl 0);
+
+    {**< Planar mode: Y + V + U  (3 planes) *}
+    SDL_PIXELFORMAT_YV12 = (Integer('Y')       ) or
+                           (Integer('V') shl  8) or
+                           (Integer('1') shl 16) or
+                           (Integer('2') shl 24);
+    {**< Planar mode: Y + U + V  (3 planes) *}
+    SDL_PIXELFORMAT_IYUV = (Integer('I')       ) or
+                           (Integer('Y') shl  8) or
+                           (Integer('U') shl 16) or
+                           (Integer('V') shl 24);
+    {**< Packed mode: Y0+U0+Y1+V0 (1 plane) *}
+    SDL_PIXELFORMAT_YUY2 = (Integer('Y')       ) or
+                           (Integer('U') shl  8) or
+                           (Integer('Y') shl 16) or
+                           (Integer('2') shl 24);
+    {**< Packed mode: U0+Y0+V0+Y1 (1 plane) *}
+    SDL_PIXELFORMAT_UYVY = (Integer('U')       ) or
+                           (Integer('Y') shl  8) or
+                           (Integer('V') shl 16) or
+                           (Integer('Y') shl 24);
+    {**< Packed mode: Y0+V0+Y1+U0 (1 plane) *}
+    SDL_PIXELFORMAT_YVYU = (Integer('Y')       ) or
+                           (Integer('V') shl  8) or
+                           (Integer('Y') shl 16) or
+                           (Integer('U') shl 24);
+
+type
+  PSDL_Color = ^TSDL_Color;
+  TSDL_Color = record
+    r: UInt8;
+    g: UInt8;
+    b: UInt8;
+    a: UInt8;
+  end;
+
+  TSDL_Colour = TSDL_Color;
+  PSDL_Colour = ^TSDL_Colour;
+
+  PSDL_Palette = ^TSDL_Palette;
+  TSDL_Palette = record
+    ncolors: SInt32;
+    colors: PSDL_Color;
+    version: UInt32;
+    refcount: SInt32;
+  end;
+
+  {**
+   *  Everything in the pixel format structure is read-only.
+   *}
+
+  PSDL_PixelFormat = ^TSDL_PixelFormat;
+  TSDL_PixelFormat = record
+    format: UInt32;
+    palette: PSDL_Palette;
+    BitsPerPixel: UInt8;
+    BytesPerPixel: UInt8;
+    padding: array[0..1] of UInt8;
+    Rmask: UInt32;
+    Gmask: UInt32;
+    Bmask: UInt32;
+    Amask: UInt32;
+    Rloss: UInt8;
+    Gloss: UInt8;
+    Bloss: UInt8;
+    Aloss: UInt8;
+    Rshift: UInt8;
+    Gshift: UInt8;
+    Bshift: UInt8;
+    Ashift: UInt8;
+    refcount: SInt32;
+    next: PSDL_PixelFormat;
+  end;