Jump to content

  • Log In with Google      Sign In   
  • Create Account


Question About D3DXSaveTextureToFile


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 hopeztm   Members   -  Reputation: 100

Like
0Likes
Like

Posted 21 April 2012 - 07:23 PM

I want to set a texture as render target and then save it to the disk. but the rendering is ok, which means I can draw the tea port on the screen, but the file I saved is not ok, I can't open it with texture format D3DFMT_A8R8G8B8, or the file corropted when I use
D3DFMT_R5G6B5.

the following is my code, I started use DX for 1 week, I am really weak in this technique, thank you so much~



HRESULT DXMainFrame::FrameSnapShot(HWND hWnd, TCHAR *filename)
{
D3DDISPLAYMODE mode;
HRESULT hr;
if (FAILED(hr = m_pD3DDevice->GetDisplayMode(0, &mode)))
return hr;
IDirect3DTexture9 * g_pRenderTexture = NULL;
hr = m_pD3DDevice->CreateTexture(mode.Width,mode.Height,1,
D3DUSAGE_RENDERTARGET,
D3DFMT_R5G6B5,
D3DPOOL_DEFAULT,&g_pRenderTexture,
NULL);
LPDIRECT3DSURFACE9 surf,oldRenderTarget;
hr = g_pRenderTexture->GetSurfaceLevel(0,&surf);
m_pD3DDevice->GetRenderTarget(0,&oldRenderTarget);
m_pD3DDevice->SetRenderTarget(0,surf);
m_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DXCOLOR
(0.0f,0.25f,0.25f,0.55f), 1.0f, 0);
drawTeaPort(m_pD3DDevice);
m_pD3DDevice->SetRenderTarget(0,oldRenderTarget);
m_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DXCOLOR (0.0f,0.25f,0.25f,0.55f), 1.0f, 0);
OnFrameRender(m_pD3DDevice,DXUTGetTime(),DXUTGetElapsedTime(),NULL);
hWnd = DXUTGetHWND();


// area to capture
RECT *rect = NULL;
WINDOWINFO windowInfo;
windowInfo.cbSize =

sizeof(WINDOWINFO);


if(hWnd) // capture windo
{
GetWindowInfo(hWnd, &windowInfo);
rect = &windowInfo.rcWindow;
}
hr = D3DXSaveTextureToFile(filename,D3DXIFF_BMP,g_pRenderTexture,NULL);


//hr = D3DXSaveSurfaceToFile(filename, D3DXIFF_BMP, surf, NULL, rect); didn't work either
surf->Release();
g_pRenderTexture->Release();


return hr;
}

Sponsor:

#2 hopeztm   Members   -  Reputation: 100

Like
0Likes
Like

Posted 21 April 2012 - 07:31 PM

thnks

#3 kubera   Members   -  Reputation: 889

Like
0Likes
Like

Posted 21 April 2012 - 10:59 PM

Hi
Please consider checking HRESULT (hr), you could put this returned value into the DXErr.exe (in the SDK) and watch what the error means.
You would run your application in Debug Mode inside Visual Studio. The console could print a warning for this situation.
Maybe you would save BITMAP this way:
D3DXSaveSurfaceToFile(filename, D3DXIFF_BMP, surf, NULL, NULL)

P. S.
You have a bit weak checking of errors. It would be possible, that the error is earlier.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS