use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
authorkoda
Sat, 06 Jul 2013 19:29:18 +0200
changeset 9317 a04c30940d2d
parent 9315 15487f7fed42
child 9319 492a0ad67e33
use SDL2 as ifdef symbol because we're not really sdl1.3 compatible, change the compatibility layer, drop unused code, add some documentation
hedgewars/SDLh.pas
hedgewars/hwengine.pas
hedgewars/options.inc
hedgewars/uAI.pas
hedgewars/uChat.pas
hedgewars/uGame.pas
hedgewars/uGears.pas
hedgewars/uMisc.pas
hedgewars/uStore.pas
hedgewars/uTypes.pas
--- a/hedgewars/SDLh.pas	Thu Jul 04 11:58:40 2013 +0200
+++ b/hedgewars/SDLh.pas	Sat Jul 06 19:29:18 2013 +0200
@@ -93,7 +93,7 @@
     SDL_INIT_AUDIO          = $00000010;
     SDL_INIT_VIDEO          = $00000020;
     SDL_INIT_JOYSTICK       = $00000200;
-{$IFDEF SDL13}
+{$IFDEF SDL2}
     SDL_INIT_HAPTIC         = $00001000;
     SDL_INIT_GAMECONTROLLER = $00002000; // implicitly activates JOYSTICK */
 {$ELSE}
@@ -113,7 +113,7 @@
     SDL_BUTTON_WHEELDOWN = 5;
 
 
-{$IFDEF SDL13}
+{$IFDEF SDL2}
     // SDL_Event types
     // pascal does not support unions as is, so we list here every possible event
     // and later associate a struct type each
@@ -327,20 +327,20 @@
 // http://www.freepascal.org/docs-html/prog/progsu144.html
 
 type
-{$IFDEF SDL13}
+{$IFDEF SDL2}
     PSDL_Window   = Pointer;
     PSDL_Renderer = Pointer;
     PSDL_Texture  = Pointer;
     PSDL_GLContext= Pointer;
-    TSDL_FingerId = Int64;
     TSDL_TouchId  = Int64;
 {$ENDIF}
+    TSDL_FingerId = Int64;
 
     TSDL_eventaction = (SDL_ADDEVENT, SDL_PEEPEVENT, SDL_GETEVENT);
 
     PSDL_Rect = ^TSDL_Rect;
     TSDL_Rect = record
-{$IFDEF SDL13}
+{$IFDEF SDL2}
         x, y, w, h: LongInt;
 {$ELSE}
         x, y: SmallInt;
@@ -354,7 +354,7 @@
 
     PSDL_PixelFormat = ^TSDL_PixelFormat;
     TSDL_PixelFormat = record
-{$IFDEF SDL13}
+{$IFDEF SDL2}
         format: LongWord;
         palette: Pointer;
         BitsPerPixel : Byte;
@@ -400,9 +400,9 @@
         flags : LongWord;
         format: PSDL_PixelFormat;
         w, h  : LongInt;
-        pitch : {$IFDEF SDL13}LongInt{$ELSE}Word{$ENDIF};
+        pitch : {$IFDEF SDL2}LongInt{$ELSE}Word{$ENDIF};
         pixels: Pointer;
-{$IFDEF SDL13}
+{$IFDEF SDL2}
         userdata: Pointer;
         locked: LongInt;
         lock_data: Pointer;
@@ -432,7 +432,7 @@
     TClose = function( context: PSDL_RWops ): LongInt; cdecl;
 
     TStdio = record
-        autoclose: {$IFDEF SDL13}Boolean{$ELSE}LongInt{$ENDIF};
+        autoclose: {$IFDEF SDL2}Boolean{$ELSE}LongInt{$ENDIF};
         fp: Pointer;
         end;
 
@@ -444,7 +444,7 @@
 
     TUnknown = record
         data1: Pointer;
-{$IFDEF SDL13}
+{$IFDEF SDL2}
         data2: Pointer;
 {$ENDIF}
         end;
@@ -462,7 +462,7 @@
         size, left : LongInt;
         end;
     TWindowsio = record
-        append = {$IFDEF SDL13}Boolean{$ELSE}LongInt{$ENDIF};
+        append = {$IFDEF SDL2}Boolean{$ELSE}LongInt{$ENDIF};
         h = pointer;
         buffer = TWinbuffer;
         end;
@@ -491,7 +491,7 @@
 
 {* SDL_Event type definition *}
 
-{$IFDEF SDL13}
+{$IFDEF SDL2}
     TSDL_Keysym = record
         scancode: LongInt;
         sym: LongInt;
@@ -614,7 +614,7 @@
 {$ENDIF}
 
     TSDL_KeyboardEvent = record
-{$IFDEF SDL13}
+{$IFDEF SDL2}
         type_: LongWord;
         timestamp: LongWord;
         windowID: LongWord;
@@ -626,7 +626,7 @@
         end;
 
     TSDL_MouseMotionEvent = record
-{$IFDEF SDL13}
+{$IFDEF SDL2}
         type_: LongWord;
         timestamp: LongWord;
         windowID: LongWord;
@@ -639,7 +639,7 @@
         end;
 
     TSDL_MouseButtonEvent = record
-{$IFDEF SDL13}
+{$IFDEF SDL2}
         type_: LongWord;
         timestamp: LongWord;
         windowID: LongWord;
@@ -654,7 +654,7 @@
 
     TSDL_MouseWheelEvent = record
         type_: LongWord;
-{$IFDEF SDL13}
+{$IFDEF SDL2}
         timestamp: LongWord;
         windowID: LongWord;
         which: LongWord;
@@ -665,7 +665,7 @@
         end;
 
     TSDL_JoyAxisEvent = record
-{$IFDEF SDL13}
+{$IFDEF SDL2}
         type_: LongWord;
         timestamp: LongWord;
         which: LongWord;
@@ -674,7 +674,7 @@
         which: Byte;
 {$ENDIF}
         axis: Byte;
-{$IFDEF SDL13}
+{$IFDEF SDL2}
         padding1, padding2, padding3: Byte;
         value: LongInt;
         padding4: Word;
@@ -684,7 +684,7 @@
         end;
 
     TSDL_JoyBallEvent = record
-{$IFDEF SDL13}
+{$IFDEF SDL2}
         type_: LongWord;
         timestamp: LongWord;
         which: LongWord;
@@ -693,14 +693,14 @@
         which: Byte;
 {$ENDIF}
         ball: Byte;
-{$IFDEF SDL13}
+{$IFDEF SDL2}
         padding1, padding2, padding3: Byte;
 {$ENDIF}
         xrel, yrel: SmallInt;
         end;
 
     TSDL_JoyHatEvent = record
-{$IFDEF SDL13}
+{$IFDEF SDL2}
         type_: LongWord;
         timestamp: LongWord;
         which: LongWord;
