17. Screenshots

Making a screenshot is very easy:

procedure TakeScreenshot;
var
  Image: TRGBImage;
begin
  Image := Control.SaveScreen;
  try
    SaveImage(Image, 'screenshot_name.png');
  finally FreeAndNil(Image) end;
end;
 
// Call TakeScreenshot
// from wherever you want in your game.
// For example, from the OnPress event.

TRGBImage, and it's ancestor TCastleImage and many other similar classes, are defined in the unit CastleImages. This unit provides various image loading, saving and processing utilities to our engine.

Note: we have our own image handling unit, to store images in the format best suitable for 3D graphics libraries, like OpenGL. This gives us some capabilities not found in common image libraries, for example we seamlessly handle S3TC compressed images (class TS3TCImage), 3D textures and float textures. Still, we use the excellent FPC FpImage library to load/save some image formats underneath.