In MFC SDI,How to write D3D code

Started by
5 comments, last by moonhalo 16 years, 8 months ago
In MFC SDI,How to write D3D code? I had wroteen some code about D3D in MFC SDI project. But I have a problem that when I resisze the view, the model will resize. I had reccomputed the projective matrix by the view size (when I resize the View). I want to keep the model's size when I resize the View. [Edited by - akira32 on August 24, 2007 6:49:19 AM]
akira32 編程之家 Yahoohttp://tw.myblog.yahoo.com/akira32-akira32
Advertisement
Well the model is suppose to resize due to the resizing of the window.
Quote:Original post by Kiryn
Well the model is suppose to resize due to the resizing of the window.


I had tried to modify the projective matrix and viewport.
But it seems to be error.

HRESULT hr;
hr=m_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255,0,0,0), 1.0f, 0);

m_ViewClientSize.cx=cx;
m_ViewClientSize.cy=cy;

D3DXMATRIX proj;
D3DXMatrixPerspectiveFovLH(
&proj,
D3DX_PI * 0.5f, // 90 - degree
(float)m_ViewClientSize.cx / (float)m_ViewClientSize.cy,
1.0f,
1000.0f);
if (m_pD3DDevice)
m_pD3DDevice->SetTransform(D3DTS_PROJECTION, &proj);

D3DVIEWPORT9 ViewPort;

m_pD3DDevice->GetViewport(&ViewPort);

ViewPort.Width=m_ViewClientSize.cx;
ViewPort.Height=m_ViewClientSize.cy;

if (m_pD3DDevice)
m_pD3DDevice->SetViewport(&ViewPort);


akira32 編程之家 Yahoohttp://tw.myblog.yahoo.com/akira32-akira32
On resizing you also need to Reset the D3D device. Otherwise DirectX will stretch the content with the original buffer size.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

"Reset the D3D device", Could you say in detail?
akira32 編程之家 Yahoohttp://tw.myblog.yahoo.com/akira32-akira32
Basically you need to release all non-managed-pool resources, call Reset on the IDirect3dDevice (with the modified PresentationParameters) and rebuild your non-managed resources (if you have any).

The modified presentation parameters are the same as on the initialising but have the new size for the backbuffer.

You can use exactly the same code you'd need for Alt-Tabbing in fullscreen mode (which results in a lost device).

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Check the second argument of D3DXMatrixPerspectiveFovLH(...).
The Fov value is also important to decide the size of model.

In my case, I set the projection matrix like this.

float Fov = atanf( (uCY*0.5f)/300 );
D3DXMATRIX matProj;
float fAspect = static_cast<float>(uCX)/uCY;
D3DXMatrixPerspectiveFovLH( &matProj, Fov, fAspect, 0.1f, 100.0f );
m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );

This topic is closed to new replies.

Advertisement