@@ -710,13 +710,13 @@
 {$ENDIF}
         hat: Byte;
         value: Byte;
-{$IFDEF SDL13}
+{$IFDEF SDL2}
         padding1, padding2: Byte;
 {$ENDIF}
         end;
 
     TSDL_JoyButtonEvent = record
-{$IFDEF SDL13}
+{$IFDEF SDL2}
         type_: LongWord;
         timestamp: LongWord;
 {$ELSE}
@@ -725,13 +725,13 @@
         which: Byte;
         button: Byte;
         state: Byte;
-{$IFDEF SDL13}
+{$IFDEF SDL2}
         padding1: Byte;
 {$ENDIF}
         end;
 
     TSDL_QuitEvent = record
-{$IFDEF SDL13}
+{$IFDEF SDL2}
         type_: LongWord;
         timestamp: LongWord;
 {$ELSE}
@@ -740,7 +740,7 @@
         end;
 
     TSDL_UserEvent = record
-{$IFDEF SDL13}
+{$IFDEF SDL2}
         type_: LongWord;
         timestamp: LongWord;
         windowID: LongWord;
@@ -753,7 +753,7 @@
 
     PSDL_Event = ^TSDL_Event;
     TSDL_Event = record
-{$IFDEF SDL13}
+{$IFDEF SDL2}
         case LongInt of
             SDL_FIRSTEVENT: (type_: LongWord);
             SDL_COMMONDEVENT: (common: TSDL_CommonEvent);
@@ -837,7 +837,7 @@
         SDL_GL_MULTISAMPLEBUFFERS,
         SDL_GL_MULTISAMPLESAMPLES,
         SDL_GL_ACCELERATED_VISUAL,
-{$IFDEF SDL13}
+{$IFDEF SDL2}
         SDL_GL_RETAINED_BACKING,
         SDL_GL_CONTEXT_MAJOR_VERSION,
         SDL_GL_CONTEXT_MINOR_VERSION,
@@ -850,7 +850,7 @@
 {$ENDIF}
         );
 
