Jump to content
  • Advertisement
Sign in to follow this  
Barina

Just want to take fullscreen capture.. somthing missing - please help

This topic is 2960 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi all

im trying to take a screenshot from a running DirectX 9 game via C# code and SlimDX
i have this code:


Direct3D direct3d = new SlimDX.Direct3D9.Direct3D();
AdapterInformation adapter = direct3d.Adapters.DefaultAdapter;

PresentParameters parameters = new SlimDX.Direct3D9.PresentParameters();
parameters.BackBufferFormat = adapter.CurrentDisplayMode.Format;
parameters.BackBufferHeight = adapter.CurrentDisplayMode.Height;
parameters.BackBufferWidth = adapter.CurrentDisplayMode.Width;
parameters.Multisample = SlimDX.Direct3D9.MultisampleType.None;
parameters.SwapEffect = SlimDX.Direct3D9.SwapEffect.Discard;
parameters.PresentationInterval = SlimDX.Direct3D9.PresentInterval.Default;
parameters.FullScreenRefreshRateInHertz = 0;


Device device = new Device(direct3d, adapter.Adapter, DeviceType.Hardware, parameters.DeviceWindowHandle, CreateFlags.SoftwareVertexProcessing, parameters);

Surface surface = Surface.CreateOffscreenPlain(device, adapter.CurrentDisplayMode.Width, adapter.CurrentDisplayMode.Height, Format.A8R8G8B8, Pool.SystemMemory);

device.GetFrontBufferData(0, surface);

Rectangle region = new Rectangle(0, 0, adapter.CurrentDisplayMode.Width, adapter.CurrentDisplayMode.Height);

bmp = new Bitmap(Surface.ToStream(surface, ImageFileFormat.Bmp, new Rectangle(region.Left, region.Top, region.Width, region.Height)));


which of course works great only on windowed games..
im really stuck here.. how do i take screens from a full screen games using that code?

thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
it works perfect on windowed games but when im maximize them to full screen i get a deviceLostException(or something like that)
i never payed attention to DPI..... i dont thinks it matter anyway?

Share this post


Link to post
Share on other sites
From the information you provided, I guess the problem is more likely in your transition code. Here are my suggestions.

1. Don't call GetFronBuffer(say by setting a flag) during the transition from windowed mode to full screen mode. what will happen? Different from D3D10 or above, during transition from windowed mode to full screen mode, D3D9 device must be reset/recreated. I wonder if your code is correct?

2. go to this site to download Direct SDK 2010

http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=2c7da5fb-ffbb-4af6-8c66-651cbd28ca15

there are many D3D9 samples which support the trasisition from windowed mode to full screen mode. Add your code for GetFrontBuffer to there, and see what will happen?

[Edited by - standby01 on September 2, 2010 8:22:49 PM]

Share this post


Link to post
Share on other sites
Here is a piece of code from DirectX SDK Feb 2010.

