STDMETHOD(LoadFromConfigFile)(/*[in]*/ULONG config_struct_ptr);
STDMETHOD(ReleaseOffScreenPlain)(/*[in]*/ULONG plain_ptr);
STDMETHOD(UnloadBitmapFile)(/*[in]*/ULONG bitmap_file_ptr);
STDMETHOD(CreateOffScreenPlain)(/*[in]*/ULONG plain_ptr,/*[in]*/int nWidth,/*[in]*/int nHeight,/*[in]*/ULONG dwFlags);
STDMETHOD(ShowUnit)(/*[in]*/ULONG plain_ptr,/*[in]*/int x_pos,/*[in]*/int y_pos);
STDMETHOD(CopyBitmapToPlain08)(/*[in]*/ULONG bitmap_file_ptr,/*[in]*/ULONG plain_ptr);
STDMETHOD(LoadBitmapFile)(/*[in]*/ULONG bitmap_file_ptr,/*[in]*/ULONG bitmap_file_name);
STDMETHOD(Wait_Clock)(/*[in]*/double count);
STDMETHOD(Start_Clock)();
STDMETHOD(Flip)();
STDMETHOD(DrawRandPixel_08)(/*[in]*/int nCount);
STDMETHOD(UpdatePalette)(/*[in]*/ULONG lp_palette_entry);
STDMETHOD(SetClipper)(/*[in]*/int nNum,/*[in]*/ULONG lp_rect);
STDMETHOD(UnInit)();
STDMETHOD(Init)(/*[in]*/ULONG hWnd,/*[in]*/int nWidth,/*[in]*/int nHeight,/*[in]*/int nBit);
/*---------------------------------------------------------------------------------
功能:初始化DirectDraw
说明:
返回:成功,0;失败,其它正数值
---------------------------------------------------------------------------------*/
STDMETHODIMP CFreeDirectDraw::Init(ULONG hWnd, int nWidth, int nHeight, int nBit)
{
m_h_wnd = (HWND)hWnd;
m_n_bit = nBit;
m_n_width = nWidth;
m_n_height = nHeight;
/////////////////////////////////////////////////////////
HRESULT result;
DDSCAPS2 caps;
DDSURFACEDESC2 desc;
result = DirectDrawCreateEx( NULL, (void**)&m_dd, IID_IDirectDraw7, NULL );
if( result != DD_OK )
{
m_log.SaveMessage("创建DirectDraw对象失败!");
return 1;
}
result = m_dd->SetCooperativeLevel(m_h_wnd,DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT | DDSCL_ALLOWMODEX );
if( result != DD_OK )
{
m_log.SaveMessage( "设置协调层级失败!" );
return 2;
}
result = m_dd->SetDisplayMode( m_n_width, m_n_height, m_n_bit, 0, 0 );
if( result != DD_OK )
{
m_log.SaveMessage( "设置显示模式失败!" );
return 3;
}
//创建主页面
INIT_STRUCT( desc );
desc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
desc.dwBackBufferCount = 1;
desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
result = m_dd->CreateSurface( &desc, &m_prim_surface, NULL );
if( result != DD_OK )
{
m_log.SaveMessage( "创建主页面失败!" );
return 4;
}
//副缓冲区
memset( &caps, 0, sizeof( caps ) );
caps.dwCaps = DDSCAPS_BACKBUFFER;
result = m_prim_surface->GetAttachedSurface( &caps, &m_back_surface );
if( result != DD_OK )
{
m_log.SaveMessage( "创建次页面失败!" );
return 5;
}
//如果是8bit,就要创建调色板
if( m_n_bit == 8 )
{
if(CreatePalatte() != 0)
{
m_log.SaveMessage( "创建调色板失败!" );
return 6;
}
}
//设置剪切区
RECT rect[] = {0, 0, m_n_width, m_n_height };
if( SetClipper( m_back_surface, 1, rect ) != 0 )
{
m_log.SaveMessage("设置剪切区失败!");
return 7;
}
m_log.SaveMessage( "DirectDraw组件初始化成功!" );
return 0;
}
/*---------------------------------------------------------------------------------
功能:清除DirectDraw资源
说明:
返回:成功,0;失败,其它正数值
---------------------------------------------------------------------------------*/
STDMETHODIMP CFreeDirectDraw::UnInit()
{
SAFE_RELEASE( m_clipper );
SAFE_RELEASE( m_palette );
SAFE_RELEASE( m_back_surface );
SAFE_RELEASE( m_prim_surface );
SAFE_RELEASE( m_dd );
return 0;
}
/*---------------------------------------------------------------------------------
功能:剪切页面
说明:
返回:成功,0;失败,其它正数值
---------------------------------------------------------------------------------*/
STDMETHODIMP CFreeDirectDraw::SetClipper(int nNum, ULONG lp_rect)
{
int nRet;
nRet = SetClipper( m_back_surface, nNum, (LPRECT)lp_rect );
return nRet;
}
/*---------------------------------------------------------------------------------
功能:更新调色板
说明:
返回:成功,0;失败,其它正数值
---------------------------------------------------------------------------------*/
STDMETHODIMP CFreeDirectDraw::UpdatePalette(ULONG lp_palette_entry)
{
int nRet;
nRet = UpdatePalette( (PALETTEENTRY*)lp_palette_entry );
return nRet;
}
/*---------------------------------------------------------------------------------
功能:直接在副页面上画随机的点-------8位
说明:
返回:成功,0;失败,其它正数值
---------------------------------------------------------------------------------*/
STDMETHODIMP CFreeDirectDraw::DrawRandPixel_08(int nCount)
{
int x,y;
int mempitch = 0;
unsigned char* lp_buf = NULL;
HRESULT hr;
int count = nCount;
DDSURFACEDESC2 dd;
INIT_STRUCT( dd );
hr = m_back_surface->Lock(NULL,&dd,DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL);
if(hr != DD_OK)
{
m_log.SaveMessage("锁定表面失败!");
return 1;
}
mempitch = dd.lPitch;
lp_buf = (unsigned char*)dd.lpSurface;
int nBitSize = dd.lPitch * m_n_height;
//清除后缓冲区中的数据
__asm
{
CLD ; clear direction of copy to forward
MOV EAX, 0 ; color goes here
MOV ECX, nBitSize ; number of DWORDS goes here
MOV EDI, lp_buf ; address of line to move data
REP STOSB ; send the pentium X on its way
}
srand( GetTickCount() );
for(int i = 0; i < count; i++ )
{
UCHAR color = rand() % MAX_PALETTE_COLORS;
x = rand() % m_n_width;
y = rand() % m_n_height;
lp_buf[ x + y * mempitch ] = color;
}
hr = m_back_surface->Unlock(NULL);
if(hr != DD_OK)
{
m_log.SaveMessage("解锁定表面失败!");
return 2;
}
return 0;
}
/*---------------------------------------------------------------------------------
功能:切换副页面为主页面
说明:
返回:成功,0;失败,其它正数值
---------------------------------------------------------------------------------*/
STDMETHODIMP CFreeDirectDraw::Flip()
{
while( m_prim_surface->Flip( NULL, DDFLIP_WAIT ) != DD_OK );
return 0;
}
/*---------------------------------------------------------------------------------
功能:开始等待
说明:
返回:成功,0;失败,其它正数值
---------------------------------------------------------------------------------*/
STDMETHODIMP CFreeDirectDraw::Start_Clock()
{
m_clock_count = GetTickCount();
return 0;
}
/*---------------------------------------------------------------------------------
功能:等待
说明:
返回:成功,0;失败,其它正数值
---------------------------------------------------------------------------------*/
STDMETHODIMP CFreeDirectDraw::Wait_Clock(double count)
{
m_clock_count += count;
while( GetTickCount() < m_clock_count );
return 0;
}
/*---------------------------------------------------------------------------------
功能:载入位图
说明:
返回:成功,0;失败,其它正数值
---------------------------------------------------------------------------------*/
STDMETHODIMP CFreeDirectDraw::LoadBitmapFile(ULONG bitmap_file_ptr, ULONG bitmap_file_name)
{
int nRet;
char* szFileName = (char*)bitmap_file_name;
BITMAP_FILE_PTR lp_bitmap = (BITMAP_FILE_PTR)bitmap_file_ptr;
if( szFileName == NULL )
{
return 1;
}
if( lp_bitmap == NULL )
{
return 2;
}
//////////////////////////////////////////////////////////////////////////
FILE* fp = fopen( szFileName, "rb" );
if( fp == NULL )
{
return 3;
}
rewind( fp );
//初始化位图文件结构
memset( lp_bitmap, 0, sizeof( BITMAP_FILE ) );
//读入文件头
fread( &lp_bitmap->m_file_head, sizeof( CHAR ), sizeof( BITMAPFILEHEADER ), fp );
if( lp_bitmap->m_file_head.bfType != BITMAP_ID )
{
fclose( fp );
return 4;
}
//读入位图信息
fread( &lp_bitmap->m_info_head, sizeof( CHAR ), sizeof( BITMAPINFOHEADER ), fp );
if( lp_bitmap->m_info_head.biBitCount == 8 )
{
fread( &lp_bitmap->
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
ATL-DirectX.zip (82个子文件)
ATL写的基于DirectX的游戏引擎
www.cnzz.cn
Game
Game.opt 58KB
Game.dsw 747B
Game.dsp 4KB
Game.plg 1KB
Game.cpp 3KB
Game.h 3KB
Lib
test8.BMP 301KB
Game.exe 152KB
FreeDirect.ini 67B
DirectDraw.log 82B
FreeDirectX.dll 272KB
sourcecodechina.url 76B
GameEngineATL
GameEngineATL.dsp 14KB
GameEngineATL.def 234B
Tools.h 617B
GameEngineATL_i.c 1KB
GameEngineATL.tlb 2KB
GameEngineATLps.mk 526B
FreeDrawDef.h 2KB
resource.h 506B
Ini.cpp 1KB
Tools.cpp 1KB
GameEngineATL.idl 1KB
ImportDirectX.h 323B
Microsoft Visual C++ 6.0.lnk 522B
GameEngineATL.aps 4KB
GameEngineATLps.def 255B
Log.h 634B
GameEngineATL.opt 58KB
Ini.h 712B
StdAfx.cpp 315B
GameEngineATL.dsw 738B
GameEngineATL_p.c 13KB
Log.cpp 2KB
GameEngineATL.plg 2KB
GameEngineATL.cpp 2KB
GameEngineATL.ncb 89KB
StdAfx.h 1KB
FreeDraw.h 2KB
FreeDraw.rgs 657B
dlldata.c 847B
FreeDraw.cpp 9KB
GameEngineATL.rc 3KB
GameEngineATL.h 10KB
FreeDirectX
FreeDirectX.def 230B
FreeDirectX.idl 2KB
FreeDirectX.rc 3KB
Tools.h 617B
FreeDirectX.aps 4KB
ExportFreeDirectX.h 985B
FreeDirectDraw.cpp 19KB
FreeDirectX.dsw 734B
FreeDirectXps.mk 502B
FreeDirectX_i.c 1KB
FreeDirectDrawDef.h 1KB
FreeDirectX.opt 59KB
resource.h 504B
Ini.cpp 1KB
Tools.cpp 1KB
复件 FreeDirectDraw.cpp 18KB
FreeDirectDrawDataStruct.h 834B
FreeDirectX.tlb 4KB
FreeDirectDraw.h 3KB
新建 文本文档.txt 20KB
FreeDirectX_p.c 26KB
FreeDirectX.cpp 2KB
ImportDirectX.h 323B
Microsoft Visual C++ 6.0.lnk 522B
FreeDirectX.plg 4KB
Log.h 805B
FreeDirectX.ncb 137KB
Ini.h 712B
复件 FreeDirectDraw.h 3KB
StdAfx.cpp 315B
FreeDirectX.h 18KB
Log.cpp 3KB
FreeDirectX.dsp 14KB
StdAfx.h 1KB
FreeDirectDraw.rgs 695B
dlldata.c 843B
FreeDirectXps.def 253B
使用说明.CHM 49KB
共 82 条
- 1
资源评论
fanxbl957
- 粉丝: 1919
- 资源: 1145
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功