-{$IFDEF SDL13}
+{$IFDEF SDL2}
     TSDL_ArrayByteOrder = (  // array component order, low Byte -> high Byte
         SDL_ARRAYORDER_NONE,
         SDL_ARRAYORDER_RGB,
@@ -965,7 +965,7 @@
 function  SDL_RWFromFile(filename, mode: PChar): PSDL_RWops; cdecl; external SDLLibName;
 function  SDL_SaveBMP_RW(surface: PSDL_Surface; dst: PSDL_RWops; freedst: LongInt): LongInt; cdecl; external SDLLibName;
 
-{$IFDEF SDL13}
+{$IFDEF SDL2}
 function  SDL_CreateWindow(title: PChar; x,y,w,h: LongInt; flags: LongWord): PSDL_Window; cdecl; external SDLLibName;
 function  SDL_CreateRenderer(window: PSDL_Window; index: LongInt; flags: LongWord): PSDL_Renderer; cdecl; external SDLLibName;
 function  SDL_DestroyWindow(window: PSDL_Window): LongInt; cdecl; external SDLLibName;
@@ -998,8 +998,15 @@
 procedure SDL_StartTextInput; cdecl; external SDLLibName;
 
 function  SDL_PeepEvents(event: PSDL_Event; numevents: LongInt; action: TSDL_eventaction; minType, maxType: LongWord): LongInt; cdecl; external SDLLibName;
+
+function  SDL_AllocFormat(format: LongWord): PSDL_PixelFormat; cdecl; external SDLLibName;
+procedure SDL_FreeFormat(pixelformat: PSDL_PixelFormat); cdecl; external SDLLibName;
 {$ELSE}
 function  SDL_PeepEvents(event: PSDL_Event; numevents: LongInt; action: TSDL_eventaction; mask: LongWord): LongInt; cdecl; external SDLLibName;
+
+function  SDL_EnableUNICODE(enable: LongInt): LongInt; cdecl; external SDLLibName;
+function  SDL_EnableKeyRepeat(timedelay, interval: LongInt): LongInt; cdecl; external SDLLibName;
+function  SDL_VideoDriverName(namebuf: PChar; maxlen: LongInt): PChar; cdecl; external SDLLibName;
 {$ENDIF}
 
 
@@ -1015,22 +1022,24 @@
 procedure SDL_SetEventFilter(filter: TSDL_EventFilter); cdecl; external SDLLibName;
 
 function  SDL_ShowCursor(toggle: LongInt): LongInt; cdecl; external SDLLibName;
+procedure SDL_WarpMouse(x, y: Word); {$IFDEF SDL2}inline{$ELSE}cdecl; external SDLLibName{$ENDIF};
+function  SDL_GetKeyState(numkeys: PLongInt): PByteArray; cdecl; external SDLLibName {$IFDEF SDL2} name 'SDL_GetKeyboardState'{$ENDIF};
 
 procedure SDL_WM_SetIcon(icon: PSDL_Surface; mask : Byte); cdecl; external SDLLibName;
 procedure SDL_WM_SetCaption(title: PChar; icon: PChar); cdecl; external SDLLibName;
 function  SDL_WM_ToggleFullScreen(surface: PSDL_Surface): LongInt; cdecl; external SDLLibName;
 
 
-// remember to mark the threaded functions as 'cdecl; export;'
-// (or have fun debugging nil arguments)
-function  SDL_CreateThread(fn: Pointer; {$IFDEF SDL13}name: PChar;{$ENDIF} data: Pointer): PSDL_Thread; cdecl; external SDLLibName;
+(* remember to mark the threaded functions as 'cdecl; export;'
+   (or have fun debugging nil arguments) *)
+function  SDL_CreateThread(fn: Pointer; {$IFDEF SDL2}name: PChar;{$ENDIF} data: Pointer): PSDL_Thread; cdecl; external SDLLibName;
 procedure SDL_WaitThread(thread: PSDL_Thread; status: PLongInt); cdecl; external SDLLibName;
 procedure SDL_KillThread(thread: PSDL_Thread); cdecl; external SDLLibName;
 
 function  SDL_CreateMutex: PSDL_mutex; cdecl; external SDLLibName;
 procedure SDL_DestroyMutex(mutex: PSDL_mutex); cdecl; external SDLLibName;
-function  SDL_LockMutex(mutex: PSDL_mutex): LongInt; cdecl; external SDLLibName {$IFNDEF SDL13}name 'SDL_mutexP'{$ENDIF};
-function  SDL_UnlockMutex(mutex: PSDL_mutex): LongInt; cdecl; external SDLLibName {$IFNDEF SDL13}name 'SDL_mutexV'{$ENDIF};
+function  SDL_LockMutex(mutex: PSDL_mutex): LongInt; cdecl; external SDLLibName {$IFNDEF SDL2}name 'SDL_mutexP'{$ENDIF};
+function  SDL_UnlockMutex(mutex: PSDL_mutex): LongInt; cdecl; external SDLLibName {$IFNDEF SDL2}name 'SDL_mutexV'{$ENDIF};
 
 function  SDL_GL_SetAttribute(attr: TSDL_GLattr; value: LongInt): LongInt; cdecl; external SDLLibName;
 procedure SDL_GL_SwapBuffers; cdecl; external SDLLibName;
@@ -1061,15 +1070,6 @@
 {$ENDIF}
 
 
-{* Compatibility between SDL-1.2 and SDL-1.3 *}
-procedure SDL_WarpMouse(x, y: Word); {$IFDEF SDL13}inline{$ELSE}cdecl; external SDLLibName{$ENDIF};
-function  SDL_GetKeyState(numkeys: PLongInt): PByteArray; cdecl; external SDLLibName {$IFDEF SDL13} name 'SDL_GetKeyboardState'{$ENDIF};
-function  SDL_AllocFormat(format: LongWord): PSDL_PixelFormat; {$IFDEF SDL13}cdecl; external SDLLibName;{$ENDIF}
-procedure SDL_FreeFormat(pixelformat: PSDL_PixelFormat); {$IFDEF SDL13}cdecl; external SDLLibName;{$ENDIF}
-function  SDL_VideoDriverName(namebuf: PChar; maxlen: LongInt): PChar; {$IFNDEF SDL13}cdecl; external SDLLibName;{$ENDIF}
-function  SDL_EnableUNICODE(enable: LongInt): LongInt; {$IFNDEF SDL13}cdecl; external SDLLibName;{$ENDIF}
-function  SDL_EnableKeyRepeat(timedelay, interval: LongInt): LongInt; {$IFNDEF SDL13}cdecl; external SDLLibName;{$ENDIF}
-
 (*  SDL_ttf  *)
 function  TTF_Init: LongInt; cdecl; external SDL_TTFLibName;
 procedure TTF_Quit; cdecl; external SDL_TTFLibName;
@@ -1084,8 +1084,8 @@
 procedure TTF_SetFontStyle(font: PTTF_Font; style: LongInt); cdecl; external SDL_TTFLibName;
 
 (*  SDL_mixer  *)
-function  Mix_Init(flags: LongInt): LongInt; {$IFDEF SDL_MIXER_NEWER}cdecl; external SDL_MixerLibName;{$ENDIF}
-procedure Mix_Quit; {$IFDEF SDL_MIXER_NEWER}cdecl; external SDL_MixerLibName;{$ENDIF}
+function  Mix_Init(flags: LongInt): LongInt; {$IFDEF SDL_MIXER_NEWER}cdecl; external SDL_MixerLibName{$ELSE}inline{$ENDIF};
+procedure Mix_Quit; {$IFDEF SDL_MIXER_NEWER}cdecl; external SDL_MixerLibName{$ELSE}inline{$ENDIF};
 
 function  Mix_OpenAudio(frequency: LongInt; format: Word; channels: LongInt; chunksize: LongInt): LongInt; cdecl; external SDL_MixerLibName;
 procedure Mix_CloseAudio; cdecl; external SDL_MixerLibName;
@@ -1120,8 +1120,8 @@
 procedure Mix_SetPostMix( mix_func: TPostMix; arg: pointer); cdecl; external SDL_MixerLibName;
 
 (*  SDL_image  *)
-function  IMG_Init(flags: LongInt): LongInt; {$IFDEF SDL_IMAGE_NEWER}cdecl; external SDL_ImageLibName;{$ENDIF}
-procedure IMG_Quit; {$IFDEF SDL_IMAGE_NEWER}cdecl; external SDL_ImageLibName;{$ENDIF}
+function  IMG_Init(flags: LongInt): LongInt; {$IFDEF SDL_IMAGE_NEWER}cdecl; external SDL_ImageLibName{$ELSE}inline{$ENDIF};
+procedure IMG_Quit; {$IFDEF SDL_IMAGE_NEWER}cdecl; external SDL_ImageLibName{$ELSE}inline{$ENDIF};
 
 function  IMG_Load(const _file: PChar): PSDL_Surface; cdecl; external SDL_ImageLibName;
 function  IMG_Load_RW(rwop: PSDL_RWops; freesrc: LongBool): PSDL_Surface; cdecl; external SDL_ImageLibName;
@@ -1150,64 +1150,23 @@
 function  SDLNet_Read32(buf: Pointer): LongWord;
 
 implementation
-{$IFDEF SDL13}
-uses strings, uVariables, uStore;
+{$IFDEF SDL2}
+uses uStore;
 
-// compatible functions
+// for sdl1.2 we directly call SDL_WarpMouse()
+// for sdl2 we provide a SDL_WarpMouse() which calls the right SDL_WarpMouseInWindow() function
+// this has the advantage of reducing 'uses' and 'ifdef' statements
+// (SDLwindow is a private member of uStore module)
 procedure SDL_WarpMouse(x, y: Word); inline;
 begin
     WarpMouse(x, y);
 end;
-
-function SDL_VideoDriverName(namebuf: PChar; maxlen: LongInt): PChar;
-var name : PChar = nil;
-begin
-    name:= SDL_GetCurrentVideoDriver();
-    if (name <> nil) and (namebuf <> nil) then
-        begin
-        strlcopy(namebuf, name, maxlen);
-        SDL_VideoDriverName:= namebuf
-        end;
-    SDL_VideoDriverName:= name;
-end;
-
-function SDL_EnableUNICODE(enable: LongInt): LongInt;
-begin
-    enable:= enable; // avoid hint
-    SDL_StartTextInput();
-    SDL_EnableUNICODE:= 0;
-end;
-
-function SDL_EnableKeyRepeat(timedelay, interval: LongInt): LongInt;
-begin
-    timedelay:= timedelay;  // avoid hint
-    interval:= interval;    // avoid hint
-    SDL_EnableKeyRepeat:= 0;
-end;
-{$ELSE}
-const conversionFormat: TSDL_PixelFormat = (
-        palette: nil; BitsPerPixel: 32; BytesPerPixel: 4;
-        Rloss: 0; Gloss: 0; Bloss: 0; Aloss: 0;
-        Rshift: RShift; Gshift: GShift; Bshift: BShift; Ashift: AShift;
-        RMask: RMask; GMask: GMask; BMask: BMask; AMask: AMask;
-        colorkey: 0; alpha: 255);
-
-function SDL_AllocFormat(format: LongWord): PSDL_PixelFormat;
-begin
-    format:= format;
-    SDL_AllocFormat:= @conversionFormat;
-end;
-
-procedure SDL_FreeFormat(pixelformat: PSDL_PixelFormat);
-begin
-    pixelformat:= pixelformat;  // avoid hint
-end;
 {$ENDIF}
 
 function SDL_MustLock(Surface: PSDL_Surface): Boolean;
 begin
     SDL_MustLock:=
-{$IFDEF SDL13}
+{$IFDEF SDL2}
         ((surface^.flags and SDL_RLEACCEL) <> 0)
 {$ELSE}
         ( surface^.offset <> 0 ) or (( surface^.flags and (SDL_HWSURFACE or SDL_ASYNCBLIT or SDL_RLEACCEL)) <> 0)
@@ -1215,23 +1174,23 @@
 end;
 
 {$IFNDEF SDL_MIXER_NEWER}
-function  Mix_Init(flags: LongInt): LongInt;
+function  Mix_Init(flags: LongInt): LongInt; inline;
 begin
     Mix_Init:= flags;
 end;
 
-procedure Mix_Quit;
+procedure Mix_Quit; inline;
 begin
 end;
 {$ENDIF}
 
 {$IFNDEF SDL_IMAGE_NEWER}
-function  IMG_Init(flags: LongInt): LongInt;
+function  IMG_Init(flags: LongInt): LongInt; inline;
 begin
     IMG_Init:= flags;
 end;
 
-procedure IMG_Quit;
+procedure IMG_Quit; inline;
 begin
 end;
 {$ENDIF}
--- a/hedgewars/hwengine.pas	Thu Jul 04 11:58:40 2013 +0200
+++ b/hedgewars/hwengine.pas	Sat Jul 06 19:29:18 2013 +0200
@@ -136,7 +136,7 @@
 var event: TSDL_Event;
     PrevTime, CurrTime: Longword;
     isTerminated: boolean;
-{$IFDEF SDL13}
+{$IFDEF SDL2}
     previousGameState: TGameState;
 {$ELSE}
     prevFocusState: boolean;
@@ -148,17 +148,17 @@
     begin
         SDL_PumpEvents();
 
-        while SDL_PeepEvents(@event, 1, SDL_GETEVENT, {$IFDEF SDL13}SDL_FIRSTEVENT, SDL_LASTEVENT{$ELSE}SDL_ALLEVENTS{$ENDIF}) > 0 do
+        while SDL_PeepEvents(@event, 1, SDL_GETEVENT, {$IFDEF SDL2}SDL_FIRSTEVENT, SDL_LASTEVENT{$ELSE}SDL_ALLEVENTS{$ENDIF}) > 0 do
         begin
             case event.type_ of
-{$IFDEF SDL13}
+{$IFDEF SDL2}
                 SDL_KEYDOWN:
                     if GameState = gsChat then
                         begin
                     // sdl on iphone supports only ashii keyboards and the unicode field is deprecated in sdl 1.3
                         KeyPressChat(SDL_GetKeyFromScancode(event.key.keysym.sym), event.key.keysym.sym); //TODO correct for keymodifiers
                         end
-                    else 
+                    else
                         if GameState >= gsGame then ProcessKey(event.key);
                 SDL_KEYUP:
                     if (GameState <> gsChat) and (GameState >= gsGame) then
@@ -339,7 +339,11 @@
     if not cOnlyStats then SDLTry(SDL_Init(SDL_INIT_VIDEO or SDL_INIT_NOPARACHUTE) >= 0, true);
     WriteLnToConsole(msgOK);
 
+{$IFDEF SDL2}
+    SDL_StartTextInput();
+{$ELSE}
     SDL_EnableUNICODE(1);
+{$ENDIF}
     SDL_ShowCursor(0);
 
     WriteToConsole('Init SDL_ttf... ');
--- a/hedgewars/options.inc	Thu Jul 04 11:58:40 2013 +0200
+++ b/hedgewars/options.inc	Sat Jul 06 19:29:18 2013 +0200
@@ -61,7 +61,7 @@
 {$ENDIF}
 
 {$IFDEF USE_TOUCH_INTERFACE}
-    {$DEFINE SDL13}
+    {$DEFINE SDL2}
 {$ENDIF}
 
 
--- a/hedgewars/uAI.pas	Thu Jul 04 11:58:40 2013 +0200
+++ b/hedgewars/uAI.pas	Sat Jul 06 19:29:18 2013 +0200
@@ -482,7 +482,7 @@
 FillBonuses(((Me^.State and gstAttacked) <> 0) and (not isInMultiShoot));
 
 SDL_LockMutex(ThreadLock);
-ThinkThread:= SDL_CreateThread(@Think{$IFDEF SDL13}, 'think'{$ENDIF}, Me);
+ThinkThread:= SDL_CreateThread(@Think{$IFDEF SDL2}, 'think'{$ENDIF}, Me);
 SDL_UnlockMutex(ThreadLock);
 end;
 
--- a/hedgewars/uChat.pas	Thu Jul 04 11:58:40 2013 +0200
+++ b/hedgewars/uChat.pas	Sat Jul 06 19:29:18 2013 +0200
@@ -298,7 +298,9 @@
 begin
     FreezeEnterKey;
     history:= 0;
+{$IFNDEF SDL2}
     SDL_EnableKeyRepeat(0,0);
+{$ENDIF}
     GameState:= gsGame;
     ResetKbd;
 end;
@@ -421,7 +423,9 @@
 begin
     s:= s; // avoid compiler hint
     GameState:= gsChat;
+{$IFNDEF SDL2}
     SDL_EnableKeyRepeat(200,45);
+{$ENDIF}
     if length(s) = 0 then
         SetLine(InputStr, '', true)
     else
--- a/hedgewars/uGame.pas	Thu Jul 04 11:58:40 2013 +0200
+++ b/hedgewars/uGame.pas	Sat Jul 06 19:29:18 2013 +0200
@@ -51,7 +51,7 @@
     else if (GameType = gmtSave) or (fastUntilLag and (GameType = gmtNet)) then
         Lag:= 2500;
 
-    if (GameType = gmtDemo) then 
+    if (GameType = gmtDemo) then
         if isSpeed then
             begin
             i:= RealTicks-SpeedStart;
@@ -90,7 +90,7 @@
         if CurrentHedgehog^.BotLevel <> 0 then
             ProcessBot;
         ProcessGears;
-        {$IFDEF SDL13}ProcessTouch;{$ENDIF}
+        {$IFDEF SDL2}ProcessTouch;{$ENDIF}
         end
     else
         begin
--- a/hedgewars/uGears.pas	Thu Jul 04 11:58:40 2013 +0200
+++ b/hedgewars/uGears.pas	Sat Jul 06 19:29:18 2013 +0200
@@ -48,7 +48,7 @@
 function  GearByUID(uid : Longword) : PGear;
 
 implementation
-uses uStore, uSound, uTeams, uRandom, uIO, uLandGraphics, {$IFDEF SDL13}uTouch,{$ENDIF}
+uses uStore, uSound, uTeams, uRandom, uIO, uLandGraphics, {$IFDEF SDL2}uTouch,{$ENDIF}
     uLocale, uAmmos, uStats, uVisualGears, uScript, uVariables,
     uCommands, uUtils, uTextures, uRenderUtils, uGearsRender, uCaptions, uDebug, uLandTexture,
     uGearsHedgehog, uGearsUtils, uGearsList, uGearsHandlersRope
@@ -151,7 +151,7 @@
                         dec(Gear^.Hedgehog^.InitialHealth, 5)
                     end
                 end;
-            if tmp > 0 then 
+            if tmp > 0 then
                 begin
                 inc(Gear^.Damage, min(tmp, max(0,Gear^.Health - 1 - Gear^.Damage)));
                 HHHurt(Gear^.Hedgehog, dsPoison);
@@ -172,7 +172,7 @@
 if GameTicks = NewTurnTick then
     begin
     ScriptCall('onNewTurn');
-{$IFDEF SDL13}
+{$IFDEF SDL2}
     uTouch.NewTurnBeginning();
 {$ENDIF}
     end;
@@ -201,7 +201,7 @@
         DeleteGear(curHandledGear)
     else
         begin
-        if curHandledGear^.Message and gmRemoveFromList <> 0 then 
+        if curHandledGear^.Message and gmRemoveFromList <> 0 then
             begin
             RemoveGearFromList(curHandledGear);
             // since I can't think of any good reason this would ever be separate from a remove from list, going to keep it inside this block
@@ -235,13 +235,13 @@
         if delay = 0 then
             inc(step)
         end;
-        
+
     stChDmg:
     if CheckNoDamage then
         inc(step)
     else
         step:= stDelay;
-        
+
     stSweep:
     if SweepDirty then
         begin
@@ -250,7 +250,7 @@
         end
     else
         inc(step);
-        
+
     stTurnReact:
         begin
         if (not bBetweenTurns) and (not isInMultiShoot) then
@@ -261,7 +261,7 @@
         else
             inc(step, 2);
         end;
-        
+
     stAfterDelay:
         begin
         if delay = 0 then
@@ -304,12 +304,12 @@
                 if cHealthDecrease <> 0 then
                     begin
                     SuddenDeathDmg:= true;
-                        
+
                     // flash
                     ScreenFade:= sfFromWhite;
                     ScreenFadeValue:= sfMax;
                     ScreenFadeSpeed:= 1;
-                    
+
                     ChangeToSDClouds;
                     ChangeToSDFlakes;
                     SetSkyColor(SDSkyColor.r * (SDTint/255) / 255, SDSkyColor.g * (SDTint/255) / 255, SDSkyColor.b * (SDTint/255) / 255);
@@ -419,7 +419,7 @@
 
 if TurnTimeLeft > 0 then
     if CurrentHedgehog^.Gear <> nil then
-        if ((CurrentHedgehog^.Gear^.State and gstAttacking) = 0) and 
+        if ((CurrentHedgehog^.Gear^.State and gstAttacking) = 0) and
             not(isInMultiShoot and (CurrentHedgehog^.CurAmmoType in [amShotgun, amDEagle, amSniperRifle])) then
                 begin
                 if (TurnTimeLeft = 5000)
@@ -518,7 +518,7 @@
             end;
         t:= t^.NextGear
         end;
-   
+
     if ((GameFlags and gfResetWeps) <> 0) and (not PlacingHogs) then
         ResetWeapons;
 
@@ -749,7 +749,7 @@
     FollowGear := AddGear(x, y, gtCase, 0, _0, _0, 0);
     cCaseFactor := 0;
     FollowGear^.Pos := posCaseDummy;
-    
+
     if explode then
         FollowGear^.Pos := FollowGear^.Pos + posCaseExplode;
     if poison then
@@ -852,7 +852,7 @@
             // if team matches current hedgehog team, default to current hedgehog
             if (i = 0) and (CurrentHedgehog <> nil) and (CurrentHedgehog^.Team = TeamsArray[t]) then
                 hh:= CurrentHedgehog
-            else 
+            else
                 begin
             // otherwise use the first living hog or the hog amongs the remaining ones indicated by i
                 j:= 0;
@@ -868,7 +868,7 @@
                     inc(j)
                     end
                 end;
-        if hh <> nil then 
+        if hh <> nil then
             begin
             Gear:= AddVisualGear(0, 0, vgtSpeechBubble);
             if Gear <> nil then
--- a/hedgewars/uMisc.pas	Thu Jul 04 11:58:40 2013 +0200
+++ b/hedgewars/uMisc.pas	Sat Jul 06 19:29:18 2013 +0200
@@ -30,7 +30,7 @@
 function  doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
 function  MakeScreenshot(filename: shortstring; k: LongInt): boolean;
 function  GetTeamStatString(p: PTeam): shortstring;
-{$IFDEF SDL13}
+{$IFDEF SDL2}
 function  SDL_RectMake(x, y, width, height: LongInt): TSDL_Rect; inline;
 {$ELSE}
 function  SDL_RectMake(x, y: SmallInt; width, height: Word): TSDL_Rect; inline;
@@ -261,7 +261,7 @@
 image^.size:= size;
 image^.buffer:= p;
 
-SDL_CreateThread(@SaveScreenshot{$IFDEF SDL13}, 'snapshot'{$ENDIF}, image);
+SDL_CreateThread(@SaveScreenshot{$IFDEF SDL2}, 'snapshot'{$ENDIF}, image);
 MakeScreenshot:= true; // possibly it is not true but we will not wait for thread to terminate
 end;
 
@@ -279,7 +279,7 @@
     end;
 end;
 
-{$IFDEF SDL13}
+{$IFDEF SDL2}
 function SDL_RectMake(x, y, width, height: LongInt): TSDL_Rect; inline;
 {$ELSE}
 function SDL_RectMake(x, y: SmallInt; width, height: Word): TSDL_Rect; inline;
@@ -299,14 +299,29 @@
 end;
 
 procedure initModule;
+{$IFDEF SDL2}
 const SDL_PIXELFORMAT_ABGR8888 = (1 shl 28) or (6 shl 24) or (7 shl 20) or (6 shl 16) or (32 shl 8) or 4;
+{$ELSE}
+const format: TSDL_PixelFormat = (
+        palette: nil; BitsPerPixel: 32; BytesPerPixel: 4;
+        Rloss: 0; Gloss: 0; Bloss: 0; Aloss: 0;
+        Rshift: RShift; Gshift: GShift; Bshift: BShift; Ashift: AShift;
+        RMask: RMask; GMask: GMask; BMask: BMask; AMask: AMask;
+        colorkey: 0; alpha: 255);
+{$ENDIF}
 begin
+{$IFDEF SDL2}
     conversionFormat:= SDL_AllocFormat(SDL_PIXELFORMAT_ABGR8888);
+{$ELSE}
+    conversionFormat:= @format;
+{$ENDIF}
 end;
 
 procedure freeModule;
 begin
+{$IFDEF SDL2}
     SDL_FreeFormat(conversionFormat);
+{$ENDIF}
 end;
 
 end.
--- a/hedgewars/uStore.pas	Thu Jul 04 11:58:40 2013 +0200
+++ b/hedgewars/uStore.pas	Sat Jul 06 19:29:18 2013 +0200
@@ -52,7 +52,9 @@
 procedure InitOffscreenOpenGL;
 {$ENDIF}
 
+{$IFDEF SDL2}
 procedure WarpMouse(x, y: Word); inline;
+{$ENDIF}
 procedure SwapBuffers; {$IFDEF USE_VIDEO_RECORDING}cdecl{$ELSE}inline{$ENDIF};
 procedure SetSkyColor(r, g, b: real);
 
@@ -61,12 +63,12 @@
     , uPhysFSLayer
     , uDebug
     {$IFDEF USE_CONTEXT_RESTORE}, uWorld{$ENDIF}
-    {$IF NOT DEFINED(SDL13) AND DEFINED(USE_VIDEO_RECORDING)}, glut {$ENDIF};
+    {$IF NOT DEFINED(SDL2) AND DEFINED(USE_VIDEO_RECORDING)}, glut {$ENDIF};
 
 //type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple);
 
 var MaxTextureSize: LongInt;
-{$IFDEF SDL13}
+{$IFDEF SDL2}
     SDLwindow: PSDL_Window;
     SDLGLcontext: PSDL_GLContext;
 {$ELSE}
@@ -76,7 +78,7 @@
     numsquares : LongInt;
     ProgrTex: PTexture;
 
-const 
+const
     cHHFileName = 'Hedgehog';
     cCHFileName = 'Crosshair';
 
@@ -202,7 +204,7 @@
                     foundBot:= true;
                     // initially was going to do the highest botlevel of the team, but for now, just apply if entire team has same bot level
                     if maxLevel = -1 then maxLevel:= BotLevel
-                    else if (maxLevel > 0) and (maxLevel <> BotLevel) then maxLevel:= 0; 
+                    else if (maxLevel > 0) and (maxLevel <> BotLevel) then maxLevel:= 0;
                     //if (maxLevel > 0) and (BotLevel < maxLevel) then maxLevel:= BotLevel
                     end
                 else if Gear <> nil then  maxLevel:= 0;
@@ -210,7 +212,7 @@
         if foundBot then
             begin
             // disabled the plain flag - I think it looks ok even w/ full bars obscuring CPU
-            //if (maxLevel > 0) and (maxLevel < 3) then Flag:= 'cpu_plain' else 
+            //if (maxLevel > 0) and (maxLevel < 3) then Flag:= 'cpu_plain' else
             Flag:= 'cpu'
             end
         else if (Flag = 'cpu') or (Flag = 'cpu_plain') then
@@ -220,10 +222,10 @@
         TryDo(flagsurf <> nil, 'Failed to load flag "' + Flag + '" as well as the default flag', true);
 
         case maxLevel of
-            1: copyToXY(SpritesData[sprBotlevels].Surface, flagsurf, 0, 0); 
-            2: copyToXYFromRect(SpritesData[sprBotlevels].Surface, flagsurf, 5, 2, 17, 13, 5, 2); 
-            3: copyToXYFromRect(SpritesData[sprBotlevels].Surface, flagsurf, 9, 5, 13, 10, 9, 5); 
-            4: copyToXYFromRect(SpritesData[sprBotlevels].Surface, flagsurf, 13, 9, 9, 6, 13, 9); 
+            1: copyToXY(SpritesData[sprBotlevels].Surface, flagsurf, 0, 0);
+            2: copyToXYFromRect(SpritesData[sprBotlevels].Surface, flagsurf, 5, 2, 17, 13, 5, 2);
+            3: copyToXYFromRect(SpritesData[sprBotlevels].Surface, flagsurf, 9, 5, 13, 10, 9, 5);
+            4: copyToXYFromRect(SpritesData[sprBotlevels].Surface, flagsurf, 13, 9, 9, 6, 13, 9);
             5: copyToXYFromRect(SpritesData[sprBotlevels].Surface, flagsurf, 17, 11, 5, 4, 17, 11)
             end;
 
@@ -385,7 +387,7 @@
                 if not reload then
                     begin
 {$IFDEF USE_CONTEXT_RESTORE}
-                    Surface:= tmpsurf 
+                    Surface:= tmpsurf
 {$ELSE}
                     if saveSurf then
                         Surface:= tmpsurf
@@ -606,7 +608,7 @@
 begin
     // check for file in user dir (never critical)
     tmpsurf:= LoadImage(cPathz[path] + '/' + filename, imageFlags);
-    
+
     LoadDataImage:= tmpsurf;
 end;
 
@@ -688,35 +690,38 @@
     SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 1);
 {$ELSE}
     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
