Sign in to follow this  
Jan Birsa

Capture the screenshot!

Recommended Posts

I am trying to make a screenshot in C++ DX9 using DXUT, but I have some problems. I have fixed one already. The device didn't work as it should, I fixed that, and now device isn't NULL anymore. It makes screenshot, but the problem is, its black. I get something.bmp, but its black, which is another frustrating problem I have. I guess there is something wrong with surface... Here is the code: HRESULT WINAPI CaptureScreen(IDirect3DDevice9* pd3dDevice) { IDirect3DSurface9* pSurface; //IDirect3DDevice9 *pd3dDevice = DXUTGetD3D9Device(); if (pd3dDevice != NULL) { //DXUTShutdown( 0 ); //proof device isnt NULL pd3dDevice->CreateOffscreenPlainSurface(1024, 768, D3DFMT_A8R8G8B8, D3DPOOL_SCRATCH, &pSurface, NULL); pd3dDevice->GetFrontBufferData(0, pSurface); } D3DXSaveSurfaceToFile(L"Media\\Screenshots\\something.bmp",D3DXIFF_BMP,pSurface,NULL,NULL); pSurface->Release(); return 0; } What should I do? Whats the problem?

Share this post


Link to post
Share on other sites
Quote:
Original post by Jan Birsa
Quote:
Original post by Demirug
I am pretty sre that the surface needs to be created in system memory pool and not in the scratch pool.

SYSTEMMEM pool didnt make any difference...
And what did the debug runtimes say when you used the system memory pool?

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
Quote:
Original post by Jan Birsa
Quote:
Original post by Demirug
I am pretty sre that the surface needs to be created in system memory pool and not in the scratch pool.

SYSTEMMEM pool didnt make any difference...
And what did the debug runtimes say when you used the system memory pool?


When I run debug with breakpoints set I get here:
pd3dDevice->GetFrontBufferData(0, pSurface); red marked 0x04915500 on d3dx9.lib and 0x049c5600 on d3dx9d.lib. I have set debug on max in DX Cpanel for this run.



Share this post


Link to post
Share on other sites
Quote:
Original post by Jan Birsa
When I run debug with breakpoints set I get here:
pd3dDevice->GetFrontBufferData(0, pSurface); red marked 0x04915500 on d3dx9.lib and 0x049c5600 on d3dx9d.lib. I have set debug on max in DX Cpanel for this run.
Don't use any breakpoints on the DirectX control panel, just let the code run (and render black), and look at the debug output.

Even with "break on D3D error" enabled, you should still get some debug output.

Share this post


Link to post
Share on other sites
Quote:
Original post by Jan Birsa
Quote:
Original post by Evil Steve
Quote:
Original post by Jan Birsa
Quote:
Original post by Demirug
I am pretty sre that the surface needs to be created in system memory pool and not in the scratch pool.

SYSTEMMEM pool didnt make any difference...
And what did the debug runtimes say when you used the system memory pool?


When I run debug with breakpoints set I get here:
pd3dDevice->GetFrontBufferData(0, pSurface); red marked 0x04915500 on d3dx9.lib and 0x049c5600 on d3dx9d.lib. I have set debug on max in DX Cpanel for this run.


What am I doing wrong?

Share this post


Link to post
Share on other sites
Quote:
Original post by Jan Birsa
Quote:
Original post by Jan Birsa
When I run debug with breakpoints set I get here:
pd3dDevice->GetFrontBufferData(0, pSurface); red marked 0x04915500 on d3dx9.lib and 0x049c5600 on d3dx9d.lib. I have set debug on max in DX Cpanel for this run.


What am I doing wrong?
You're not looking at the debug output window. Can you paste the entire contents of the debug output window here when you get to that line?

If you don't know how to do that, I'd recommend This Article.

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
Quote:
Original post by Jan Birsa
Quote:
Original post by Jan Birsa
When I run debug with breakpoints set I get here:
pd3dDevice->GetFrontBufferData(0, pSurface); red marked 0x04915500 on d3dx9.lib and 0x049c5600 on d3dx9d.lib. I have set debug on max in DX Cpanel for this run.


What am I doing wrong?
You're not looking at the debug output window. Can you paste the entire contents of the debug output window here when you get to that line?

If you don't know how to do that, I'd recommend This Article.


Sorry, but I am soo stupid...I forgot to compile as debug and thats why I aint got anything.

Now, bingo:
Direct3D9: (ERROR) :Destination surface not big enough to hold the size of the screen. GetFrontBufferData fails.
D3D9 Helper: IDirect3DDevice9::GetFrontBufferData failed: D3DERR_INVALIDCALL

Share this post


Link to post
Share on other sites
Quote:
Original post by Jan Birsa
Quote:
Original post by Evil Steve
Quote:
Original post by Jan Birsa
Quote:
Original post by Jan Birsa
When I run debug with breakpoints set I get here:
pd3dDevice->GetFrontBufferData(0, pSurface); red marked 0x04915500 on d3dx9.lib and 0x049c5600 on d3dx9d.lib. I have set debug on max in DX Cpanel for this run.


What am I doing wrong?
You're not looking at the debug output window. Can you paste the entire contents of the debug output window here when you get to that line?

If you don't know how to do that, I'd recommend This Article.


Sorry, but I am soo stupid...I forgot to compile as debug and thats why I aint got anything.

Now, bingo:
Direct3D9: (ERROR) :Destination surface not big enough to hold the size of the screen. GetFrontBufferData fails.
D3D9 Helper: IDirect3DDevice9::GetFrontBufferData failed: D3DERR_INVALIDCALL


Oh, thank you so much for help. I guess I should run debugs more often (now I learned how to do it).

All I had to do is store dimensions of surface to width and height variable, and use both for fetching (CreateOffscreenPlainSurface and GetFrontBufferData) buffer data.

Yet one funny thing Ive noticed. If I set size manually for example 2000x2000 it captures everything (app + windows). Maybe because of Vista's Areo or something?

Share this post


Link to post
Share on other sites
Ok, I have another problem (this is because I am a n00b).

I have made 2 UINT variables, height and width where I store my height and width from pBackBufferSurfaceDesc.

It stores everything fine, but it fails to make a screenshot in windowed mode.
For some reason, it want to make a screenshot of whole desktop (display resolution), which is 1680x1050, but in pBackBufferSurfaceDesc I have 1024x786, and screenshot fails to make (black screen).

If I go fullscreen for example 640x480, it makes screenshot just fine, since in fullscreen display resolution changes to same as applications one.

What the hell am I doing wrong this time?

Share this post


Link to post
Share on other sites
I have a question regarding the rights of using an image format to capture screenshot in comercial applications. Can I use JPG or BMP to save screenshots on a commercial application??, because I remember that even Microsoft had a problem with this ( http://yro.slashdot.org/yro/05/04/24/1228234.shtml?tid=123&tid=109&tid=188&tid=95 )
I'm using DirectX, winXP.

Saludos

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this