2013年8月27日星期一(DEMO7-19窗口的裁剪等)
来源:互联网 发布:苹果mac一体机 编辑:程序博客网 时间:2024/06/16 04:44
OK,现在马不停蹄,结束这个第7章,拖延的时间真长,有6个月了,汗。。。
这个是上次的应用,加上逻辑判断如何画点,并用GetWindowRect()是客户区,实际上这不对,应该是GetClientRect(),果然不对,只能是说把图画上了。
代码如下
DDSURFACEDESC2 ddsd;
RECT client;
GetWindowRect( main_window_handle, & client );
DDRAW_INIT_STRUCT( ddsd );
lpddsprimary->Lock( NULL, & ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL );
UCHAR * primary_buffer = ( UCHAR * ) ddsd.lpSurface;
if( pixel_format == 32 )
{
for( int index = 0; index < 10; index ++ )
{
int x = rand() % ( client.right - client.left ) + client.left;
int y = rand() % ( client.bottom - client.top ) + client.top;
DWORD color = _RGB32BIT( 0, rand() % 256, rand() % 256, rand() % 256 );
* ( ( DWORD * ) ( primary_buffer + x * 4 + y * ddsd.lPitch ) ) = color;
}
}
else
if( pixel_format == 24 )
{
for( int index = 0; index < 10; index ++ )
{
int x = rand() % ( client.right - client.left ) + client.left;
int y = rand() % ( client.bottom - client.top ) + client.top;
( ( primary_buffer + x * 3 + y * ddsd.lPitch ) )[0] = rand() % 256 ;
( ( primary_buffer + x * 3 + y * ddsd.lPitch ) )[1] = rand() % 256 ;
( ( primary_buffer + x * 3 + y * ddsd.lPitch ) )[2] = rand() % 256 ;
}
}
else
if( pixel_format == 16 )
{
for( int index = 0; index < 10; index ++ )
{
int x = rand() % ( client.right - client.left ) + client.left;
int y = rand() % ( client.bottom - client.top ) + client.top;
USHORT color = _RGB32BIT( 0, rand() % 256, rand() % 256, rand() % 256 );
* ( ( USHORT * ) ( primary_buffer + x * 4 + y * ddsd.lPitch ) ) = color;
}
}
else
{
for( int index = 0; index < 10; index ++ )
{
int x = rand() % ( client.right - client.left ) + client.left;
int y = rand() % ( client.bottom - client.top ) + client.top;
UCHAR color = rand() % 256;
primary_buffer[x + y * ddsd.lPitch] = color;
}
}
lpddsprimary->Unlock( NULL );
Sleep( 1 );
结果如下图所示
但是当封装后,
DDSURFACEDESC2 ddsd;
RECT client;
GetWindowRect( main_window_handle, & client );
DDRAW_INIT_STRUCT( ddsd );
ddraw->getPrimarySurface()->Lock( NULL, & ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL );
UCHAR * primary_buffer = ( UCHAR * ) ddsd.lpSurface;
if( ddraw->getPixelFormat() == 32 )
{
for( int index = 0; index < 10; index ++ )
{
int x = rand() % ( client.right - client.left ) + client.left;
int y = rand() % ( client.bottom - client.top ) + client.top;
DWORD color = _RGB32BIT( 0, rand() % 256, rand() % 256, rand() % 256 );
* ( ( DWORD * ) ( primary_buffer + x * 4 + y * ddsd.lPitch ) ) = color;
}
}
else
if( ddraw->getPixelFormat() == 24 )
{
for( int index = 0; index < 10; index ++ )
{
int x = rand() % ( client.right - client.left ) + client.left;
int y = rand() % ( client.bottom - client.top ) + client.top;
( ( primary_buffer + x * 3 + y * ddsd.lPitch ) )[0] = rand() % 256 ;
( ( primary_buffer + x * 3 + y * ddsd.lPitch ) )[1] = rand() % 256 ;
( ( primary_buffer + x * 3 + y * ddsd.lPitch ) )[2] = rand() % 256 ;
}
}
else
if( ddraw->getPixelFormat() == 16 )
{
for( int index = 0; index < 10; index ++ )
{
int x = rand() % ( client.right - client.left ) + client.left;
int y = rand() % ( client.bottom - client.top ) + client.top;
USHORT color = _RGB32BIT( 0, rand() % 256, rand() % 256, rand() % 256 );
* ( ( USHORT * ) ( primary_buffer + x * 4 + y * ddsd.lPitch ) ) = color;
}
}
else
{
for( int index = 0; index < 10; index ++ )
{
int x = rand() % ( client.right - client.left ) + client.left;
int y = rand() % ( client.bottom - client.top ) + client.top;
UCHAR color = rand() % 256;
primary_buffer[x + y * ddsd.lPitch] = color;
}
}
ddraw->getPrimarySurface()->Unlock( NULL );
Sleep( 1 );
8位模式时却不对,只占了左侧一部分。
但是改为全屏,却是可以的,邪门了
接下来,就是查找实际的客户区,或许与这个有关系。
这里在T3DCONSOLE2中的main()函数里面了。
加上以下代码后,窗口根本显示不出来了,废了,
if( WINDOWED_APP )
{
RECT window_rect = { 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
AdjustWindowRectEx( & window_rect, GetWindowStyle( main_window_handle ), GetMenu( main_window_handle ) != NULL,
GetWindowExStyle( main_window_handle ) );
// window_client_x0 = -window_rect.left;
// window_client_y0 = -window_rect.top;
MoveWindow( main_window_handle, CW_USEDEFAULT, CW_USEDEFAULT, window_rect.right - window_rect.left,
window_rect.bottom - window_rect.top, TRUE );
ShowWindow( main_window_handle, SW_SHOW );
}
加了个窗口的裁剪器 LPDIRECTDRAWCLIPPER m_lpddclipperwin;
if( m_bWindowed == true )
{
m_lpdd->CreateClipper( 0, & m_lpddclipperwin, NULL );
m_lpddclipperwin->SetHWnd( 0, m_hWnd );
m_lpddsprimary->SetClipper( m_lpddclipperwin );
}
终于OK了,因为书上的代码不对,而光盘上的代码才是正确的
正确代码如下:
// resize the window so that client is really width x height
if (WINDOWED_APP)
{
// now resize the window, so the client area is the actual size requested
// since there may be borders and controls if this is going to be a windowed app
// if the app is not windowed then it won't matter
RECT window_rect = {0,0,WINDOW_WIDTH-1,WINDOW_HEIGHT-1};
// make the call to adjust window_rect
AdjustWindowRectEx(&window_rect,
GetWindowStyle(main_window_handle),
GetMenu(main_window_handle) != NULL,
GetWindowExStyle(main_window_handle));
// save the global client offsets, they are needed in DDraw_Flip()
window_client_x0 = -window_rect.left;
window_client_y0 = -window_rect.top;
// now resize the window with a call to MoveWindow()
MoveWindow(main_window_handle,
0, // x position
0, // y position
window_rect.right - window_rect.left, // width
window_rect.bottom - window_rect.top, // height
FALSE);
// show the window, so there's no garbage on first render
ShowWindow(main_window_handle, SW_SHOW);
} // end if windowed
不禁感慨,窗口确实要小心测试。
- 2013年8月27日星期一(DEMO7-19窗口的裁剪等)
- 2013年8月20日星期二(DEMO7-19DX与GDI混合使用)
- 2014年2月20日星期四(DEMO7-5)
- 2013年8月19日星期一(demo7_16,色彩旋转)
- 2011年12月19日 星期一(oracle读书笔记)
- 2013年9月16日星期一(DEMO8_8,多边形)
- 2010年4月19日星期一
- 2013年9月23日星期一
- 2009年8月10日---星期一
- 2017年8月7日 星期一
- 2017年8月14日 星期一
- 2017年8月21日 星期一
- 8月23日(星期一)
- 2013年9月2日星期一(8-4,平移和旋转)
- 2013年4月10日星期三 (DEMO7——6使用blitter)
- 2014年1月14日(DEMO7-2,加载PLG)
- 2014年2月14日星期五(DEMO7-4,3D坦克)
- 2014年2月21日星期五(DEMO7-6战区漫步)
- 详解iOS应用程序内使用IAP/StoreKit付费、沙盒(SandBox)测试、创建测试账号流程
- 不再以讹传讹,GET和POST的真正区别
- C++中const用法总结
- Android之內置、外置SDCard
- 进程上下文与中断上下文
- 2013年8月27日星期一(DEMO7-19窗口的裁剪等)
- Android核心基础(十一)
- php 对于utf-8 格式下 substr出现截取乱码的处理
- android开发中自适应屏幕分辨率总结
- 推荐引擎分类介绍
- 一台电脑安装多个版本的jdk
- 关于strcpy
- 兜兜轉轉--閒話聊UNION
- hdu_4602 Partition