-{$IFNDEF SDL13} // vsync is default in 1.3
+{$ENDIF}
+{$IFNDEF SDL2} // vsync is default in SDL2
     SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, LongInt((cReducedQuality and rqDesyncVBlank) = 0));
 {$ENDIF}
-{$ENDIF}
-    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); // no depth buffer
     SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
     SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
     SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
-    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); // no alpha channel required
-    SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 16); // buffer has to be 16 bit only
-    SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); // try to prefer hardware rendering
+    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);         // no depth buffer
+    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0);         // no alpha channel
+    SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 16);       // buffer should be 16
+    SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); // prefer hw rendering
 end;
 
 procedure SetupOpenGL;
-//var vendor: shortstring = '';
-var buf: array[byte] of char;
-{$IFDEF USE_VIDEO_RECORDING}
-    AuxBufNum: LongInt;
-{$ENDIF}
+var name: array[byte] of char;
+    AuxBufNum: LongInt = 0;
     tmpstr: AnsiString;
     tmpint: LongInt;
     tmpn: LongInt;
 begin
-    buf[0]:= char(0); // avoid compiler hint
-    AddFileLog('Setting up OpenGL (using driver: ' + shortstring(SDL_VideoDriverName(buf, sizeof(buf))) + ')');
+{$IFDEF SDL2}
+    name:= SDL_GetCurrentVideoDriver();
+{$ELSE}
+    name:= SDL_VideoDriverName(name, sizeof(name));
+{$ENDIF}
 
