Directx 8 Screen Capture

Just starting out? Need help? Post your questions and find answers here.
Effigy
User
User
Posts: 35
Joined: Fri Apr 25, 2003 5:40 pm
Location: Canada
Contact:

Directx 8 Screen Capture

Post by Effigy »

Hello all... I have been working on a screen capture program, but I'm having some issues with the GDI method of Capturing the screen. Basically it's too slow. ABout 50MS to get the screen from memory.

I have heard the Directx Method of capturing is much faster, the problem is I'm no Direct X Guru.

This method uses the getfrontbuffer() method to get the videobuffer to memory.

Here is some code I found on the net.

Code: Select all

 Public Sub SaveScreenShot(ByVal sFilename As String)
    Dim oSurface As Direct3DSurface8
    Dim SrcPalette As PALETTEENTRY
    Dim SrcRect As RECT
    Dim DispMode As D3DDISPLAYMODE

    'get display dimensions
    g_oDevice.GetDisplayMode DispMode

    'create a surface to put front buffer on,
    'GetFrontBuffer always returns D3DFMT_A8R8G8B8
    Set oSurface = g_oDevice.CreateImageSurface(DispMode.Width, _
            DispMode.Height, _
            D3DFMT_A8R8G8B8)

    'get data from front buffer
    g_oDevice.GetFrontBuffer oSurface

    'we are saving entire area of this surface
    With SrcRect
        .Left = 0
        .Right = DispMode.Width
        .Top = 0
        .Bottom = DispMode.Height
    End With

    'save this surface to a BMP file
    g_oD3DX.SaveSurfaceToFile sFilename, _
            D3DXIFF_BMP, _
            oSurface, _
            SrcPalette, _
            SrcRect
End Sub
 
This would be patricularly useful for those people who want to get screen shots out of their Directx game. I think this Method Requires Directx 8.

I would appreciate any help any one could offer.
Derek Gavey
- PB Newbie -
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Re: Directx 8 Screen Capture

Post by traumatic »

This works for me (PB 4.0):

Code: Select all

;
; get the necessary includes here:
; http://www.purebasic.fr/english/viewtopic.php?t=16652
;
IncludePath "include"
IncludeFile "dx8.h.pb"


#D3DXIFF_BMP = 0



Import "d3d8.lib"
 Direct3DCreate8(a.l = #D3D_SDK_VERSION)
EndImport


;
; The library ('d3dx8.lib') supplied with PB needs the DLL 'd3dx8.dll' from
; which I somehow can't remember where I got it from, I think it was PellesC
;
; The recommended way is to use the static library that comes with the dx8-sdk,
; simply copy it over to your "/PureLibraries/Windows/Libraries" directory
;
; If you're running into "unresolved external symbols", uncomment the next line:
;Import "msvcrt.lib" : EndImport
;
; ###
; ### NOTE: this will only work with PB v4.0b8 and above, beta7 and lower will
; ###       complain about "multiply defined symbol __fltused"
; ###
;
Import "d3dx8.lib"
  D3DXSaveSurfaceToFileA(pDestFile.p-ascii, DestFormat.l, pSrcSurface.IDirect3DSurface8, *pSrcPalette.PALETTEENTRY,  *pSrcRect.RECT)
EndImport



;
;
;


hWnd = GetForegroundWindow_()  ; just to have a window handle for CreateDevice()
;
;
;
d3d.IDirect3D8 = Direct3DCreate8()


d3d\GetAdapterDisplayMode(#D3DADAPTER_DEFAULT, @ddm.D3DDISPLAYMODE)

d3dpp.D3DPRESENT_PARAMETERS
ZeroMemory_(@d3dpp, SizeOf(D3DPRESENT_PARAMETERS))

d3dpp\Windowed = #True
d3dpp\Flags = #D3DPRESENTFLAG_LOCKABLE_BACKBUFFER
d3dpp\BackBufferFormat = ddm\Format
d3dpp\BackBufferHeight = ddm\Height
d3dpp\BackBufferWidth = ddm\Width
d3dpp\MultiSampleType = #D3DMULTISAMPLE_NONE
d3dpp\SwapEffect = #D3DSWAPEFFECT_DISCARD
d3dpp\hDeviceWindow = hWnd
d3dpp\FullScreen_PresentationInterval = #D3DPRESENT_INTERVAL_DEFAULT
d3dpp\FullScreen_RefreshRateInHz = #D3DPRESENT_RATE_DEFAULT



If d3d\CreateDevice(#D3DADAPTER_DEFAULT, #D3DDEVTYPE_HAL, hWnd, #D3DCREATE_SOFTWARE_VERTEXPROCESSING , @d3dpp, @d3dDevice.IDirect3DDevice8) = #D3D_OK
  If d3dDevice\CreateImageSurface(ddm\Width, ddm\Height, #D3DFMT_A8R8G8B8, @surface.IDirect3DSurface8) = #D3D_OK
    If d3dDevice\GetFrontBuffer(surface) = #D3D_OK
      If D3DXSaveSurfaceToFileA("c:\filename.bmp", #D3DXIFF_BMP, surface, #Null, #Null) = #D3D_OK
        Debug "screenshot saved!"
      EndIf
    EndIf
  EndIf
EndIf
Good programmers don't comment their code. It was hard to write, should be hard to read.
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Re: Directx 8 Screen Capture

Post by traumatic »

Still alive, Effigy?
Good programmers don't comment their code. It was hard to write, should be hard to read.
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

I think Micro$oft kidnapped him because of trying to convert VB code to PB code. Damn Billy Gatez, always hunting money :lol:
Liqu
User
User
Posts: 77
Joined: Sun Apr 21, 2013 10:31 am

Re: Directx 8 Screen Capture

Post by Liqu »

Did someone got the d3dx8.lib?

i'm trying to get screenshot for directx games froms steam
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Directx 8 Screen Capture

Post by Danilo »

Liqu wrote:Did someone got the d3dx8.lib?
Did you download Microsoft DirectX Software Development Kit?

EDIT: DirectX SDKs of a certain age
The August 2007 DirectX SDK was the last version to include Direct3D 8 (d3d8.h d3d8caps.h d3d8types.h) and Direct3D 7 and prior (d3d.h d3dcaps.h d3dvec.inl d3dtypes.h).
- dxsdk_aug2007.exe
- dxsdk_aug2006.exe
Liqu
User
User
Posts: 77
Joined: Sun Apr 21, 2013 10:31 am

Re: Directx 8 Screen Capture

Post by Liqu »

i've downloaded these 2 :
- dxsdk_aug2007.exe
- dxsdk_aug2006.exe

but it didn't contain d3dx8.lib,

so i tried to use d3d9.lib and d3dx9.lib, but failed haha
how to upgrade it to use DirectX 9 / 10 / 11 / 12
Post Reply