koda's patch fixing some iphone port troubles (color, mouse)
authorunc0rr
Sun, 14 Jun 2009 13:20:28 +0000
changeset 2163 12730f5e79b9
parent 2162 2bce91404d49
child 2164 3d7e8afd869d
koda's patch fixing some iphone port troubles (color, mouse)
hedgewars/uConsts.pas
hedgewars/uKeys.pas
hedgewars/uLand.pas
hedgewars/uLandTexture.pas
hedgewars/uMisc.pas
--- a/hedgewars/uConsts.pas	Sat Jun 13 15:39:26 2009 +0000
+++ b/hedgewars/uConsts.pas	Sun Jun 14 13:20:28 2009 +0000
@@ -163,14 +163,25 @@
 
 	MAXNAMELEN = 192;
 
+{$IFDEF IPHONEOS}
+//gotta rework this for compatibility; is it really needed anyway?
+	LAND_WIDTH = 1024;
+    LAND_HEIGHT = 512;
+    LAND_WIDTH_MASK  = $FFFFFC00;
+    LAND_HEIGHT_MASK = $FFFFFE00;
+{$ELSE}
     LAND_WIDTH = 4096;
     LAND_HEIGHT = 2048;
     LAND_WIDTH_MASK  = $FFFFF000;
     LAND_HEIGHT_MASK = $FFFFF800;
-	
+{$ENDIF}
+
 	COLOR_LAND           = $FFFFFFFF;  // white
 	COLOR_INDESTRUCTIBLE = $FF0000FF;  // red
 
+    GL_BGR = $80E0; // some opengl headers do not have these macros
+	GL_BGRA = $80E1;
+
 	cifRandomize = $00000001;
 	cifTheme     = $00000002;
 	cifMap       = $00000002; // either theme or map (or map+theme)
--- a/hedgewars/uKeys.pas	Sat Jun 13 15:39:26 2009 +0000
+++ b/hedgewars/uKeys.pas	Sun Jun 14 13:20:28 2009 +0000
@@ -67,7 +67,12 @@
 {$ELSE}
 pkbd:= SDL_GetKeyState(nil);
 {$ENDIF}
-i:= SDL_GetMouseState(nil, nil);
+{$IFDEF IPHONEOS}
+//SDL_GetMouseState currently broken in sdl13
+i:=1;
+{$ELSE}
+i:=SDL_GetMouseState(nil, nil);
+{$ENDIF}
 pkbd^[1]:= (i and 1);
 pkbd^[2]:= ((i shr 1) and 1);
 {$IFDEF DARWIN}
--- a/hedgewars/uLand.pas	Sat Jun 13 15:39:26 2009 +0000
+++ b/hedgewars/uLand.pas	Sun Jun 14 13:20:28 2009 +0000
@@ -77,7 +77,10 @@
 if digest = '' then
    digest:= s
 else
+{$IFNDEF IPHONEOS}
+//HACK & FIXME!!!
    TryDo(s = digest, 'Different maps generated, sorry', true)
+{$ENDIF}
 end;
 
 procedure DrawLine(X1, Y1, X2, Y2: LongInt; Color: Longword);
--- a/hedgewars/uLandTexture.pas	Sat Jun 13 15:39:26 2009 +0000
+++ b/hedgewars/uLandTexture.pas	Sun Jun 14 13:20:28 2009 +0000
@@ -95,7 +95,11 @@
 					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	Sat Jun 13 15:39:26 2009 +0000
+++ b/hedgewars/uMisc.pas	Sun Jun 14 13:20:28 2009 +0000
@@ -150,7 +150,10 @@
 procedure FreeTexture(tex: PTexture);
 function  toPowerOf2(i: Longword): Longword;
 function DecodeBase64(s: shortstring): shortstring;
+{$IFNDEF IPHONEOS}
 procedure MakeScreenshot(s: shortstring);
+{$ENDIF}
+
 function modifyDamage(dmg: Longword): Longword;
 
 var CursorPoint: TPoint;
@@ -331,8 +334,11 @@
 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);
@@ -341,7 +347,8 @@
 end;
 
 function Surface2Tex(surf: PSDL_Surface): PTexture;
-var mode: LongInt;
+var modeIntFormat: LongInt;
+    modeFormat: LongInt;
 	tw, th, x, y: Longword;
 	tmpp: pointer;
 	fromP4, toP4: PLongWordArray;
@@ -351,8 +358,26 @@
 Surface2Tex^.w:= surf^.w;
 Surface2Tex^.h:= surf^.h;
 
-if (surf^.format^.BytesPerPixel = 3) then mode:= GL_RGB else
-if (surf^.format^.BytesPerPixel = 4) then mode:= GL_RGBA else
+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
    TryDo(false, 'Surface2Tex: BytesPerPixel not in [3, 4]', true);
    Surface2Tex^.id:= 0;
@@ -433,18 +458,17 @@
 			end;
 		end;
 
-//   gluScaleImage(mode, Surf^.w, Surf^.h, GL_UNSIGNED_BYTE,
-//        Surf^.pixels, tw, th, GL_UNSIGNED_BYTE,
-//        tmpp);
-
-	glTexImage2D(GL_TEXTURE_2D, 0, mode, tw, th, 0, mode, GL_UNSIGNED_BYTE, tmpp);
+//	legacy resizing function
+//	gluScaleImage(mode, Surf^.w, Surf^.h, GL_UNSIGNED_BYTE, Surf^.pixels, tw, th, GL_UNSIGNED_BYTE, tmpp);
+	
+	glTexImage2D(GL_TEXTURE_2D, 0, modeIntFormat, tw, th, 0, modeFormat, GL_UNSIGNED_BYTE, tmpp);
 	
 	FreeMem(tmpp, tw * th * surf^.format^.BytesPerPixel)
 	end else
 	begin
 	Surface2Tex^.rx:= 1.0;
 	Surface2Tex^.ry:= 1.0;
-	glTexImage2D(GL_TEXTURE_2D, 0, mode, surf^.w, surf^.h, 0, mode, GL_UNSIGNED_BYTE, surf^.pixels);
+	glTexImage2D(GL_TEXTURE_2D, 0, modeIntFormat, surf^.w, surf^.h, 0, modeFormat, GL_UNSIGNED_BYTE, surf^.pixels);
 	end;
 
 ResetVertexArrays(Surface2Tex);
@@ -495,7 +519,7 @@
 byte(DecodeBase64[0]):= t - 1
 end;
 
-const GL_BGR = $80E0; // some opengl headers don't have that const (?)'
+{$IFNDEF IPHONEOS}
 procedure MakeScreenshot(s: shortstring);
 const head: array[0..8] of Word = (0, 2, 0, 0, 0, 0, 0, 0, 24);
 var p: Pointer;
@@ -508,11 +532,9 @@
 size:= cScreenWidth * cScreenHeight * 3;
 p:= GetMem(size);
 
-{$IFDEF IPHONEOS}
-//since opengl es operates on a single surface GL_FRONT is implied, but how to test that?
-{$ELSE}
+
+//remember that opengles operates on a single surface, so GL_FRONT *should* be implied
 glReadBuffer(GL_FRONT);
-{$ENDIF}
 glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_BGR, GL_UNSIGNED_BYTE, p);
 
 {$I-}
@@ -528,6 +550,7 @@
 
 FreeMem(p)
 end;
+{$ENDIF}
 
 function modifyDamage(dmg: Longword): Longword;
 begin