DirectX Problem -- Render to Bitmap

Started by
2 comments, last by deffer 18 years, 9 months ago
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.
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
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?
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();

This topic is closed to new replies.

Advertisement