XNA Creators Club Online
Page 1 of 2 (29 items) 1 2 Next >
Sort Posts: Previous Next

Capture the screen

Last post 05-30-2008 5:36 AM by getviewsnow. 28 replies.
  • 04-24-2008 1:38 PM

    Capture the screen

    Hello,

    Do you guys have any idea how to capture the screen in DX9 and save to file? Any not-so-complicated tutorial?

    Thanks in advance,

    Jan
  • 04-24-2008 1:42 PM In reply to

    Re: Capture the screen

    In code or with a tool?

    For a tool use Fraps or HyperCam



    The ZBuffer News and information for XNA

    Please read the forum FAQs - Bug reporting
  • 04-24-2008 1:59 PM In reply to

    Re: Capture the screen

    Lets say I have simple DirectX 9 application.
    I have the "Capture screen" button in it, and when its pressed I wanna the current frame being captured and stored into a file.

    How could I do that (yes, code).
  • 04-24-2008 2:01 PM In reply to

    Re: Capture the screen

  • 04-24-2008 2:13 PM In reply to

    Re: Capture the screen

    Thank you

  • 04-25-2008 11:06 AM In reply to

    Re: Capture the screen

    Hello guys,

    I have a little problem.
    I have:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    HRESULT makeScreenshot()
    {
      
    HRESULT hr = S_OK;
    LPDIRECT3DSURFACE9 frontBuffer;
    int x, y;

      x = 800;
      y = 600;

    if( FAILED( hr = pd3dDevice->CreateOffscreenPlainSurface(x, y, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &frontBuffer, NULL)))
    return hr;

    if( FAILED( hr = pd3dDevice->GetFrontBufferData(NULL, frontBuffer)))
    {
    frontBuffer->Release();
    return hr;
    }

    D3DXSaveSurfaceToFile(L"Screenshot1.bmp", D3DXIFF_BMP, frontBuffer, NULL, NULL);

    // D3DXSaveSurfaceToFile(L"Screenshot1.jpg", D3DXIFF_JPG, frontbuf, NULL, &rcWindow);

    frontBuffer->Release();

    return hr;
    }
    Compiles well, but when I call the function, the application crushes.

    I get:
    Unhandled exception at 0x0042c6b6 in application.exe: 0xC0000005: Access violation reading location 0x00000000.

    And, this line is marked.
     if( FAILED( hr = pd3dDevice->CreateOffscreenPlainSurface(x, y, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &frontBuffer, NULL)))

    What am I missing?
  • 04-30-2008 11:20 AM In reply to

    Re: Capture the screen

    Seems like your pd3dDevice pointer is null.
    Wessam Bahnassi
    Microsoft DirectX MVP
  • 04-30-2008 12:37 PM In reply to

    Re: Capture the screen

    Yeah, I've realized that. How do prepare it for creating plain surface?
  • 04-30-2008 4:08 PM In reply to

    Re: Capture the screen

    This pointer should be initialized to the actual D3D device you're using to render your scenes. You cannot render anything without a valid device object. For example, I suggest you try to find the variable you're calling Present() on, and using that for your screen capture code.
    Wessam Bahnassi
    Microsoft DirectX MVP
  • 05-01-2008 3:27 AM In reply to

    Re: Capture the screen

    I don't really have Preset() since I'm playing around DXUT.

    And D3D Device I use for rendering screnes is the same device that is "NULL".

        V_RETURN( loadMesh( pd3dDevice, g_Model1, &g_pModelMesh ) );
    or
     V_RETURN( D3DXCreateSprite( pd3dDevice, &g_pSprite ) );

    Forgot to mention, I also tried with setting up pd3dDevice here:
    HRESULT makeScreenshot(IDirect3DDevice9* pd3dDevice)
  • 05-01-2008 4:16 AM In reply to

    Re: Capture the screen

    If you are using DXUT, then you can easily obtain a pointer to the active device via DXUTGetD3D9Device():

    IDirect3DDevice9 *pDevice = DXUTGetD3D9Device();
    Wessam Bahnassi
    Microsoft DirectX MVP
  • 05-01-2008 4:34 AM In reply to

    Re: Capture the screen

    Well, I added IDirect3DDevice9 *pd3dDevice = DXUTGetD3D9Device(); , but pd3dDevice seems to be still NULL.
  • 05-01-2008 1:04 PM In reply to

    Re: Capture the screen

    That would imply that you are calling DXUTGetD3D9Device() before the device has been created.