-{$IFDEF SDL13}
-    // this function creates an opengles1.1 context by default on mobile devices
-    // unless you un-comment this two attributes
+    AuxBufNum:= AuxBufNum;
+    AddFileLog('Setting up OpenGL (using driver: ' + shortstring(name) + ')');
+
+{$IFDEF MOBILE}
+    // TODO: this function creates an opengles1.1 context
+    // un-comment below and add proper logic to support opengles2.0
     //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
     //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
     if SDLGLcontext = nil then
@@ -725,7 +730,7 @@
     SDL_GL_SetSwapInterval(1);
 {$ENDIF}
 
-    // get the max (horizontal and vertical) size for textures that the gpu can support
+    // get the max (h and v) size for textures that the gpu can support
     glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize);
     if MaxTextureSize <= 0 then
         begin
@@ -734,29 +739,11 @@
         end
     else if (MaxTextureSize < 1024) and (MaxTextureSize >= 512) then
         begin
-        cReducedQuality := cReducedQuality or rqNoBackground;  
+        cReducedQuality := cReducedQuality or rqNoBackground;
         AddFileLog('Texture size too small for backgrounds, disabling.');
         end;
 
-(*  // find out which gpu we are using (for extension compatibility maybe?)
-{$IFDEF IPHONEOS}
-    vendor:= vendor; // avoid hint
-    cGPUVendor:= gvApple;
-{$ELSE}
-    vendor:= LowerCase(shortstring(pchar(glGetString(GL_VENDOR))));
-    if StrPos(Str2PChar(vendor), Str2PChar('nvidia')) <> nil then
-        cGPUVendor:= gvNVIDIA
-    else if StrPos(Str2PChar(vendor), Str2PChar('intel')) <> nil then
-        cGPUVendor:= gvATI
-    else if StrPos(Str2PChar(vendor), Str2PChar('ati')) <> nil then
-        cGPUVendor:= gvIntel
-    else
-        AddFileLog('OpenGL Warning - unknown hardware vendor; please report');
-{$ENDIF}
-//SupportNPOTT:= glLoadExtension('GL_ARB_texture_non_power_of_two');
-*)
-
-    // everyone love debugging
+    // everyone loves debugging
     AddFileLog('OpenGL-- Renderer: ' + shortstring(pchar(glGetString(GL_RENDERER))));
     AddFileLog('  |----- Vendor: ' + shortstring(pchar(glGetString(GL_VENDOR))));
     AddFileLog('  |----- Version: ' + shortstring(pchar(glGetString(GL_VERSION))));
