real fix for iphone color (reverting previous commit)
authorkoda
Fri, 10 Jul 2009 16:47:11 +0000
changeset 2248 26e11cb27c61
parent 2247 10a5c05e09c9
child 2249 ac8a762ccb4e
real fix for iphone color (reverting previous commit)
hedgewars/SDLh.pas
hedgewars/uConsts.pas
hedgewars/uLandTexture.pas
hedgewars/uMisc.pas
hedgewars/uStore.pas
share/hedgewars/Data/Maps/Basketball/mask.png
--- a/hedgewars/SDLh.pas	Fri Jul 10 14:46:33 2009 +0000
+++ b/hedgewars/SDLh.pas	Fri Jul 10 16:47:11 2009 +0000
@@ -151,6 +151,7 @@
                     offset: LongInt;
                     end;
 
+
      PSDL_Color = ^TSDL_Color;
      TSDL_Color = record
                   case byte of
@@ -162,6 +163,7 @@
                        1: (value: Longword);
                   end;
 
+
      PSDL_RWops = ^TSDL_RWops;
      TSeek = function( context: PSDL_RWops; offset: LongInt; whence: LongInt ): LongInt; cdecl;
      TRead = function( context: PSDL_RWops; Ptr: Pointer; size: LongInt; maxnum : LongInt ): LongInt;  cdecl;
@@ -276,6 +278,7 @@
 procedure SDL_FreeSurface(Surface: PSDL_Surface); cdecl; external SDLLibName;
 function  SDL_SetColorKey(surface: PSDL_Surface; flag, key: Longword): LongInt; cdecl; external SDLLibName;
 function  SDL_SetAlpha(surface: PSDL_Surface; flag, key: Longword): LongInt; cdecl; external SDLLibName;
+function  SDL_ConvertSurface(src: PSDL_Surface; fmt: PSDL_PixelFormat; flags: LongInt): PSDL_Surface; cdecl; external SDLLibName;
 
 function  SDL_UpperBlit(src: PSDL_Surface; srcrect: PSDL_Rect; dst: PSDL_Surface; dstrect: PSDL_Rect): LongInt; cdecl; external SDLLibName;
 function  SDL_FillRect(dst: PSDL_Surface; dstrect: PSDL_Rect; color: Longword): LongInt; cdecl; external SDLLibName;
--- a/hedgewars/uConsts.pas	Fri Jul 10 14:46:33 2009 +0000
+++ b/hedgewars/uConsts.pas	Fri Jul 10 16:47:11 2009 +0000
@@ -190,9 +190,9 @@
 {$ENDIF}
 
     COLOR_LAND           = $FFFF;  // white
-    COLOR_INDESTRUCTIBLE = $FF88;  // green
+    COLOR_INDESTRUCTIBLE = $88FF;  // red
 
-    //some opengl headers do not have these macros
+    //some opengl headers do not have these macros (unused)
     GL_BGR  = $80E0;
     GL_BGRA = $80E1;
 
--- a/hedgewars/uLandTexture.pas	Fri Jul 10 14:46:33 2009 +0000
+++ b/hedgewars/uLandTexture.pas	Fri Jul 10 16:47:11 2009 +0000
@@ -95,11 +95,7 @@
 					begin
 					shouldUpdate:= false;
 					glBindTexture(GL_TEXTURE_2D, tex^.id);
-					{$IFDEF IPHONEOS}
-					glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, TEXSIZE, TEXSIZE, GL_BGRA, GL_UNSIGNED_BYTE, Pixels(x, y));
-					{$ELSE}
 					glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, TEXSIZE, TEXSIZE, GL_RGBA, GL_UNSIGNED_BYTE, Pixels(x, y));
-					{$ENDIF}
 					end
 end;
 
--- a/hedgewars/uMisc.pas	Fri Jul 10 14:46:33 2009 +0000
+++ b/hedgewars/uMisc.pas	Fri Jul 10 16:47:11 2009 +0000
@@ -334,11 +334,7 @@
 glGenTextures(1, @NewTexture^.id);
 
 glBindTexture(GL_TEXTURE_2D, NewTexture^.id);
