Jump to content
  • Advertisement
Sign in to follow this  
qboygary

DirectX Problem -- Render to Bitmap

This topic is 4883 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

Hello everyone, I am writing a program with direct 3D and I need to render the scene to a bitmap file or memory DC. Can anyone help me how to do this? The version of directx is 8.1 and I am programming in VB 6. Thx for help.

Share this post


Link to post
Share on other sites
Advertisement
You could substitute current render target with a texture, then render the scene as usual, then switch back, and save the texture.

Alternatively: you could render as usual, then create a texture, copy front-buffer data to its main surface, and safe the texture to file. For this approach I even found an implementation (altough very old, and in C++, but you get the point). That was in DX9.0, but I thing al this was already there in 8.1:


HRESULT TakeScreenShot(CString& fileName)
{
HRESD hr;
// prepare buffer to safe the content of frontBuffer.
DXSurface pSurf;
DXTexture pTex;
int width = ...;
int height = ...;
hr = g_pDevice->CreateTexture( width, height, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &pTex, NULL);
hr = pTex->GetSurfaceLevel( 0, &pSurf );
// copy content of the render-target.
hr = g_pDevice->GetFrontBufferData(0, pSurf);
hr = D3DXSaveTextureToFile( fileName, D3DXIFF_BMP, pTex, NULL );

pSurf->Release();
pTex->Release();

return hr;
}



This screen-shot takes a little (~1 second), but accessing the front-buffer data is very slow in general.

Hope that helps.
/def

Share this post


Link to post
Share on other sites
Thanks for your help, but I can't find D3DXSaveTextureToFile function in VB documentation, only find in C++. I think I can copy the scene to a memory DC (together a hBitmap) and the just use SavePicture to save it. How to copy the scene to a memory DC?

Share this post


Link to post
Share on other sites
Quote:
Original post by qboygary
I can't find D3DXSaveTextureToFile function in VB documentation, only find in C++.


So how do you load a texture? I think you can save it through the same interface.

Anyway, you can also access texture data directly:
D3DLOCKED_RECT data;
pTex->LockRect( 0, &data, NULL, D3DLOCK_READONLY );
// ...do something with the data...
pTex->UnlockRect();

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!