hedgewars/uMisc.pas
changeset 5910 c9a4de51b5a0
parent 5239 f34f391a223b
child 5911 4a28d0ae9624
equal deleted inserted replaced
5909:fb0113caa8c7 5910:c9a4de51b5a0
    46 end;
    46 end;
    47 
    47 
    48 
    48 
    49 procedure MakeScreenshot(filename: shortstring);
    49 procedure MakeScreenshot(filename: shortstring);
    50 var p: Pointer;
    50 var p: Pointer;
    51     size: Longword;
    51     size: QWord;
    52     f: file;
    52     f: file;
    53     // Windows Bitmap Header
    53     // Windows Bitmap Header
    54     head: array[0..53] of Byte = (
    54     head: array[0..53] of Byte = (
    55     $42, $4D, // identifier ("BM")
    55     $42, $4D, // identifier ("BM")
    56     0, 0, 0, 0, // file size
    56     0, 0, 0, 0, // file size
    75 ScreenFadeSpeed:= 5;
    75 ScreenFadeSpeed:= 5;
    76 
    76 
    77 size:= cScreenWidth * cScreenHeight * 3;
    77 size:= cScreenWidth * cScreenHeight * 3;
    78 p:= GetMem(size);
    78 p:= GetMem(size);
    79 
    79 
       
    80 // memory could not be allocated
       
    81 if p = nil then
       
    82     exit;
       
    83 
    80 // update header information and file name
    84 // update header information and file name
    81 
    85 
    82 filename:= UserPathPrefix + '/Screenshots/' + filename + '.bmp';
    86 filename:= UserPathPrefix + '/Screenshots/' + filename + '.bmp';
    83 
    87 
    84 head[$02]:= (size + 54) and $ff;
    88 head[$02]:= (size + 54) and $ff;
   100 
   104 
   101 //remember that opengles operates on a single surface, so GL_FRONT *should* be implied
   105 //remember that opengles operates on a single surface, so GL_FRONT *should* be implied
   102 //glReadBuffer(GL_FRONT);
   106 //glReadBuffer(GL_FRONT);
   103 glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_BGR, GL_UNSIGNED_BYTE, p);
   107 glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_BGR, GL_UNSIGNED_BYTE, p);
   104 
   108 
   105 {$I-}
   109 {$IOCHECKS OFF}
   106 Assign(f, filename);
   110 Assign(f, filename);
   107 Rewrite(f, 1);
   111 Rewrite(f, 1);
   108 if IOResult = 0 then
   112 if IOResult = 0 then
   109     begin
   113     begin
   110     BlockWrite(f, head, sizeof(head));
   114     BlockWrite(f, head, sizeof(head));
   111     BlockWrite(f, p^, size);
   115     BlockWrite(f, p^, size);
   112     Close(f);
   116     Close(f);
   113     end;
   117     end;
   114 {$I+}
   118 {$IOCHECKS ON}
   115 
   119 
   116 FreeMem(p)
   120 FreeMem(p, size)
   117 end;
   121 end;
   118 
   122 
   119 // http://www.idevgames.com/forums/thread-5602-post-21860.html#pid21860
   123 // http://www.idevgames.com/forums/thread-5602-post-21860.html#pid21860
   120 function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
   124 function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
   121 var convertedSurf: PSDL_Surface;
   125 var convertedSurf: PSDL_Surface;