hedgewars/uMisc.pas
changeset 6267 be5d40bb1e86
parent 5912 d31eba29e706
child 6695 32de8965c62c
equal deleted inserted replaced
6266:b02a1e92dba2 6267:be5d40bb1e86
    51     p: Pointer;
    51     p: Pointer;
    52     size: QWord;
    52     size: QWord;
    53     f: file;
    53     f: file;
    54     // Windows Bitmap Header
    54     // Windows Bitmap Header
    55     head: array[0..53] of Byte = (
    55     head: array[0..53] of Byte = (
    56     $42, $4D, // identifier ("BM")
    56     $42, $4D,       // identifier ("BM")
    57     0, 0, 0, 0, // file size
    57     0, 0, 0, 0,     // file size
    58     0, 0, 0, 0, // reserved
    58     0, 0, 0, 0,     // reserved
    59     54, 0, 0, 0, // starting offset
    59     54, 0, 0, 0,    // starting offset
    60     40, 0, 0, 0, // header size
    60     40, 0, 0, 0,    // header size
    61     0, 0, 0, 0, // width
    61     0, 0, 0, 0,     // width
    62     0, 0, 0, 0, // height
    62     0, 0, 0, 0,     // height
    63     1, 0, // color planes
    63     1, 0,           // color planes
    64     24, 0, // bit depth
    64     32, 0,          // bit depth
    65     0, 0, 0, 0, // compression method (uncompressed)
    65     0, 0, 0, 0,     // compression method (uncompressed)
    66     0, 0, 0, 0, // image size
    66     0, 0, 0, 0,     // image size
    67     96, 0, 0, 0, // horizontal resolution
    67     96, 0, 0, 0,    // horizontal resolution
    68     96, 0, 0, 0, // vertical resolution
    68     96, 0, 0, 0,    // vertical resolution
    69     0, 0, 0, 0, // number of colors (all)
    69     0, 0, 0, 0,     // number of colors (all)
    70     0, 0, 0, 0 // number of important colors
    70     0, 0, 0, 0      // number of important colors
    71     );
    71     );
    72 begin
    72 begin
    73 // flash
    73 // flash
    74 ScreenFade:= sfFromWhite;
    74 ScreenFade:= sfFromWhite;
    75 ScreenFadeValue:= sfMax;
    75 ScreenFadeValue:= sfMax;
    76 ScreenFadeSpeed:= 5;
    76 ScreenFadeSpeed:= 5;
    77 
    77 
    78 size:= toPowerOf2(cScreenWidth) * toPowerOf2(cScreenHeight) * 3;
    78 size:= toPowerOf2(cScreenWidth) * toPowerOf2(cScreenHeight) * 4;
    79 p:= GetMem(size);
    79 p:= GetMem(size);
    80 
    80 
    81 // memory could not be allocated
    81 // memory could not be allocated
    82 if p = nil then
    82 if p = nil then
    83 begin
    83 begin
    84     AddFileLog('Error: Could not allocate memory for screenshot.');
    84     AddFileLog('Error: Could not allocate memory for screenshot.');
    85     exit(false);
    85     exit(false);
    86 end;
    86 end;
    87 
    87 
    88 // update header information and file name
    88 // update header information and file name
    89 
       
    90 filename:= UserPathPrefix + '/Screenshots/' + filename + '.bmp';
    89 filename:= UserPathPrefix + '/Screenshots/' + filename + '.bmp';
    91 
    90 
    92 head[$02]:= (size + 54) and $ff;
    91 head[$02]:= (size + 54) and $ff;
    93 head[$03]:= ((size + 54) shr 8) and $ff;
    92 head[$03]:= ((size + 54) shr 8) and $ff;
    94 head[$04]:= ((size + 54) shr 16) and $ff;
    93 head[$04]:= ((size + 54) shr 16) and $ff;
   104 head[$22]:= size and $ff;
   103 head[$22]:= size and $ff;
   105 head[$23]:= (size shr 8) and $ff;
   104 head[$23]:= (size shr 8) and $ff;
   106 head[$24]:= (size shr 16) and $ff;
   105 head[$24]:= (size shr 16) and $ff;
   107 head[$25]:= (size shr 24) and $ff;
   106 head[$25]:= (size shr 24) and $ff;
   108 
   107 
   109 //remember that opengles operates on a single surface, so GL_FRONT *should* be implied
   108 // read pixel from the front buffer
   110 //glReadBuffer(GL_FRONT);
   109 glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_BGRA, GL_UNSIGNED_BYTE, p);
   111 glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_BGR, GL_UNSIGNED_BYTE, p);
       
   112 
   110 
   113 {$IOCHECKS OFF}
   111 {$IOCHECKS OFF}
   114 Assign(f, filename);
   112 Assign(f, filename);
   115 Rewrite(f, 1);
   113 Rewrite(f, 1);
   116 if IOResult = 0 then
   114 if IOResult = 0 then
   126     success:= false;
   124     success:= false;
   127     end;
   125     end;
   128 {$IOCHECKS ON}
   126 {$IOCHECKS ON}
   129 
   127 
   130 FreeMem(p, size);
   128 FreeMem(p, size);
   131 
       
   132 MakeScreenshot:= success;
   129 MakeScreenshot:= success;
   133 end;
   130 end;
   134 
   131 
   135 // http://www.idevgames.com/forums/thread-5602-post-21860.html#pid21860
   132 // http://www.idevgames.com/forums/thread-5602-post-21860.html#pid21860
   136 function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
   133 function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;