HRESULT WINAPI DXUTToggleFullScreen()
{
HRESULT hr;

// Get the current device settings and flip the windowed state then
// find the closest valid device settings with this change
DXUTDeviceSettings deviceSettings = DXUTGetDeviceSettings();
DXUTDeviceSettings orginalDeviceSettings = DXUTGetDeviceSettings();

// Togggle windowed/fullscreen bit
if( DXUTIsD3D9( &deviceSettings ) )
deviceSettings.d3d9.pp.Windowed = !deviceSettings.d3d9.pp.Windowed;
else
deviceSettings.d3d10.sd.Windowed = !deviceSettings.d3d10.sd.Windowed;

DXUTMatchOptions matchOptions;
matchOptions.eAPIVersion = DXUTMT_PRESERVE_INPUT;
matchOptions.eAdapterOrdinal = DXUTMT_PRESERVE_INPUT;
matchOptions.eDeviceType = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eWindowed = DXUTMT_PRESERVE_INPUT;
matchOptions.eAdapterFormat = DXUTMT_IGNORE_INPUT;
matchOptions.eVertexProcessing = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eBackBufferFormat = DXUTMT_IGNORE_INPUT;
matchOptions.eBackBufferCount = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eMultiSample = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eSwapEffect = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eDepthFormat = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eStencilFormat = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.ePresentFlags = DXUTMT_CLOSEST_TO_INPUT;
matchOptions.eRefreshRate = DXUTMT_IGNORE_INPUT;
matchOptions.ePresentInterval = DXUTMT_CLOSEST_TO_INPUT;

// Go back to previous state

BOOL bIsWindowed = DXUTGetIsWindowedFromDS( &deviceSettings );
UINT nWidth = ( bIsWindowed ) ? GetDXUTState().GetWindowBackBufferWidthAtModeChange() :
GetDXUTState().GetFullScreenBackBufferWidthAtModeChange();
UINT nHeight = ( bIsWindowed ) ? GetDXUTState().GetWindowBackBufferHeightAtModeChange() :
GetDXUTState().GetFullScreenBackBufferHeightAtModeChange();

if( nWidth > 0 && nHeight > 0 )
{
matchOptions.eResolution = DXUTMT_CLOSEST_TO_INPUT;
if( DXUTIsD3D9( &deviceSettings ) )
{
deviceSettings.d3d9.pp.BackBufferWidth = nWidth;
deviceSettings.d3d9.pp.BackBufferHeight = nHeight;
}
else
{
deviceSettings.d3d10.sd.BufferDesc.Width = nWidth;
deviceSettings.d3d10.sd.BufferDesc.Height = nHeight;
}
}
else
{
// No previous data, so just switch to defaults
matchOptions.eResolution = DXUTMT_IGNORE_INPUT;
}

hr = DXUTFindValidDeviceSettings( &deviceSettings, &deviceSettings, &matchOptions );
if( SUCCEEDED( hr ) )
{
// Create a Direct3D device using the new device settings.
// If there is an existing device, then it will either reset or recreate the scene.
hr = DXUTChangeDevice( &deviceSettings, NULL, NULL, false, false );

// If hr == E_ABORT, this means the app rejected the device settings in the ModifySettingsCallback so nothing changed
if( FAILED( hr ) && ( hr != E_ABORT ) )
{
// Failed creating device, try to switch back.
HRESULT hr2 = DXUTChangeDevice( &orginalDeviceSettings, NULL, NULL, false, false );
if( FAILED( hr2 ) )
{
// If this failed, then shutdown
DXUTShutdown();
}
}
}

return hr;
}

Calling GetFrontBuffer during transition could cause an exception.

Share this post


Link to post
Share on other sites
oh thanks a lot!
are there any C# solutions for that..?
i just finished learning C# and i have no background at all...
and i don't really know what to do with this..... :\

Share this post


Link to post
Share on other sites
download DirectX SDK 06/2006. There are many C# samples in this packet.

http://www.microsoft.com/downloads/details.aspx?FamilyId=C72D9F1E-53F3-4747-8490-6801D8E8B4EF&displaylang=en

Share this post


Link to post
Share on other sites
I forgot to mention, directly using C# for Game programing is not recommended. Instead you could consider to use XNA Game Studio, which is a programming environment that allows you to use Visual Studio to create games for Windows Phone, the Xbox 360 console, and Windows-based computers. XNA Game Studio includes the XNA Framework, which is a set of managed libraries designed for game development based on Microsoft .NET Framework 2.0. This documentation collection contains technology overviews, tutorials, and reference material related to XNA Game Studio.

download XNA Game Studio
http://creators.xna.com/en-US/downloads

Search XNA GameStudio on the web you can find some good books.

[Edited by - standby01 on September 7, 2010 5:27:10 PM]

Share this post


Link to post
Share on other sites
Barina already uses SlimDX which is probably the "best" way to access DirectX from a .NET language (Edit: on Windows platform).

To be of more help, I checked my screen-shot function and it seems to work in both full-screen and windowed mode. I do use the backbuffer though:

void SaveScreenShot()
{
Surface backbuffer = device.GetBackBuffer(0, 0);
Surface.ToFile(backbuffer, "screenshot.bmp", ImageFileFormat.Bmp);
backbuffer.Dispose();
}


Just make sure you do this after device.EndScene() and before device.Present(). Haven't checked for the other overload of Surface and a custom rectangle, but maybe this helps.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!