hedgewars/uMisc.pas
changeset 6990 40e5af28d026
parent 6952 7f70f37bbf08
child 6992 b8f3d8991e92
equal deleted inserted replaced
6989:4c35e9cf6057 6990:40e5af28d026
    21 unit uMisc;
    21 unit uMisc;
    22 interface
    22 interface
    23 
    23 
    24 uses SDLh, uConsts, GLunit, uTypes;
    24 uses SDLh, uConsts, GLunit, uTypes;
    25 
    25 
       
    26 procedure initModule;
       
    27 procedure freeModule;
       
    28 
    26 procedure movecursor(dx, dy: LongInt);
    29 procedure movecursor(dx, dy: LongInt);
    27 function  doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
    30 function  doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
    28 function  MakeScreenshot(filename: shortstring): boolean;
    31 function  MakeScreenshot(filename: shortstring): boolean;
    29 function  GetTeamStatString(p: PTeam): shortstring;
    32 function  GetTeamStatString(p: PTeam): shortstring;
    30 {$IFDEF SDL13}
    33 {$IFDEF SDL13}
    31 function SDL_RectMake(x, y, width, height: LongInt): TSDL_Rect;
    34 function SDL_RectMake(x, y, width, height: LongInt): TSDL_Rect;
    32 {$ELSE}
    35 {$ELSE}
    33 function SDL_RectMake(x, y: SmallInt; width, height: Word): TSDL_Rect;
    36 function SDL_RectMake(x, y: SmallInt; width, height: Word): TSDL_Rect;
    34 {$ENDIF}
    37 {$ENDIF}
    35 procedure initModule;
       
    36 procedure freeModule;
       
    37 
    38 
    38 implementation
    39 implementation
    39 uses typinfo, sysutils, uVariables, uUtils
    40 uses typinfo, sysutils, uVariables, uUtils
    40      {$IFDEF PNG_SCREENSHOTS}, PNGh, png {$ENDIF}
    41      {$IFDEF PNG_SCREENSHOTS}, PNGh, png {$ENDIF}
    41      {$IFNDEF USE_SDLTHREADS} {$IFDEF UNIX}, cthreads{$ENDIF} {$ENDIF};
    42      {$IFNDEF USE_SDLTHREADS} {$IFDEF UNIX}, cthreads{$ENDIF} {$ENDIF};
    72 
    73 
    73 png_ptr := png_create_write_struct(png_get_libpng_ver(nil), nil, nil, nil);
    74 png_ptr := png_create_write_struct(png_get_libpng_ver(nil), nil, nil, nil);
    74 if png_ptr = nil then
    75 if png_ptr = nil then
    75 begin
    76 begin
    76     // AddFileLog('Error: Could not create png write struct.');
    77     // AddFileLog('Error: Could not create png write struct.');
    77     exit(0);
    78     SaveScreenshot:= 0;
       
    79     exit;
    78 end;
    80 end;
    79 
    81 
    80 info_ptr := png_create_info_struct(png_ptr);
    82 info_ptr := png_create_info_struct(png_ptr);
    81 if info_ptr = nil then
    83 if info_ptr = nil then
    82 begin
    84 begin
    83     png_destroy_write_struct(@png_ptr, nil);
    85     png_destroy_write_struct(@png_ptr, nil);
    84     // AddFileLog('Error: Could not create png info struct.');
    86     // AddFileLog('Error: Could not create png info struct.');
    85     exit(0);
    87     SaveScreenshot:= 0;
       
    88     exit;
    86 end;
    89 end;
    87 
    90 
    88 {$IOCHECKS OFF}
    91 {$IOCHECKS OFF}
    89 Assign(f, image^.filename);
    92 Assign(f, image^.filename);
    90 Rewrite(f, 1);
    93 Rewrite(f, 1);
   207 
   210 
   208 // memory could not be allocated
   211 // memory could not be allocated
   209 if p = nil then
   212 if p = nil then
   210 begin
   213 begin
   211     AddFileLog('Error: Could not allocate memory for screenshot.');
   214     AddFileLog('Error: Could not allocate memory for screenshot.');
   212     exit(false);
   215     MakeScreenshot:= false;
       
   216     exit;
   213 end;
   217 end;
   214 
   218 
   215 // read pixel from the front buffer
   219 // read pixel from the front buffer
   216 glReadPixels(0, 0, cScreenWidth, cScreenHeight, format, GL_UNSIGNED_BYTE, p);
   220 glReadPixels(0, 0, cScreenWidth, cScreenHeight, format, GL_UNSIGNED_BYTE, p);
   217 
   221 
   233 
   237 
   234 // http://www.idevgames.com/forums/thread-5602-post-21860.html#pid21860
   238 // http://www.idevgames.com/forums/thread-5602-post-21860.html#pid21860
   235 function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
   239 function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface;
   236 var convertedSurf: PSDL_Surface;
   240 var convertedSurf: PSDL_Surface;
   237 begin
   241 begin
       
   242     doSurfaceConversion:= tmpsurf;
   238     if ((tmpsurf^.format^.bitsperpixel = 32) and (tmpsurf^.format^.rshift > tmpsurf^.format^.bshift)) or
   243     if ((tmpsurf^.format^.bitsperpixel = 32) and (tmpsurf^.format^.rshift > tmpsurf^.format^.bshift)) or
   239        (tmpsurf^.format^.bitsperpixel = 24) then
   244        (tmpsurf^.format^.bitsperpixel = 24) then
   240         begin
   245         begin
   241         convertedSurf:= SDL_ConvertSurface(tmpsurf, conversionFormat, SDL_SWSURFACE);
   246         convertedSurf:= SDL_ConvertSurface(tmpsurf, conversionFormat, SDL_SWSURFACE);
   242         SDL_FreeSurface(tmpsurf);
   247         SDL_FreeSurface(tmpsurf);
   243         exit(convertedSurf);
   248         doSurfaceConversion:= convertedSurf;
   244         end;
   249         end;
   245 
       
   246     exit(tmpsurf);
       
   247 end;
   250 end;
   248 
   251 
   249 {$IFDEF SDL13}
   252 {$IFDEF SDL13}
   250 function SDL_RectMake(x, y, width, height: LongInt): TSDL_Rect;
   253 function SDL_RectMake(x, y, width, height: LongInt): TSDL_Rect;
   251 {$ELSE}
   254 {$ELSE}