|
我把directX的第三课(Matrices )的绘图代码移植到到DXUT框架下,发现不能正常的绘制出三角形。我已经搞了一个下午了,还是不知道原因。下面是一部分代码。DXUT的框架就是教程里面的SimpleSample
DXUT中的绘图代码,中间有一段是我加的绘图代码,其他都是框架自动生成的,我可以保证摄像机的位置和绘制的三角形的位置都没有问题。
void CALLBACK OnD3D9FrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
HRESULT hr;
D3DXMATRIXA16 mWorld;
D3DXMATRIXA16 mView;
D3DXMATRIXA16 mProj;
D3DXMATRIXA16 mWorldViewProjection;
// If the settings dialog is being shown, then render it instead of rendering the app's scene
if( g_SettingsDlg.IsActive() )
{
g_SettingsDlg.OnRender( fElapsedTime );
return;
}
// Clear the render target and the zbuffer
V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 45, 50, 170 ), 1.0f, 0 ) );
//My Render Codes
g_pd3dDevice->SetTransform( D3DTS_PROJECTION, g_Camera.GetProjMatrix());
g_pd3dDevice->SetTransform( D3DTS_VIEW, g_Camera.GetViewMatrix());
g_pd3dDevice->SetTransform( D3DTS_WORLD, g_Camera.GetWorldMatrix());
if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{
// Render the vertex buffer contents
g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof( CUSTOMVERTEX ) );
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 1 );
// End the scene
g_pd3dDevice->EndScene();
}
//End My Render Code
if( SUCCEEDED( pd3dDevice->BeginScene() ) )
{
// Get the projection & view matrix from the camera class
mWorld = *g_Camera.GetWorldMatrix();
mProj = *g_Camera.GetProjMatrix();
mView = *g_Camera.GetViewMatrix();
mWorldViewProjection = mWorld * mView * mProj;
// Update the effect's variables. Instead of using strings, it would
// be more efficient to cache a handle to the parameter by calling
// ID3DXEffect::GetParameterByName
V( g_pEffect9->SetMatrix( g_hmWorldViewProjection, &mWorldViewProjection ) );
V( g_pEffect9->SetMatrix( g_hmWorld, &mWorld ) );
V( g_pEffect9->SetFloat( g_hfTime, ( float )fTime ) );
DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" ); // These events are to help PIX identify what the code is doing
RenderText();
V( g_HUD.OnRender( fElapsedTime ) );
V( g_SampleUI.OnRender( fElapsedTime ) );
DXUT_EndPerfEvent();
V( pd3dDevice->EndScene() );
}
} |
|