Solved

Take screenshot while in fullscreen opengl game

Posted on 2010-11-14
9
1,730 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 24

Expert Comment

by:jimyX
ID: 34157861
Could you attach image sample please.
0
 
LVL 32

Assisted Solution

by:Ephraim Wangoya
Ephraim Wangoya 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:Ephraim Wangoya
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

690 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