Sign in to follow this  
Halsafar

Get Frontbuffer / Does Clear() empty backbuffer

Recommended Posts

Halsafar    205
In Dx7 you needed to have a front buffer and backbuffer declared so it was easy to manage the both of them. In Dx9 it handles all that for you, but it is still easy to get a copy of the backbuffer. Now one, I either need to get a copy of the front buffer so I can create a texture out of the current picture on the screen. Or, I need to know if when I call Device3D->Clear(...) does that clear out the backbuffer? I need a way to freeze the current image the player can see on his moniter during the gameLoop and create a texture out of it. I can do that part myself once I get either the bits from the image on the screen, that is where I do not know where to start.

Share this post


Link to post
Share on other sites
Aldenar    378
Getting the content of the backbuffer is usually better and faster, since you can use IDirect3DDevice9::StretchRect() *before* you present the scene.

If you want the content of the front buffer, you can use IDirect3DDevice9::GetFrontBufferData(), but it is pretty tricky since it will return a copy of the entire screen (annoying when running in windowed mode). It is also not very fast, but it is a good way to generate screenshots of your game.

Share this post


Link to post
Share on other sites
Staffan E    536
Quote:
Original post by Halsafar
Now one, I either need to get a copy of the front buffer so I can create a texture out of the current picture on the screen.

Same answer as Aldenar above.

Quote:
Or, I need to know if when I call Device3D->Clear(...) does that clear out the backbuffer?

Yes, well, Clear( ) operates on the currently selected render target which is the next backbuffer in the swap chain by default. It does nothing to the other surfaces in the chain if that's what you mean.
Present( ) on the other hand is not guaranteed to keep the last frame's frontbuffer when presenting the current backbuffer onto the screen unless you explicitly told it to in the SwapEffect member of D3DPRESENT_PARAMETERS when you created the device. You can read about what happens during a present operation with the different swap effects here.

Quote:
I need a way to freeze the current image the player can see on his moniter during the gameLoop and create a texture out of it. I can do that part myself once I get either the bits from the image on the screen, that is where I do not know where to start.

To use the scene as a texture I usually find it easier to do it the other way around; to render the scene to a texture at first and then render that texture to the back buffer and presenting it.

You can create a texture with the D3DUSAGE set to D3DUSAGE_RENDERTARGET and with the same size as your back buffer, then get it's surface through GetSurfaceLevel( ). Then you use the SetRenderTarget( ) of the device with the acquired surface and render. The result is your scene boxed up in a texture which you can render to the back buffer or blend with something else, etc.

This way you don't have to worry about what's in the front or back buffer and can let DX handle those by itself.

Stay sharp.

Share this post


Link to post
Share on other sites
Halsafar    205
Staaf, using your method is it possible to go from the texture which has the rendered screen on it to a bmp?

Would I just create a bitmap by using the bits from the texture?
All snapshots would then be n^2.

Share this post


Link to post
Share on other sites
superpig    1825
Quote:
Original post by Halsafar
Staaf, using your method is it possible to go from the texture which has the rendered screen on it to a bmp?

Would I just create a bitmap by using the bits from the texture?
All snapshots would then be n^2.


Take a look at D3DXSaveTextureToFile().

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