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

Screen Shot

Started by davidkosenina Apr 18, 2004 at 10:24 AM 5 replies 3.1k views
Original Post
davidkosenina
davidkosenina
Helo How can I do screenshot in DirectX9? D3DXSaveSurfaceToFile always returns invalid call and I am out of ideas. please help

HRESULT hr;
IDirect3DSurface9* screenshot; 
hr =  pDevice->CreateRenderTarget( 			 		
				oDirectX9.GetBackBufferWidth(),						oDirectX9.GetBackBufferHeight(),					oDirectX9.GetBackBufferFormat(),					D3DMULTISAMPLE_NONE,							0,
				false,									&screenshot,	
				NULL
									  );

hr = pDevice->GetRenderTarget( 						  		               0,				
 		                &screenshot							      );

hr = D3DXSaveSurfaceToFile( ".\\shot.bmp", D3DXIFF_BMP,  
                               screenshot, NULL, NULL );

SAFE_RELEASE( screenshot );

[\source]

davidkosenina
davidkosenina
again :-)



HRESULT hr;
IDirect3DSurface9* screenshot;

hr = pDevice->CreateRenderTarget(
oDirectX9.GetBackBufferWidth(),
oDirectX9.GetBackBufferHeight(),
oDirectX9.GetBackBufferFormat(),
D3DMULTISAMPLE_NONE,
0,
false,
&screenshot,
NULL
);


hr = pDevice->GetRenderTarget(
1,
&screenshot
);


hr = D3DXSaveSurfaceToFile( ".\\shot.bmp", D3DXIFF_BMP,
screenshot, NULL, NULL );

SAFE_RELEASE( screenshot );


bzroom
bzroom
Maybe another ".", I don't know anything about dx so thats my only guess. N/M I have a second guess, shouldn't you be allocating the surface somewhere? You declare it then you just start using it it looks like. Maybe the createrendertarget function is how you allocate it? What does is that function actualy doing?

Is this all the code in this area?

edit: hmm, your second post looks better, does it work now?

[edited by - honayboyz on April 18, 2004 11:33:39 AM]
DivineLight
DivineLight
Hey here''s a code which i found and works:


SaveScreenShot( char *fileName, _D3DXIMAGE_FILEFORMAT ImgFormat)
{
HRESULT hr;

//The front buffer used to get the screenshot
LPDIRECT3DSURFACE9 buffer = NULL;


// Create a surface for the screenshot to be rendered to
if( FAILED( hr = mpD3DDevice->CreateOffscreenPlainSurface(
mD3DPParameters.BackBufferWidth,
mD3DPParameters.BackBufferHeight,
D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &buffer, NULL ) ) )
return false;

// Write the front buffer to the surface
if( FAILED( hr = mpD3DDevice->GetFrontBufferData( 0, buffer ) ) )
{
mGCLog.Error("Cannot Acquire front buffer...");
buffer->Release();

return false;
}

D3DXSaveSurfaceToFile( fileName, ImgFormat, buffer, NULL, NULL );

// Cleanup
buffer->Release();
return true;
}


hope it helps!
Syntax is same, Thinking is Different<<<
intransigent-seal
intransigent-seal
It may be overkill if you''ve got your method sorted out by now, but:
Designing a Screen Shot System (here on GDnet)

also,
Sweet Snippets: Generating a Screenshot in DirectX 8.1 (also here on GDnet; I know it''s for DX8.1, but it may still be applicable)

John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
davidkosenina
davidkosenina
Helo

Thank you very much for help. DivineLight code seem to work, but
I can only get a totaly black screen shot or some pixel mess
if I use D3DPOOL_DEFAULT insted of SCRETCH. I tryed everything and
I still get totaly black picture.

Any ideas?
eFoDay
eFoDay
D3DXSaveSurfaceToFile will fail because D3DX cannot lock nondynamic surfaces located in video memory?
try making the surface dynamic

Topic Locked

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

Sign in to reply to this topic.