make screenshots with 32bits of depths, so that they are more opengles friendly
authorkoda
Thu, 03 Nov 2011 03:58:24 +0100
changeset 6267 be5d40bb1e86
parent 6266 b02a1e92dba2
child 6268 d773867f93db
make screenshots with 32bits of depths, so that they are more opengles friendly
hedgewars/hwengine.pas
hedgewars/uMisc.pas
--- a/hedgewars/hwengine.pas	Thu Nov 03 01:10:25 2011 +0100
+++ b/hedgewars/hwengine.pas	Thu Nov 03 03:58:24 2011 +0100
@@ -115,15 +115,11 @@
         s:= 'hw_' + FormatDateTime('YYYY-MM-DD_HH-mm-ss', Now()) + inttostr(GameTicks);
 
         playSound(sndShutter);
-{$IFNDEF IPHONEOS}
-        if not MakeScreenshot(s) then
-        begin
+        if MakeScreenshot(s) then WriteLnToConsole('Screenshot saved: ' + s)
+        else begin
             WriteLnToConsole('Screenshot failed.');
             AddChatString(#5 + 'screen capture failed (lack of memory or write permissions)');
-        end
-        else
-{$ENDIF}
-            WriteLnToConsole('Screenshot saved: ' + s);
+            end
     end;
 end;
 
@@ -148,11 +144,8 @@
 
 ///////////////////
 procedure MainLoop;
-{$WARNINGS OFF}
-// disable "Some fields weren't initialized" warning
-const event: TSDL_Event = ();
-{$WARNINGS ON}
-var PrevTime, CurrTime: Longword;
+var event: TSDL_Event;
+    PrevTime, CurrTime: Longword;
 {$IFDEF SDL13}
     previousGameState: TGameState;
 {$ELSE}
--- a/hedgewars/uMisc.pas	Thu Nov 03 01:10:25 2011 +0100
+++ b/hedgewars/uMisc.pas	Thu Nov 03 03:58:24 2011 +0100
@@ -53,21 +53,21 @@
     f: file;
     // Windows Bitmap Header
     head: array[0..53] of Byte = (
-    $42, $4D, // identifier ("BM")
-    0, 0, 0, 0, // file size
-    0, 0, 0, 0, // reserved
-    54, 0, 0, 0, // starting offset
-    40, 0, 0, 0, // header size
-    0, 0, 0, 0, // width
-    0, 0, 0, 0, // height
-    1, 0, // color planes
-    24, 0, // bit depth
-    0, 0, 0, 0, // compression method (uncompressed)
-    0, 0, 0, 0, // image size
-    96, 0, 0, 0, // horizontal resolution
-    96, 0, 0, 0, // vertical resolution
-    0, 0, 0, 0, // number of colors (all)
-    0, 0, 0, 0 // number of important colors
+    $42, $4D,       // identifier ("BM")
+    0, 0, 0, 0,     // file size
+    0, 0, 0, 0,     // reserved
+    54, 0, 0, 0,    // starting offset
+    40, 0, 0, 0,    // header size
+    0, 0, 0, 0,     // width
+    0, 0, 0, 0,     // height
+    1, 0,           // color planes
+    32, 0,          // bit depth
+    0, 0, 0, 0,     // compression method (uncompressed)
+    0, 0, 0, 0,     // image size
+    96, 0, 0, 0,    // horizontal resolution
+    96, 0, 0, 0,    // vertical resolution
+    0, 0, 0, 0,     // number of colors (all)
+    0, 0, 0, 0      // number of important colors
     );
 begin
 // flash
@@ -75,7 +75,7 @@
 ScreenFadeValue:= sfMax;
 ScreenFadeSpeed:= 5;
 
-size:= toPowerOf2(cScreenWidth) * toPowerOf2(cScreenHeight) * 3;
+size:= toPowerOf2(cScreenWidth) * toPowerOf2(cScreenHeight) * 4;
 p:= GetMem(size);
 
 // memory could not be allocated
@@ -86,7 +86,6 @@
 end;
 
 // update header information and file name
-
 filename:= UserPathPrefix + '/Screenshots/' + filename + '.bmp';
 
 head[$02]:= (size + 54) and $ff;
@@ -106,9 +105,8 @@
 head[$24]:= (size shr 16) and $ff;
 head[$25]:= (size shr 24) and $ff;
 
-//remember that opengles operates on a single surface, so GL_FRONT *should* be implied
-//glReadBuffer(GL_FRONT);
-glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_BGR, GL_UNSIGNED_BYTE, p);
+// read pixel from the front buffer
+glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_BGRA, GL_UNSIGNED_BYTE, p);
 
 {$IOCHECKS OFF}
 Assign(f, filename);
@@ -128,7 +126,6 @@
 {$IOCHECKS ON}
 
 FreeMem(p, size);
-
 MakeScreenshot:= success;
 end;