Skip to main content
GameDev.net gamedev.net
🔒 Locked

Dumb GetFrontBufferData()

Started by Ademan555 Mar 8, 2004 at 12:17 AM 7 replies 8.9k views
Original Post
Ademan555
Ademan555
Alright... so i wanna take a screenshot, ive created my surface and all that good sheite... but then... i see thise dumb "swap chain" param smack dab in the way of me taking screenshots, i know it has SOMETHING to do with the back buffers, but i dont know anything about it, the function ALWAYS fails when i set it to 0, ive also tried 1 (i have 1 back buffer) i dunno what i should be doin... -Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out hi
eFoDay
eFoDay
here is the code I use to take a screen shot
I want to implement a system for taking multiple screen shots automatically


void CDirect3D::TakeScreenShot(LPCTSTR pDestFile)
{
D3DDISPLAYMODE displayMode;

LPDIRECT3DSURFACE9 pd3dsFront = NULL;

// Get the display mode

m_pd3dDevice->GetDisplayMode(0, &displayMode);

// Create a surface to hold the front buffer

m_pd3dDevice->CreateOffscreenPlainSurface(displayMode.Width, displayMode.Height,
D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &pd3dsFront, NULL);

// Get the front buffer and save it to a file

if( SUCCEEDED( m_pd3dDevice->GetFrontBufferData(0, pd3dsFront) ) )
D3DXSaveSurfaceToFile(pDestFile, D3DXIFF_BMP, pd3dsFront, NULL, NULL);

// Release the surface

if( pd3dsFront ) pd3dsFront->Release();
}


[edited by - eFoDay on March 8, 2004 1:48:41 AM]
Ademan555
Ademan555
heres wut im usin (the PresentParameters is already a member of the class)


bool ID3D::TakeScreenshot(char * FilePath)
{
HRESULT hr;
LPDIRECT3DSURFACE9 pFrontBuff;
hr = pDev->CreateOffscreenPlainSurface(PresentParameters.BackBufferWidth, PresentParameters.BackBufferHeight, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &(pFrontBuff), NULL);

if (FAILED(hr))
{
OutputDebugString("Couldn''t Make the Front Buffer\n");
return FALSE;
}

hr = pDev->GetFrontBufferData(0, pFrontBuff);

if (FAILED(hr))
{
OutputDebugString("Couldn''t Grab the front Buffer\n");
return FALSE;
}

hr = D3DXSaveSurfaceToFile(FilePath, D3DXIFF_BMP, pFrontBuff, NULL, NULL);

if (FAILED(hr))
{
OutputDebugString("Couldn''t Save Screenie\n");
return FALSE;
}

return TRUE;
}

-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out hi
eFoDay
eFoDay
what error do you get?
also your not releasing the surface you created
Ademan555
Ademan555
I know im not releasing it... its not the point right now though... i get the... 0x8876086c error... i think thats invalid call.... im gonna look it up

yup, the error lookup said this:

HRESULT: 0x8876086c (2289436780)
Name: D3DERR_INVALIDCALL
Description: Invalid call
Severity code: Failed
Facility Code: FACILITY_D3D (2166)
Error Code: 0x086c (2156)


-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out hi
don
don
The swap chain parameter is the display adapter number. IDirect3DDevice9::GetFrontBufferData will only get a copy of the front buffers created as part of the implicit swap chain created by CreateDevice. If you''re creating the swap chain using CreateAdditionalSwapChain, you''ll have to use IDirect3DSwapChain9::GetFrontBufferData instead.

Also, you didn''t mention whether you''re in windowed or fullscreen mode. Since you''re using the back buffer width and height, that might not match the size of the display, which is what GetFrontBufferData expects.

Does the debug runtime not report more information when this function fails?

Ademan555
Ademan555
I am in windowed mode... ill try fullscreen.... but as far as the debug runtime... i tried it, it didnt do anything... of course i was using d3dx9dt.lib not just d3dx9d.lib because for whatever reason, d3dx9d.lib gives me a wierd error at runtime...
edit: it does work in fullscreen yAy... but i hafta ask... would the GetDisplayMode() return something different if, it was in windowed mode? (because the window is smaller than the 640x480 that i wanted the resolution to be at)
-Dan

[edited by - Ademan555 on March 8, 2004 8:14:59 PM]
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out hi
don
don
In windowed mode, the size of your back buffer is usually the client area of the window. Since your code is using the back buffer width and height, rather than the front buffer width and height, GetFrontBufferData is failing.

Read the SDK docs, in windowed mode, you must provide a surface to GetFrontBufferData that is the same size as the desktop.

In windowed mode, you don''t set the display mode when you create the device obviously, so GetDisplayMode returns whatever the current Windows desktop display mode is. In fullscreen mode, you must specify the mode when you create the device (front buffer format/width/height must be the same as back buffer) so GetDisplayMode is going to reflect whatever you''ve set it to.

BTW, when I say use the debug runtime, that has nothing to do with D3DX''s various flavors of DLLs. I''m talking about going into the DirectX applet in Control Panel and selecting "Use Debug Version of Direct3D", moving the "Debug Output Level" slider to "More", and clicking the "Maximum Validation" checkbox.
If you were to do this, you would see the following in the debugger when GetFrontBufferData fails in windowed mode when you pass in a surface that is the back buffer width/height instead of the width and height of the desktop:

Direct3D9: (ERROR) :Destination surface not big enough to hold the size of the screen. GetFrontBufferData fails.

eFoDay
eFoDay
if you use the code I posted before it will take screen shots in both fullscreen and windowed mode. in windowed mode it will save everything including the desktop.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.