@@ -857,7 +844,7 @@
         exit;
 
     if f = cDefaultZoomLevel then
-        glPopMatrix         // "return" to default scaling
+        glPopMatrix         // return to default scaling
     else                    // other scaling
         begin
         glPushMatrix;       // save default scaling
@@ -888,7 +875,7 @@
         with mobileRecord do
             if GameLoading <> nil then
                 GameLoading();
-        
+
         end;
 
     TryDo(ProgrTex <> nil, 'Error - Progress Texure is nil!', true);
@@ -1099,11 +1086,11 @@
 end;
 
 {$IFDEF USE_VIDEO_RECORDING}
-{$IFDEF SDL13}
+{$IFDEF SDL2}
 procedure InitOffscreenOpenGL;
 begin
     // create hidden window
-    SDLwindow:= SDL_CreateWindow('hedgewars (you don''t see this)',
+    SDLwindow:= SDL_CreateWindow('hedgewars video rendering (SDL2 hidden window)',
                                  SDL_WINDOWPOS_CENTERED_MASK, SDL_WINDOWPOS_CENTERED_MASK,
                                  cScreenWidth, cScreenHeight,
                                  SDL_WINDOW_HIDDEN or SDL_WINDOW_OPENGL);
@@ -1119,19 +1106,21 @@
     PrgName:= 'hwengine';
     glutInit(@ArgCount, @PrgName);
     glutInitWindowSize(cScreenWidth, cScreenHeight);
-    glutCreateWindow('hedgewars (you don''t see this)'); // we don't need a window, but if this function is not called then OpenGL will not be initialized
+    // we do not need a window, but without this call OpenGL will not initialize
+    glutCreateWindow('hedgewars video rendering (glut hidden window)');
     glutHideWindow();
-    glutDisplayFunc(@SwapBuffers); // we don't need a callback, but it's required for GLUT3
+    // we do not need to set this callback, but it is required for GLUT3 compat
+    glutDisplayFunc(@SwapBuffers);
     SetupOpenGL();
 end;
-{$ENDIF} // SDL13
+{$ENDIF} // SDL2
 {$ENDIF} // USE_VIDEO_RECORDING
 
 procedure chFullScr(var s: shortstring);
 var flags: Longword = 0;
     reinit: boolean = false;
     {$IFNDEF DARWIN}ico: PSDL_Surface;{$ENDIF}
-    {$IFDEF SDL13}x, y: LongInt;{$ENDIF}
+    {$IFDEF SDL2}x, y: LongInt;{$ENDIF}
 begin
     if cOnlyStats then
         begin
@@ -1141,7 +1130,7 @@
     if Length(s) = 0 then
          cFullScreen:= (not cFullScreen)
     else cFullScreen:= s = '1';
-    
+
     if cFullScreen then
         begin
         cScreenWidth:= cFullscreenWidth;
@@ -1154,14 +1143,16 @@
         end;
 
     AddFileLog('Preparing to change video parameters...');
-{$IFDEF SDL13}
+{$IFDEF SDL2}
     if SDLwindow = nil then
 {$ELSE}
     if SDLPrimSurface = nil then
 {$ENDIF}
         begin
         // set window title
-        {$IFNDEF SDL13}SDL_WM_SetCaption(_P'Hedgewars', nil);{$ENDIF}
+    {$IFNDEF SDL2}
+        SDL_WM_SetCaption(_P'Hedgewars', nil);
+    {$ENDIF}
         WriteToConsole('Init SDL_image... ');
         SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, true);
         WriteLnToConsole(msgOK);
