Well how do I react to WM_SIZE when using D3D8 ?
I tried to set a viewport and to reset the projection matrix but it did not exactly work because the graphics were not clipped but messed up.
Here is the code:
case WM_SIZE:
D3DVIEWPORT8 ViewPort;
RECT Rect;
GetClientRect(g_pApplication->GetHandle(), &Rect);
ViewPort.X = 0;
ViewPort.Y = 0;
ViewPort.Width = Rect.right - Rect.left;
ViewPort.Height = Rect.bottom - Rect.top;
ViewPort.MinZ = 0.0f;
ViewPort.MaxZ = 1.0f;
if(SAFE_CHECK(g_pGraphics)) {
g_pGraphics->GetDevice()->SetViewport(&ViewPort);
g_pGraphics->SetPerspective(D3DX_PI / 4, 1.0f, 1000.0f);
}
break;
And the code of the SetPerspective method:
bool CGraphics3D::SetPerspective(float fFOV, float fNear, float fFar) {
//Lokale Variablen
D3DXMATRIX MatrixProjection;
HRESULT hr;
D3DVIEWPORT8 Viewport;
hr = m_lpD3DDevice->GetViewport(&Viewport);
if(FAILED(hr)) {
return ReportError(NULL, &hr, "Fehler beim Auslesen des Viewports (CGraphics3D::SetPerspective)");
}
float fAspect = ((float)Viewport.Width) / ((float)Viewport.Height);
D3DXMatrixPerspectiveFovLH(&MatrixProjection, fFOV, fAspect, fNear, fFar);
hr = m_lpD3DDevice->SetTransform(D3DTS_PROJECTION, &MatrixProjection);
if(FAILED(hr)) {
return ReportError(NULL, &hr, "Fehler beim Setzen der Projektions Matrix (CGraphics3D::SetPerspective)");
}
return true;
}