DirectX 开发,显示文字,画面闪烁问题
我是VC新手,最近在用VC做DX9的开发,现在问题是这样的,采用sdk中DXUT框架,在 OnFrameRender中绘图,绘图显示的是一个string类型的全局结构变量(通过函数转换为LPCWSTR后用DrawText绘制),该变量由winsock处理并接收,大约每秒60次刷新。
现在的问题是,屏幕显示内容是正确的,但是文字有闪烁,该如何处理?
部分代码如下:
void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
if( g_SettingsDlg.IsActive() )
{
g_SettingsDlg.OnRender( fElapsedTime );
return;
}
HRESULT hr;
RECT rc;
D3DMATERIAL9 mtrl;
D3DXMATRIXA16 matWorld;
D3DXMATRIXA16 matView = *g_Camera.GetViewMatrix();
D3DXMATRIXA16 matProj = *g_Camera.GetProjMatrix();
D3DXMATRIXA16 matViewProj = matView * matProj;
pd3dDevice->SetTransform( D3DTS_VIEW, &matView );
pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
// Clear the viewport
pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0L );
// Begin the scene
if( SUCCEEDED( pd3dDevice->BeginScene() ) )
{
//主绘制程序
SetRect(&rc, 5, 5, 0, 0);
g_pFont->DrawText(NULL, ConvertCharToLPWSTR(FD.title.c_str()), -1, &rc, DT_NOCLIP,
D3DCOLOR_XRGB(255,255,255));
SetRect(&rc, 5, 25, 0, 0);
g_pFont->DrawText(NULL, ConvertCharToLPWSTR(FD.kohlsmann.c_str()), -1, &rc, DT_NOCLIP,
D3DCOLOR_XRGB(255, 255, 255));
pd3dDevice->EndScene();
}
}