make sdl1.3 window creation code more readable
authorkoda
Fri, 29 Apr 2011 02:42:46 +0200
changeset 5187 b01ab1ef01fb
parent 5186 a05c14510c8a
child 5188 d0461bd6d45b
make sdl1.3 window creation code more readable
hedgewars/SDLh.pas
hedgewars/uStore.pas
--- a/hedgewars/SDLh.pas	Thu Apr 28 01:01:07 2011 +0200
+++ b/hedgewars/SDLh.pas	Fri Apr 29 02:42:46 2011 +0200
@@ -767,16 +767,17 @@
 function  SDL_CreateRenderer(window: PSDL_Window; index, flags: LongInt): PSDL_Renderer; cdecl; external SDLLibName;
 function  SDL_DestroyRenderer(renderer: PSDL_Renderer): LongInt; cdecl; external SDLLibName;
 function  SDL_DestroyWindow(window: PSDL_Window): LongInt; cdecl; external SDLLibName;
-function  SDL_GetRenderer(window: PSDL_Window): PSDL_Renderer; cdecl; external SDLLibName;
 
 procedure SDL_VideoQuit; cdecl; external SDLLibName;
 function  SDL_GetNumVideoDisplays: LongInt; cdecl; external SDLLibName;
 
 function  SDL_SetRenderDrawColor(renderer: PSDL_Renderer; r,g,b,a: byte): LongInt; cdecl; external SDLLibName;
+function  SDL_GetRenderer(window: PSDL_Window): PSDL_Renderer; cdecl; external SDLLibName;
 function  SDL_RenderFillRect(renderer: PSDL_Renderer; rect: PSDL_Rect): LongInt; cdecl; external SDLLibName;
 function  SDL_RenderClear(renderer: PSDL_Renderer): LongInt; cdecl; external SDLLibName;
 procedure SDL_RenderPresent(renderer: PSDL_Renderer); cdecl; external SDLLibName;
 function  SDL_RenderReadPixels(renderer: PSDL_Renderer; rect: PSDL_Rect; format: LongInt; pixels: pointer; pitch: LongInt): LongInt; cdecl; external SDLLibName;
+function  SDL_RenderSetViewport(window: PSDL_Window; rect: PSDL_Rect): LongInt; cdecl; external SDLLibName;
 
 function  SDL_SelectMouse(index: LongInt): LongInt; cdecl; external SDLLibName;
 function  SDL_GetRelativeMouseState(x, y: PLongInt): Byte; cdecl; external SDLLibName;
--- a/hedgewars/uStore.pas	Thu Apr 28 01:01:07 2011 +0200
+++ b/hedgewars/uStore.pas	Fri Apr 29 02:42:46 2011 +0200
@@ -510,7 +510,7 @@
 {$IFNDEF IPHONEOS}
 var vendor: shortstring;
 {$IFDEF DARWIN}
-const one = 1;
+const one : LongInt = 1;
 {$ENDIF}
 {$ENDIF}
 begin
@@ -523,7 +523,7 @@
     vendor:= LowerCase(shortstring(pchar(glGetString(GL_VENDOR))));
 {$IFNDEF SDL13}
 // this attribute is default in 1.3 and must be enabled in MacOSX
-    SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, ((cReducedQuality and rqDesyncVBlank) = 0))
+    SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, LongInt((cReducedQuality and rqDesyncVBlank) = 0));
 
 {$IFDEF DARWIN}
 // fixes vsync in Snow Leopard
@@ -921,22 +921,32 @@
     end;
 
 {$IFDEF SDL13}
-    if SDLwindow = nil then
-    begin
-        // the values in x and y make the window appear in the center
-        // on ios, make the sdl window appear on the second monitor when present
-        x:= (SDL_WINDOWPOS_CENTERED_MASK or {$IFDEF IPHONEOS}(SDL_GetNumVideoDisplays() - 1){$ELSE}0{$ENDIF});
-        y:= (SDL_WINDOWPOS_CENTERED_MASK or {$IFDEF IPHONEOS}(SDL_GetNumVideoDisplays() - 1){$ELSE}0{$ENDIF});
-        SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cScreenWidth, cScreenHeight, SDL_WINDOW_OPENGL or SDL_WINDOW_SHOWN
-                          {$IFDEF IPHONEOS} or SDL_WINDOW_BORDERLESS {$ENDIF});  // do not set SDL_WINDOW_RESIZABLE on iOS
-        SDLrender:= SDL_CreateRenderer(SDLwindow, -1, SDL_RENDERER_ACCELERATED or SDL_RENDERER_PRESENTVSYNC);
-    end;
+    // these values in x and y make the window appear in the center
+    x:= SDL_WINDOWPOS_CENTERED_MASK;
+    y:= SDL_WINDOWPOS_CENTERED_MASK;
+    flags:= SDL_WINDOW_OPENGL or SDL_WINDOW_SHOWN;
+
+{$IFDEF IPHONEOS}
+    // make the sdl window appear on the second monitor when present
+    x:= x or (SDL_GetNumVideoDisplays() - 1);
+    y:= y or (SDL_GetNumVideoDisplays() - 1);
 
+    // hardcode the opengles driver as we do our own drawing
+    SDL_SetHint('SDL_RENDER_DRIVER','opengles');
+    flags:= flags or SDL_WINDOW_BORDERLESS;  // do not set SDL_WINDOW_RESIZABLE on iOS
+{$ENDIF}
+
+    SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cScreenWidth, cScreenHeight, flags);
+    SDLTry(SDLwindow <> nil, true);
+    SDLrender:= SDL_CreateRenderer(SDLwindow, -1, SDL_RENDERER_ACCELERATED or SDL_RENDERER_PRESENTVSYNC);
+    SDLTry(SDLrender <> nil, true);
+
+    // clean the renderer before using it
     SDL_SetRenderDrawColor(SDLrender, 0, 0, 0, 255);
     SDL_RenderClear(SDLrender);
     SDL_RenderPresent(SDLrender);
 
-    // we need to reset the gl context from the one created by SDL as we have our own drawing system
+    // reset the gl context from the one created by SDL (as we have our own drawing system)
     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
 {$ELSE}