@@ -1190,7 +1181,7 @@
         exit;
 {$ELSE}
         SetScale(cDefaultZoomLevel);
-     {$IFDEF USE_CONTEXT_RESTORE}
+    {$IFDEF USE_CONTEXT_RESTORE}
         reinit:= true;
         StoreRelease(true);
         ResetLand;
@@ -1198,7 +1189,7 @@
         //uTextures.freeModule; //DEBUG ONLY
     {$ENDIF}
         AddFileLog('Freeing old primary surface...');
-    {$IFNDEF SDL13}        
+    {$IFNDEF SDL2}
         SDL_FreeSurface(SDLPrimSurface);
         SDLPrimSurface:= nil;
     {$ENDIF}
@@ -1207,17 +1198,20 @@
 
     // these attributes must be set up before creating the sdl window
 {$IFNDEF WIN32}
-(* On a large number of testers machines, SDL default to software rendering when opengl attributes were set.
-   These attributes were "set" after CreateWindow in .15, which probably did nothing.
-   IMO we should rely on the gl_config defaults from SDL, and use SDL_GL_GetAttribute to possibly post warnings if any
-   bad values are set.  *)
+(* On a large number of testers machines, SDL default to software rendering
+   when opengl attributes were set. These attributes were "set" after
+   CreateWindow in .15, which probably did nothing.
+   IMO we should rely on the gl_config defaults from SDL, and use
+   SDL_GL_GetAttribute to possibly post warnings if any bad values are set.
+ *)
     SetupOpenGLAttributes();
 {$ENDIF}
