you could try near-/farZ 0.2 1600.0. That works perfect for me. i fail to get correct results using the camera´s values, which were 0/1 when i checked the last time.
i´m counting viewportcalls with min == 0 and max == 1 every frame, then render my stuff in numMaxCalls -2. basically works from -5 to -2.
it´s not perfect, as it hides some of the ui text, and "flickers" when the number of viewport calls changes. but the geom is perfectly in place, that´s what is important for me.
here´s my mess:
Code:
void WowWorldRenderCtx::setDeviceStates()
{
// check if device supports alphablend
bool bSupportsAlphaBlend = true;
LPDIRECT3D9 pd3d9 = NULL;
if( SUCCEEDED( m_pD3dDevice->GetDirect3D( &pd3d9 ) ) )
{
D3DCAPS9 Caps;
D3DDISPLAYMODE Mode;
LPDIRECT3DSURFACE9 pSurf = NULL;
D3DSURFACE_DESC Desc;
m_pD3dDevice->GetDeviceCaps( &Caps );
m_pD3dDevice->GetDisplayMode( 0, &Mode );
if( SUCCEEDED( m_pD3dDevice->GetRenderTarget( 0, &pSurf ) ) )
{
pSurf->GetDesc( &Desc );
if( FAILED( pd3d9->CheckDeviceFormat( Caps.AdapterOrdinal, Caps.DeviceType, Mode.Format,
D3DUSAGE_RENDERTARGET | D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, D3DRTYPE_SURFACE,
Desc.Format ) ) )
{
bSupportsAlphaBlend = false;
}
SAFE_RELEASE( pSurf );
}
SAFE_RELEASE( pd3d9 );
}
if(bSupportsAlphaBlend)
{
m_pD3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
m_pD3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
m_pD3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
}
else
{
m_pD3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
}
m_pD3dDevice->SetRenderState( D3DRS_CULLMODE , 0);
m_pD3dDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
m_pD3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
m_pD3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
m_pD3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
m_pD3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_DISABLE );
m_pD3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
m_pD3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_TEXTURE);
}
Code:
void WowWorldRenderCtx::beginDrawing()
{
D3DXMATRIX projMatrix;
D3DXMATRIX viewMatrix;
D3DXMATRIX worldMatrix;
// make that stuff member variables..
float m_AspectRatio = 1680.0 / 1050.0; // get values from client...
float m_fFovYMulti = 0.6;
float m_ZNearPlane = 0.2;
float m_ZFarPlane = 1600.0;
CameraInfo* cam = CGWorld::getActiveCamera();
D3DXMatrixPerspectiveFovRH(&projMatrix, cam->fFov * m_fFovYMulti , m_AspectRatio ,m_ZNearPlane, m_ZFarPlane);
D3DXVECTOR3 eye = cam->fPos;
float ppos[3];
ppos[0] = eye[0] + cam->fViewMat[0][0] ;
ppos[1] = eye[1] + cam->fViewMat[0][1] ;
ppos[2]= eye[2] + cam->fViewMat[0][2] ;
D3DXVECTOR3 at = ppos ;
D3DXVECTOR3 upVec(0, 0, 1);
D3DXMatrixLookAtRH(&viewMatrix, &eye, &at, &upVec);
// set Transformation matix
m_pD3dDevice->SetTransform(D3DTS_VIEW, &viewMatrix);
m_pD3dDevice->SetTransform(D3DTS_PROJECTION, &projMatrix);
// move somewhere other/
D3DXMatrixIdentity(&worldMatrix);
D3DXMatrixTranslation(&worldMatrix, 0, 0, 0);
m_pD3dDevice->SetTransform(D3DTS_WORLD, &worldMatrix);
// setup viewport
D3DVIEWPORT9 Viewport;
m_pD3dDevice->GetViewport(&Viewport);
Viewport.MinZ = m_ZViewPortNearPlane;
Viewport.MaxZ = m_ZViewPortFarPlane;
m_pD3dDevice->SetViewport(&Viewport);
if(m_bWireFramed)
{
m_pD3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_WIREFRAME );
m_pD3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
}
else
{
m_pD3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID );
m_pD3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
}
}