发信人: wenbobo(灌了拂衣去) 
整理人: wenbobo(2002-07-10 16:42:05), 站内信件
 | 
 
 
★原文转载自GameDevelop版wenbobo的《d3d frame真不好用,人类兄帮忙看看》★
 这是我用dx8的frame框架写的第一个程序,以前自己直接写的都很好,但是这个就有问题,每次font的DrawText都出错:
 错误点在SDK的samples\Multimedia\common\d3dfont.cpp里面:
 HRESULT CD3DFont::DrawText( FLOAT sx, FLOAT sy, DWORD dwColor,
                             TCHAR* strText, DWORD dwFlags )
 {
     if( m_pd3dDevice == NULL )
         return E_FAIL;
 
     // Setup renderstate
     m_pd3dDevice->CaptureStateBlock( m_dwSavedStateBlock );
     m_pd3dDevice->ApplyStateBlock( m_dwDrawTextStateBlock );
     //就是这里:
     m_pd3dDevice->SetVertexShader( D3DFVF_FONT2DVERTEX );
 ...
 
 与字体相关的用红色表示,完整程序如下:
 
 #include <windows.h>
 #include <d3d8.h>
 #include "d3dapp.h"
 #include "d3dfont.h"
 #include "DXUtil.h"
 
 class CMyD3DApplication: public CD3DApplication
 {
     CD3DFont*     m_pFont;              // Font for drawing text
 
     HRESULT ConfirmDevice( D3DCAPS8*, DWORD, D3DFORMAT );
 
 protected:
     HRESULT OneTimeSceneInit();
     HRESULT InitDeviceObjects();
     HRESULT FrameMove();
     HRESULT Render();
     HRESULT DeleteDeviceObjects();
     HRESULT FinalCleanup();
 
 public:
     CMyD3DApplication();
 };
 
 CMyD3DApplication::CMyD3DApplication():m_pFont(NULL)
 {
     m_strWindowTitle    = _T("DirectX 8 program study");
     m_bUseDepthBuffer   = TRUE;
     m_pFont = new CD3DFont( _T("Tahoma"), 18, D3DFONT_BOLD );
 }
 
 HRESULT CMyD3DApplication::ConfirmDevice( D3DCAPS8* pCaps, DWORD dwBehavior,
                                           D3DFORMAT Format )
 {
     if( dwBehavior & D3DCREATE_PUREDEVICE )
         return E_FAIL; // GetTransform doesn't work on PUREDEVICE
 
     // This sample uses alpha textures and/or straight alpha. Make sure the
     // device supports them
     if( pCaps->TextureCaps & D3DPTEXTURECAPS_ALPHAPALETTE )
         return S_OK;
     if( pCaps->TextureCaps & D3DPTEXTURECAPS_ALPHA )
         return S_OK;
 
     return E_FAIL;
 }
 
 // Desc: Called during initial app startup, this function performs all the
 //       permanent initialization.
 HRESULT CMyD3DApplication::OneTimeSceneInit()
 {
     return S_OK;
 }
 
 HRESULT CMyD3DApplication::InitDeviceObjects()
 {	
     m_pFont->InitDeviceObjects( m_pd3dDevice );
     return S_OK;
 }
 
 HRESULT CMyD3DApplication::DeleteDeviceObjects()
 {
     m_pFont->DeleteDeviceObjects();
     return S_OK;
 }
 
 HRESULT CMyD3DApplication::FinalCleanup()
 {
     SAFE_DELETE( m_pFont );
     return S_OK;
 }
 
 HRESULT CMyD3DApplication::FrameMove()
 {
     return S_OK;
 }
 
 HRESULT CMyD3DApplication::Render()
 {
     // Clear the viewport
     m_pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,255), 1.0f, 0L );
 
     // Begin the scene
     if( SUCCEEDED( m_pd3dDevice->BeginScene() ) )
     {
         //就是这里出错
         m_pFont->DrawText( 1, 1, D3DCOLOR_ARGB(255,255,255,0), _T("haha") );
         // End the scene.
         m_pd3dDevice->EndScene();
     }
     return S_OK;
 }
 
 
 CMyD3DApplication MyD3DApplication;
 
 INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
 {
     if( FAILED( MyD3DApplication.Create( hInst ) ) )
         return 0;
 
     return MyD3DApplication.Run();
 }
 
 
  ---- ◢█◣◢█◣
 ◤◥◢█◤◥
 ◣◢█◤◣◢
 ◥█◤◥█◤     | 
 
 
 |