Solved

Take screenshot while in fullscreen opengl game

Posted on 2010-11-14
9
1,692 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 24

Expert Comment

by:jimyX
ID: 34157861
Could you attach image sample please.
0
 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

786 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