Page 3 of 3 FirstFirst 123
Results 21 to 24 of 24

Thread: This is easiest way to make screenshoots of your game.

  1. #21
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Re: This is easiest way to make screenshoots of your game.

    I've been trying to make your code support PNG. Well, let me tell you. It's pretty much it's own function altogether.

    Here is the documentation I've been using: http://www.libpng.org/pub/png/spec/1...-Contents.html

    I've got a little CRC function to handle calculating CRC for each chunk. The only thing I'm stuck on is how to encode the IDAT chunk data. I'm not 100% sure, but I believe that I have to drop in 1 byte before each scanline of image data specifying it's filter method. THEN I take that data and lzh encode it and then do my CRC then store it. *whew* This format doesn't mess around.

    Can someone let me know if I'm on the right track or at least point me in the right direction. Considering that I'm using JEDI-SDL and OpenGL I'm trying to think of how I'm going to do the compression now.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  2. #22

    Re: This is easiest way to make screenshoots of your game.

    Are you using compression or just store uncompressed pngs?
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  3. #23
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Re: This is easiest way to make screenshoots of your game.

    Quote Originally Posted by Delfi
    Are you using compression or just store uncompressed pngs?
    Well I'd opt to doing them uncompressed just to get it working then add compression next to make my function practical for use in my projects.
    Jason McMillen
    Pascal Game Development
    Co-Founder





  4. #24

    Re: This is easiest way to make screenshoots of your game.

    If it helps, I have some code that creates uncompressed .tga files from a buffer in memory...

    It expects a image pixel buffer in bgr format like so as default

    Code:
    TSomeBuffer = packed record
      b,g,r : Byte;
    End;
    but you can use the ASwapPixels param to use r,g,b instead.

    You can also make it output the pixel rows in reverse (AFlipVertically) if you need to, if the image ends upside down.

    [pascal]Unit tga_unit;
    {$IFDEF fpc}
    {$MODE Delphi}
    {$ENDIF}
    {$H+}
    Interface

    Type
    PByteArray = ^TByteArray;

    Function WriteTGA(Const AFileName : AnsiString;
    Const AImageWidth,AImageHeight : Integer;
    Const AImageBuffer : PByteArray;
    Const ASwapPixels : Boolean;
    Const AFlipVertically : Boolean) : Boolean;

    implementation

    Uses
    Classes;

    Function WriteTGA(Const AFileName : AnsiString;
    Const AImageWidth,AImageHeight : Integer;
    Const AImageBuffer : PByteArray;
    Const ASwapPixels : Boolean;
    Const AFlipVertically : Boolean) : Boolean;
    Const
    TGAHeader : Packed Array[0..12 - 1] Of Byte = (0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0);

    Var
    TGAFile : TFileStream;
    Header : Packed Array[0..6 - 1] Of Byte;
    Bits : Byte;
    ColorMode : Integer;
    TempColor : Byte;
    index : Integer;
    Row : Integer;
    Begin
    // Open file for output.
    TGAFile := TFileStream.Create(AFileName,fmCreate);

    // Set the color mode, and the bit depth.
    ColorMode := 3;
    Bits := 24;

    Header[0] := AImageWidth Mod 256;
    Header[1] := AImageWidth Div 256;
    Header[2] := AImageHeight Mod 256;
    Header[3] := AImageHeight Div 256;
    Header[4] := Bits;
    Header[5] := 0;

    TGAFile.Write(TGAHeader,SizeOf(tgaHeader));
    TGAFile.Write(Header ,SizeOf(Header));

    If ASwapPixels Then
    Begin
    // Now switch image from RGB to BGR.
    index := 0;
    While index < (AImageWidth * AImageHeight * ColorMode) Do
    Begin
    TempColor := AImageBuffer^[index + 0];
    AImageBuffer^[index + 0] := AImageBuffer^[index + 2];
    AImageBuffer^[index + 2] := TempColor;
    Inc(index,ColorMode);
    End;
    End;

    // Finally write the image.
    If Not AFlipVertically Then
    TGAFile.Write(AImageBuffer^,AImageWidth * AImageHeight * ColorMode)
    Else
    // Write pixels in reverse row order
    Begin
    For Row := AImageHeight - 1 Downto 0 Do
    TGAFile.Write(AImageBuffer^[Row * AImageWidth * ColorMode],AImageWidth * ColorMode);
    End;

    If ASwapPixels Then
    Begin
    // Now switch image from BGR back to RGB.
    index := 0;
    While index < (AImageWidth * AImageHeight * ColorMode) Do
    Begin
    TempColor := AImageBuffer^[index + 0];
    AImageBuffer^[index + 0] := AImageBuffer^[index + 2];
    AImageBuffer^[index + 2] := TempColor;
    Inc(index,ColorMode);
    End;
    End;

    // close the file.
    TGAFile.Free;
    Result := True;
    End;

    end.
    [/pascal]

    cheers,
    Paul

Page 3 of 3 FirstFirst 123

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •