Solved

Take screenshot while in fullscreen opengl game

Posted on 2010-11-14
9
1,662 Views
Last Modified: 2012-05-10
I'm using this standard screenshot function. It get's the image fine when the game is in windowed mode, but just gives me a gray image when in fullscreen. How do I get the game image while in fullscreen?

procedure ScreenShot(destBitmap : TBitmap) ;
 var
    w,h : integer;
    DC : HDC;
    hWin : Cardinal;
 begin
      hWin := GetForegroundWindow;
      dc := GetDC(hWin) ;
      w := 1 ;
      h := 1 ;

    try
     destBitmap.Width := w;
     destBitmap.Height := h;
     BitBlt(destBitmap.Canvas.Handle,
            0,
            0,
            destBitmap.Width,
            destBitmap.Height,
            DC,
            X,
            Y,
            SRCCOPY) ;
    finally
     ReleaseDC(hWin, DC) ;
    end;
 end; 

Open in new window

0
Comment
Question by:Grant1842
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 24

Accepted Solution

by:
jimyX earned 200 total points
ID: 34133439
I have tried this successfully:

http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_25147197.html


procedure ScreenShot(Bild: TBitMap);
var
  c: TCanvas;
  r: TRect;
begin
  c := TCanvas.Create;
  c.Handle := GetWindowDC(GetDesktopWindow);
  try
    r := Rect(0, 0, Screen.Width, Screen.Height);
    Bild.Width := Screen.Width;
    Bild.Height := Screen.Height;
    Bild.Canvas.CopyRect(r, c, r);
  finally
    ReleaseDC(0, c.Handle);
    c.Free;
  end;
end;

Open in new window

0
 
LVL 19

Assisted Solution

by:Thommy
Thommy earned 100 total points
ID: 34134945
Check the below link for infos how to take screenshots from active window and full screen...

How to take a screenshot of the Active Window in Delphi?
http://stackoverflow.com/questions/661250/how-to-take-a-screenshot-of-the-active-window-in-delphi
0
 
LVL 12

Author Comment

by:Grant1842
ID: 34157140
Hey guys no go on full screen still get grey image.
Its quake live www.quakelive.com if that will help you.
0
 
LVL 24

Expert Comment

by:jimyX
ID: 34157861
Could you attach image sample please.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 32

Assisted Solution

by:ewangoya
ewangoya earned 200 total points
ID: 34182236

Try this

uses
  DirectDraw;

procedure ScreenShot(ABitmap: TBitmap);
var
  DDSCaps: TDDSCaps;
  DesktopDC: HDC;
  DirectDraw: IDirectDraw;
  Surface: IDirectDrawSurface;
  SurfaceDesc: TDDSurfaceDesc;
begin
  if DirectDrawCreate(nil, DirectDraw, nil) = DD_OK then
    if DirectDraw.SetCooperativeLevel(GetDesktopWindow, DDSCL_EXCLUSIVE or
       DDSCL_FULLSCREEN or DDSCL_ALLOWREBOOT) = DD_OK then
    begin
      FillChar(SurfaceDesc, SizeOf(SurfaceDesc), 0);
      SurfaceDesc.dwSize := Sizeof(SurfaceDesc);
      SurfaceDesc.dwFlags := DDSD_CAPS or DDSD_BACKBUFFERCOUNT;
      SurfaceDesc.ddsCaps.dwCaps := DDSCAPS_PRIMARYSURFACE or DDSCAPS_FLIP or DDSCAPS_COMPLEX;
      SurfaceDesc.dwBackBufferCount := 1;
      if DirectDraw.CreateSurface(SurfaceDesc, Surface, nil) = DD_OK then
      begin
        if Surface.GetDC(DesktopDC) = DD_OK then
        try
          ABitmap.Width := Screen.Width;
          ABitmap.Height := Screen.Height;
          BitBlt(ABitmap.Canvas.Handle, 0, 0, Screen.Width, Screen.Height, DesktopDC, 0, 0, SRCCOPY);
        finally
          Surface.ReleaseDC(DesktopDC);
        end;
      end;
  end;
end;

0
 
LVL 12

Author Comment

by:Grant1842
ID: 34200440
@ewangoya that method is rather slow.  I'm trying to get enough screenshots to record video.
0
 
LVL 12

Author Comment

by:Grant1842
ID: 34200571
It works in fullscreen but is just a little too slow to use.
0
 
LVL 32

Expert Comment

by:ewangoya
ID: 34213967
I removed the back buffer and flipping, this should be faster

The BitBlt function tends to be slow and is the culprit here
procedure ScreenShot(ABitmap: TBitmap);

var

  DDSCaps: TDDSCaps;

  DesktopDC: HDC;

  DirectDraw: IDirectDraw;

  Surface: IDirectDrawSurface;

  SurfaceDesc: TDDSurfaceDesc;

begin

  if DirectDrawCreate(nil, DirectDraw, nil) = DD_OK then

    if DirectDraw.SetCooperativeLevel(GetDesktopWindow, DDSCL_EXCLUSIVE or

       DDSCL_FULLSCREEN or DDSCL_ALLOWREBOOT) = DD_OK then

    begin

      FillChar(SurfaceDesc, SizeOf(SurfaceDesc), 0);

      SurfaceDesc.dwSize := Sizeof(SurfaceDesc);

      SurfaceDesc.dwFlags := DDSD_CAPS;

      SurfaceDesc.ddsCaps.dwCaps := DDSCAPS_PRIMARYSURFACE;

      SurfaceDesc.dwBackBufferCount := 0;

      if DirectDraw.CreateSurface(SurfaceDesc, Surface, nil) = DD_OK then

      begin

        if Surface.GetDC(DesktopDC) = DD_OK then

        try

          ABitmap.Width := Screen.Width;

          ABitmap.Height := Screen.Height;

          BitBlt(ABitmap.Canvas.Handle, 0, 0, Screen.Width, Screen.Height, DesktopDC, 0, 0, SRCCOPY);

        finally

          Surface.ReleaseDC(DesktopDC);

        end;

      end;

  end;

end;

Open in new window

0
 
LVL 12

Author Closing Comment

by:Grant1842
ID: 34388515
thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now