2013年8月20日星期二(DEMO7-19DX与GDI混合使用)

 

只需要在ddraw中找到一个兼容DC,就可以使用,使用完之后再释放。

函数实现为

int Draw_Text_GDI( char * text, int x, int y, COLORREF color, LPDIRECTDRAWSURFACE7 lpdds )

{

     HDC  xdc;

     lpdds->GetDC( & xdc );

     SetTextColor( xdc, color );

     SetBkMode( xdc, TRANSPARENT );

     TextOut( xdc, x, y, text, strlen( text ) );

     lpdds->ReleaseDC( xdc );

     return ( 1 );

}

在game_main()中,实现也很简单

 

int Game_Main(void *parms = NULL,int num_parms = 0)

{

// this is the main loop of the game, do all your processing

// here

 

// make sure this isn't executed again

if (window_closed)

   return(0);

 

// for now test if user is hitting ESC and send WM_CLOSE

if (KEYDOWN(VK_ESCAPE))

   {

   PostMessage(main_window_handle,WM_CLOSE,0,0);

   window_closed = 1;

   } // end if

 

     int x = rand() % SCREEN_WIDTH;

     int y = rand() % SCREEN_HEIGHT;

    

     Draw_Text_GDI( "hello",x, y, RGB( rand() % 256, rand() % 256, rand() % 256 ), lpddsprimary );

 

// wait a sec

Sleep(33);

 

// do nothing -- look at pretty picture

 

// return success or failure or your own return code here

return(1);

 

} // end Game_Main

开始封装,加上成员函数

 

int DDRAW_Interface::Draw_Text_GDI(char * text, int x,int y, COLORREF color, LPDIRECTDRAWSURFACE7 lpdds )

{

     HDC           xdc;

     lpdds->GetDC( & xdc );

     SetTextColor( xdc, color );

     SetBkMode( xdc, TRANSPARENT );

     TextOut( xdc, x, y, text, strlen( text ) );

 

     lpdds->ReleaseDC( xdc );

 

     return 1;

 

}但是出来后都是白色,在game_main()中改为

     ddraw->Draw_Text_GDI( "hello",x, y, RGB( 100,200, 130 ));也是白色的,奇怪了。

 

备注:

后来发现书上说,RGB是24位结构,于是在引擎中,改了#define     SCREEN_BPP    16或者24,颜色正常了,分辨率还得调一下,不过这倒是不关键了,

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值