-{$IFDEF IPHONEOS}
-glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, buf);
-{$ELSE}
 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf);
-{$ENDIF}
 
 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
@@ -361,21 +357,13 @@
 if (surf^.format^.BytesPerPixel = 3) then 
 	begin
 		modeIntFormat:= GL_RGB;
-		{$IFDEF IPHONEOS}
-		modeFormat:= GL_BGR;
-		{$ELSE}
 		modeFormat:= modeIntFormat;
-		{$ENDIF}
 	end
 else
 if (surf^.format^.BytesPerPixel = 4) then
 	begin
 		modeIntFormat:= GL_RGBA;
-		{$IFDEF IPHONEOS}
-		modeFormat:= GL_BGRA;
-		{$ELSE}
 		modeFormat:= modeIntFormat;
-		{$ENDIF}
 	end
 else
    begin
--- a/hedgewars/uStore.pas	Fri Jul 10 14:46:33 2009 +0000
+++ b/hedgewars/uStore.pas	Fri Jul 10 16:47:11 2009 +0000
@@ -281,11 +281,7 @@
         if (not cReducedQuality) or ((ii <> sprSky) and (ii <> sprHorizont) and (ii <> sprFlake)) then
 		begin
 			if AltPath = ptNone then
-//{$IFDEF IPHONEOS}
-//				tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent)
-//{$ELSE}
 				tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifCritical or ifLowRes)
-//{$ENDIF}
 			else begin
 				tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent);
 				if tmpsurf = nil then
@@ -879,11 +875,30 @@
 Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16)
 end;
 
-// hasAlpha: boolean; critical, setTransparent: boolean
 function  LoadImage(const filename: string; imageFlags: Integer): PSDL_Surface;
 var tmpsurf: PSDL_Surface;
-    //Result: PSDL_Surface;
     s: shortstring;
+{$IFDEF IPHONEOS}
+    convertedSurf: PSDL_Surface;
+const TestFormat: TSDL_PixelFormat = (
+            palette: nil; 
+            BitsPerPixel : 32;
+            BytesPerPixel: 4;
+            Rloss : 0; 
+            Gloss : 0; 
+            Bloss : 0; 
+            Aloss : 0; 
+			Rshift: 0; 
+            Gshift: 8; 
+            Bshift: 16; 
+            Ashift: 24; 
+            RMask : $000000FF; 
+            GMask : $0000FF00; 
+            BMask : $00FF0000; 
+            AMask : $FF000000; 
+            colorkey: 0;
+            alpha : 255); 
+{$ENDIF}
 begin
 WriteToConsole(msgLoading + filename + '... ');
 s:= filename + '.' + cBitsStr + '.png';
@@ -923,15 +938,21 @@
 	begin
 		SDL_FreeSurface(tmpsurf);
 		OutError(msgFailedSize, (imageFlags and ifCritical) <> 0);
+		//dummy surface to replace non-critical textures that failed to load due to their size
 		exit(SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32, RMask, GMask, BMask, AMask));
 	end;
 
 if (imageFlags and ifTransparent) <> 0 then TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
-//if (imageFlags and ifAlpha) <> 0 then Result:= SDL_DisplayFormatAlpha(tmpsurf)
-//            else Result:= SDL_DisplayFormat(tmpsurf);
+//if (imageFlags and ifAlpha) <> 0 then Result:= SDL_DisplayFormatAlpha(tmpsurf) else Result:= SDL_DisplayFormat(tmpsurf);
 WriteLnToConsole('(' + inttostr(tmpsurf^.w) + ',' + inttostr(tmpsurf^.h) + ') ');
 WriteLnToConsole(msgOK);
 
+{$IFDEF IPHONEOS}
+//for more information http://www.idevgames.com/forum/showpost.php?p=85864&postcount=7
+convertedSurf:= SDL_ConvertSurface(tmpsurf, @TestFormat, SDL_SWSURFACE);
+tmpsurf:= convertedSurf;
+{$ENDIF}
+
 LoadImage:= tmpsurf //Result
 end;
 
Binary file share/hedgewars/Data/Maps/Basketball/mask.png has changed