0

Possible Duplicate:
How Take screenshot opengl game ? for Delphi

I need help.I need take screenshot fullscreen opengl game delphi sources.

1
  • 3
    Have you checked the link I've posted to your previous question ?
    – TLama
    Mar 19, 2012 at 9:53

1 Answer 1

2

here's something I've cooked up, you haven't specified the Delphi version, so this is wrote in D2010, unfortunately the only game I have is counter-strike 1.6, and the result is a black image, but I'm pretty sure you can work your way from here(it's a rush job, but I haven't much time), so here's the code:

function TakeGameShot(const AFileName: string; const AWidth, AHeight: Integer): Boolean;
var
  LPixels: array of Byte;
  LLine: PByteArray;
  LBitmap: TBitmap;
  Index: Integer;
begin
  Result := False;
  LBitmap := TBitmap.Create;
  try
    LBitmap.PixelFormat := pf24bit;
    LBitmap.Height := AHeight;
    LBitmap.Width := AWidth;

    //  width * height * 3 bytes/pixel
    SetLength(LPixels, AWidth * AHeight * 3);

    //  tell open gl which buffer we're interested in
    glReadBuffer(GL_BACK);
    //  read pixels
    glReadPixels(0, 0, AWidth, AHeight, GL_RGB, GL_UNSIGNED_BYTE, @LPixels);
    //  scan each line from bitmap
    for Index := 0 to AHeight -1 do begin
      LLine := LBitmap.ScanLine[ Index ];
      //  move data from LPixels to LLine, data size = Width * 3(bytes/pixel)
      Move(LPixels[ Index * AWidth ], LLine^[0], AWidth * 3);
    end; // for Index := 0 to AHeight -1 do begin
    //  save the bitmap
    LBitmap.SaveToFile(AFileName);
    //  if we reached this line, we're pretty much OK
    Result := True;
  finally
    LBitmap.Free;
  end;
end;

Not the answer you're looking for? Browse other questions tagged or ask your own question.