-{$IFDEF SDL13}
+{$IFDEF SDL2}
     // these values in x and y make the window appear in the center
     x:= SDL_WINDOWPOS_CENTERED_MASK;
     y:= SDL_WINDOWPOS_CENTERED_MASK;
-    // SDL_WINDOW_RESIZABLE makes the window respond to rotation events on mobile devices
+    // SDL_WINDOW_RESIZABLE makes the window resizable and
+    //  respond to rotation events on mobile devices
     flags:= SDL_WINDOW_OPENGL or SDL_WINDOW_SHOWN or SDL_WINDOW_RESIZABLE;
 
     {$IFDEF MOBILE}
@@ -1227,20 +1221,16 @@
     flags:= flags or SDL_WINDOW_BORDERLESS;
     {$ENDIF}
 
+    if cFullScreen then
+        flags:= flags or SDL_WINDOW_FULLSCREEN;
+
     if SDLwindow = nil then
-        if cFullScreen then
-            SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cScreenWidth, cScreenHeight, flags or SDL_WINDOW_FULLSCREEN)
-        else
-            begin
-            SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cScreenWidth, cScreenHeight, flags);
-            end;
+        SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cScreenWidth, cScreenHeight, flags);
     SDLTry(SDLwindow <> nil, true);
 {$ELSE}
     flags:= SDL_OPENGL or SDL_RESIZABLE;
     if cFullScreen then
-        begin
         flags:= flags or SDL_FULLSCREEN;
-        end;
     if not cOnlyStats then
         begin
     {$IFDEF WIN32}
@@ -1249,7 +1239,9 @@
     {$ENDIF}
         SDLPrimSurface:= SDL_SetVideoMode(cScreenWidth, cScreenHeight, 0, flags);
         SDLTry(SDLPrimSurface <> nil, true);
-    {$IFDEF WIN32}SDL_putenv(str2pchar('SDL_VIDEO_CENTERED=' + s));{$ENDIF}
+    {$IFDEF WIN32}
+        SDL_putenv(str2pchar('SDL_VIDEO_CENTERED=' + s));
+    {$ENDIF}
         end;
 {$ENDIF}
 
@@ -1260,7 +1252,7 @@
         glClear(GL_COLOR_BUFFER_BIT);
         if SuddenDeathDmg then
             SetSkyColor(SDSkyColor.r * (SDTint/255) / 255, SDSkyColor.g * (SDTint/255) / 255, SDSkyColor.b * (SDTint/255) / 255)
-        else if ((cReducedQuality and rqNoBackground) = 0) then 
+        else if ((cReducedQuality and rqNoBackground) = 0) then
             SetSkyColor(SkyColor.r / 255, SkyColor.g / 255, SkyColor.b / 255)
         else
             SetSkyColor(RQSkyColor.r / 255, RQSkyColor.g / 255, RQSkyColor.b / 255);
@@ -1274,20 +1266,22 @@
         end;
 end;
 
+{$IFDEF SDL2}
+// for sdl1.2 we directly call SDL_WarpMouse()
+// for sdl2 we provide a SDL_WarpMouse() which just calls this function
+// this has the advantage of reducing 'uses' and 'ifdef' statements
+// (SDLwindow is a private member of this module)
 procedure WarpMouse(x, y: Word); inline;
 begin
-{$IFDEF SDL13}
     SDL_WarpMouseInWindow(SDLwindow, x, y);
-{$ELSE}
-    x:= x; y:= y; // avoid hints
+end;
 {$ENDIF}
-end;
 
 procedure SwapBuffers; {$IFDEF USE_VIDEO_RECORDING}cdecl{$ELSE}inline{$ENDIF};
 begin
     if GameType = gmtRecord then
         exit;
-{$IFDEF SDL13}
+{$IFDEF SDL2}
     SDL_GL_SwapWindow(SDLwindow);
 {$ELSE}
     SDL_GL_SwapBuffers();
@@ -1318,7 +1312,7 @@
     // init all count texture pointers
     for i:= Low(CountTexz) to High(CountTexz) do
         CountTexz[i] := nil;
-{$IFDEF SDL13}
+{$IFDEF SDL2}
     SDLwindow:= nil;
     SDLGLcontext:= nil;
 {$ELSE}
@@ -1330,7 +1324,7 @@
 begin
     StoreRelease(false);
     TTF_Quit();
-{$IFDEF SDL13}
+{$IFDEF SDL2}
     SDL_GL_DeleteContext(SDLGLcontext);
     SDL_DestroyWindow(SDLwindow);
 {$ENDIF}
--- a/hedgewars/uTypes.pas	Thu Jul 04 11:58:40 2013 +0200
+++ b/hedgewars/uTypes.pas	Sat Jul 06 19:29:18 2013 +0200
@@ -469,15 +469,15 @@
 
     POnScreenWidget = ^TOnScreenWidget;
     TOnScreenWidget = record
-        show          : boolean;                      // if false widget will not be drawn
-        sprite        : TSprite;                    // a convenience type
-        frame         : TSDL_Rect;                   // graphical coordinates
-        active        : TSDL_Rect;                  // active touch region
-        fadeAnimStart : Longword;            // time the fade started, 0 means don't fade
-        moveAnim      : TWidgetMovement;          // the animation associated to the widget
+        show          : boolean;            // if false widget will not be drawn
+        sprite        : TSprite;            // a convenience type
+        frame         : TSDL_Rect;          // graphical coordinates
+        active        : TSDL_Rect;          // active touch region
+        fadeAnimStart : Longword;           // time the fade started
+                                            //     (0 means do not fade)
+        moveAnim      : TWidgetMovement;    // animation associated to widget
         end;
 
-{$IFDEF SDL13}
     PTouch_Data = ^TTouch_Data;
     TTouch_Data = record
         id                       : TSDL_FingerId;
@@ -487,7 +487,6 @@
         timeSinceDown            : Longword;
         pressedWidget            : POnScreenWidget;
         end;
-{$ENDIF}
 
 implementation