锘??xml version="1.0" encoding="utf-8" standalone="yes"?> 2008-12-02 絎?璁層愬垱寤烘鏋躲?/font> 7 涓篊WelfGameFrm綾繪坊鍔燱indowProc鍑芥暟錛屽茍鍔犲叆浠g爜錛?a >http://hi.baidu.com/welflau/甯屾湜鑳戒繚鐣欏師鍒涗綔鑰呴摼鎺ワ紝璋㈣阿錛?/font> 8 涓哄伐紼嬫坊鍔犱袱涓枃浠?br />
myd3d.cpp錛?myd3d.h 9 緙栬瘧鍑虹幇 10 灝咮OOL CWelfGameApp::InitInstance()涓殑 11 涓篊WelfGameFrm綾繪坊鍔燨nPaint鍝嶅簲 絎?璁層愮粯鍒舵枃瀛楀拰鍥懼儚銆?/strong> 鐩綍 public : 2鍦╩yd3d.cpp涓坊鍔犲嚱鏁板畾涔?br />
d3dHdc::d3dHdc() d3dHdc::~d3dHdc() void d3dHdc::Release() 3 鐜板湪灝卞彲浠ヤ嬌鐢ㄤ粬浜?br />
鍦ㄧ粯鍒跺嚱鏁頒腑娣誨姞錛?br />
d3dHdc hdc ; 2 騫舵坊鍔犲畾涔夛細(xì) /*//////////////////////////////////////////////// /*//////////////////////////////////////////////// d3dTexture::d3dTexture() d3dTexture::~d3dTexture() void d3dTexture::Release() BOOL d3dTexture::Create( LPCTSTR file ) void d3dTexture::BltFast(int x, int y) void d3dTexture::BltFast(int l , int t , int r , int b ) 3 緙栬瘧鏃朵細(xì)鍑洪敊 4 鍦╓elfGameFrm涓坊鍔犱袱涓垚鍛?br />
d3dTexture m_Bk ; 5 鍦╓elfGameFrm鐨凜reate鍝嶅簲娣誨姞錛?br />
m_Bk.Create( "鑳屾櫙.tga" ); 6 璋冪敤BltFast榪涜緇樺埗 7 灝咮ltFast鍑芥暟鏀硅繘 絎?璁?WelfGame銆愬浘鍍忛忔槑鍙婇鑹層?/strong> http://hi.baidu.com/welflau/甯屾湜鑳戒繚鐣欏師鍒涗綔鑰呴摼鎺ワ紝 銆愪竴銆戙佸疄鐜伴忔槑鍥懼儚 1 鍦?/span>RenderScene()涓坊鍔犺緗唬鐮?/span> 鍦ㄨ儗鏅粯鍒跺墠娣誨姞錛?/font> d3d_Device->SetRenderState( D3DRS_CULLMODE , D3DCULL_NONE ); d3d_Device->SetRenderState( D3DRS_ZENABLE , D3DZB_FALSE ); d3d_Device->SetRenderState( D3DRS_SHADEMODE , D3DSHADE_FLAT ); d3d_Device->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE ); 鍦ㄥ墠鏅粯鍒剁殑鍓嶉潰娣誨姞 d3d_Device->SetRenderState( D3DRS_SRCBLEND , D3DBLEND_SRCALPHA ); d3d_Device->SetRenderState( D3DRS_DESTBLEND , D3DBLEND_INVSRCALPHA ); d3d_Device->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );//寮鍚販鑹?/span> 鏁堟灉 2 涓?/span>d3dTexture娣誨姞BltFast鍑芥暟 void d3dTexture::BltFast(int l , int t , int r , int b , DWORD diffuse ) { D3DTLVERTEX v[4] ; //閮寸看 鎸$ memset( v , 0 , sizeof( v )); v[0].x = v[3].x = (float)(l) ; v[1].x = v[2].x = (float)(r); v[0].y = v[1].y = (float)(t); v[2].y = v[3].y = (float)(b); v[0].rhw = v[1].rhw = v[2].rhw = v[3].rhw = v[0].z = v[1].z = v[2].z = v[3].z = //鑲咃腹 v[0].diffuse = v[1].diffuse = v[2].diffuse = v[3].diffuse = diffuse ; v[1].tu = v[2].tu = v[2].tv = v[3].tv = //鐮為叾鐡滃Α d3d_Device->SetTexture( 0 , m_Texture ); d3d_Device->SetFVF( D3DFVF_TLVERTEX ); d3d_Device->DrawPrimitiveUP( D3DPT_TRIANGLEFAN , 2 , (LPVOID)v , sizeof( D3DTLVERTEX )); } 娣誨姞浠ヤ笅鍑犲彞錛?/font> d3d_Device->SetTextureStageState( 0 , D3DTSS_ALPHAARG1 , D3DTA_TEXTURE ); d3d_Device->SetTextureStageState( 0 , D3DTSS_ALPHAARG2 , D3DTA_DIFFUSE ); d3d_Device->SetTextureStageState( 0 , D3DTSS_COLORARG1 , D3DTA_TEXTURE ); d3d_Device->SetTextureStageState( 0 , D3DTSS_COLORARG2 , D3DTA_DIFFUSE ); d3d_Device->SetTextureStageState( 0 , D3DTSS_COLOROP , D3DTOP_SELECTARG1 ); d3d_Device->SetTextureStageState( 0 , D3DTSS_ALPHAOP , D3DTOP_MODULATE ); //浠ヤ笅涓哄墠鏅?/span> m_Role.BltFast( 100, 100, 250 ,250 ,D3DCOLOR_ARGB( 128 , 255 , 255 , 255 ));//鏈鍚庝竴涓弬鏁頒負(fù)棰滆壊錛屽寘鎷忔槑搴?/span> 鏁堟灉鍥?/font>
http://hi.baidu.com/welflau/甯屾湜鑳戒繚鐣欏師鍒涗綔鑰呴摼鎺ワ紝璋㈣阿錛?/font>
1 鏂板緩MFC exe / dialog based
2 鍒犻櫎dialog綾葷殑鏄劇ず浠g爜
3 娣誨姞WelflGameFrm綾?br />
4 鍦╝pp綾葷殑InitInstance 鍑芥暟涓?娣誨姞http://hi.baidu.com/welflau/甯屾湜鑳戒繚鐣欏師鍒涗綔鑰呴摼鎺ワ紝璋㈣阿錛?/font>
m_pMainWnd = new CWelflGameFrm;
m_pMainWnd->ShowWindow( m_nCmdShow );
m_pMainWnd->UpdateWindow();
5 灝咰WelflGameFrm()鏋勯犲嚱鏁版敼涓簆ublic 鎴愬憳
6 鍦ㄦ瀯閫犲嚱鏁癈WelflGameFrm涓坊鍔狅細(xì)
RECT rect;
Create(NULL,"ch07-1: 銉烡irectGraphics");
CClientDC dc(this);
int width = dc.GetDeviceCaps(HORZRES);
int height = dc.GetDeviceCaps(VERTRES);
GetWindowRect( &rect );
width = ( width - ( rect.right - rect.left ))/2 ;
height = (height - (rect.bottom - rect.top ))/2 ;
MoveWindow( width , height , (rect.right - rect.left ) , (rect.bottom - rect.top ) ,true);
switch( message )
{
case WM_CREATE :
if( !d3dCreate( m_hWnd , 640 , 480 , true ))
PostMessage( WM_CLOSE );
return 0 ;
case WM_DESTROY :
d3dRelease();
return 0 ;
}
fatal error C1010: unexpected end of file while looking for precompiled header directive
瑙e喅鏂規(guī)錛氬湪Project Settings閲孋++欏甸潰鐨凱recomplie Header閲屾妸鍑洪敊婧愭枃浠惰緗負(fù)涓嶄嬌鐢ㄩ緙栬瘧澶村氨鍙互浜嗭紝璇﹁瑙嗛
return FALSE;鏀逛負(fù) return TRUE;
娣誨姞濡備笅浠g爜錛?br />
d3dClear(0);
//
d3d_Device->Present( NULL , NULL , NULL , NULL );
銆愪竴銆戙佷粠DirectGraphic涓幏鍙朌C錛圙DI錛?br />
銆愪簩銆戙?D鍥懼儚緇樺埗
銆愪竴銆戙佷粠DirectGraphic涓幏鍙朌C錛圙DI錛?br />
1 娣誨姞綾籨3dHdc 鍦?myd3d.h鏂囦歡涓?br />
class d3dHdc
{
private :
HDC m_hdc ;
LPDIRECT3DSURFACE9 m_Surface ;
void Release();
inline operator HDC(){ return m_hdc ;};
public :
d3dHdc();
~d3dHdc();
};
{
m_hdc = 0 ;
m_Surface = 0 ;
// 鑾峰緱璁懼
if( !d3d_Device )
return ;
if( d3d_Device->GetBackBuffer( 0 , 0 , D3DBACKBUFFER_TYPE_MONO , &m_Surface ) != D3D_OK )
return ;
m_Surface->GetDC( &m_hdc );
}
{
Release();
}
{
if( m_Surface )
{
if( m_hdc )
m_Surface->ReleaseDC( m_hdc );
m_Surface->Release();
m_hdc = NULL ;
m_Surface = NULL ;
}
}
SetTextColor( hdc , RGB( 255 , 255 , 255 ));
SetBkMode( hdc , 1 );
TextOut( hdc , 0 , 0 , str , strlen( str ));
hdc.Release();
銆愪簩銆戙?D鍥懼儚緇樺埗
1 鏂板緩d3dTexture綾?br />
class d3dTexture
{
private :
int m_Width ;
int m_Height ;
LPDIRECT3DTEXTURE9 m_Texture ;
public :
void BltFast( int x , int y );
void BltFast( int l , int t , int r , int b );
public :
BOOL Create( LPCTSTR file );
void Release();
inline operator LPDIRECT3DTEXTURE9(){ return m_Texture ;};
public :
d3dTexture();
~d3dTexture();
};
3D 綰圭悊綾籨3dTexture 鍑芥暟瀹氫箟 2008-12-02
{
m_Texture = NULL ;
}
{
Release();
}
{
if( m_Texture )
m_Texture->Release();
m_Texture = NULL ;
}
{
D3DXIMAGE_INFO in ;
memset( &in , 0 , sizeof( in ));
// 錒嶃仸
Release();
//鏇?
D3DXCreateTextureFromFileEx( d3d_Device ,
file , D3DX_DEFAULT , D3DX_DEFAULT ,
0 , 0 , D3DFMT_UNKNOWN , D3DPOOL_MANAGED ,
D3DX_DEFAULT ,
D3DX_DEFAULT , 0 , &in , NULL , &m_Texture );
if( m_Texture == NULL )
return false ;
// 鐪旀垐
m_Width = in.Width ;
m_Height = in.Height ;
return true ;
}
{
BltFast( x , y , x + m_Width , y + m_Height );
}
{
D3DTLVERTEX v[4] ;
//閮寸看 鎸$
memset( v , 0 , sizeof( v ));
v[0].x = v[3].x = (float)(l) ;
v[1].x = v[2].x = (float)(r);
v[0].y = v[1].y = (float)(t);
v[2].y = v[3].y = (float)(b);
v[0].rhw = v[1].rhw = v[2].rhw = v[3].rhw =
v[0].z = v[1].z = v[2].z = v[3].z = 0.5f ;
v[0].diffuse = v[1].diffuse = v[2].diffuse = v[3].diffuse = -1 ;
v[1].tu = v[2].tu = 1.0f ;
v[2].tv = v[3].tv = 1.0f ;
//鐮為叾鐡滃Α
d3d_Device->SetTexture( 0 , m_Texture );
d3d_Device->SetFVF( D3DFVF_TLVERTEX );
d3d_Device->DrawPrimitiveUP( D3DPT_TRIANGLEFAN , 2 , (LPVOID)v , sizeof( D3DTLVERTEX ));
}
瑙e喅鏂規(guī)硶錛?br />
鍦╩yd3d.h鏂囦歡涓坊鍔?br />
#include "d3dx9tex.h"
鍜?br />
#pragma comment(lib,"d3dx9.lib")
浠ュ強
const DWORD D3DFVF_TLVERTEX = (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1 );
typedef struct _D3DTLVERTEX
{
float x , y , z , rhw ;
D3DCOLOR diffuse , specular;
float tu, tv;
}D3DTLVERTEX ;
d3dTexture m_Role ;
m_Role.Create( "濞冨▋.tga" );
//寮濮嬬粯鍒?br />
d3d_Device->BeginScene();
d3d_Device->SetRenderState( D3DRS_CULLMODE , D3DCULL_NONE );
d3d_Device->SetRenderState( D3DRS_ZENABLE , D3DZB_FALSE );
m_Bk.BltFast( 0 , 0 );
m_Role.BltFast( 0 , 0 );
d3d_Device->EndScene();
]]>
string 杞?CString
CString.format("%s", string.c_str());
char 杞?CString
CString.format("%s", char*);
char 杞?string
string s(char *);
string 杞?char *
char *p = string.c_str();
CString 杞?string
string s(CString.GetBuffer());
1錛宻tring -> CString
CString.format("%s", string.c_str());
鐢╟_str()紜疄姣攄ata()瑕佸ソ.
2錛宑har -> string
string s(char *);
浣犵殑鍙兘鍒濆鍖栵紝鍦ㄤ笉鏄垵濮嬪寲鐨勫湴鏂規(guī)渶濂借繕鏄敤assign().
3,CString -> string
string s(CString.GetBuffer());
GetBuffer()鍚庝竴瀹氳ReleaseBuffer(),鍚﹀垯灝辨病鏈夐噴鏀劇紦鍐插尯鎵鍗犵殑絀洪棿.