Get Frontbuffer / Does Clear() empty backbuffer

Started by
3 comments, last by superpig 18 years, 10 months ago
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.
Advertisement
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.
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.
Hack my projects! Oh Yeah! Use an SVN client to check them out.BlockStacker
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.
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().

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

This topic is closed to new replies.

Advertisement