📄 csdn_文档中心_directdraw6的初级编程应用 —— 配合实例讲解,让你迅速入门.htm
字号:
LPCSTR szBitmap);<BR>extern IDirectDrawSurface4
*DDLoadBitmap(IDirectDraw4 *pdd, LPCSTR szBitmap, int dx, int
dy);<BR>extern
HRESULT
DDReLoadBitmap(IDirectDrawSurface4 *pdds, LPCSTR
szBitmap);<BR>extern
HRESULT
DDCopyBitmap(IDirectDrawSurface4 *pdds, HBITMAP hbm, int x, int y,
int dx, int dy);<BR>extern
DWORD
DDColorMatch(IDirectDrawSurface4 *pdds, COLORREF rgb);<BR>extern
HRESULT
DDSetColorKey(IDirectDrawSurface4 *pdds, COLORREF rgb);</P>
<P>#ifdef __cplusplus<BR>}<BR>#endif /* __cplusplus */</P>
<P><BR>-> DDLoadPalette(IDirectDraw4 *pdd, LPCSTR szBitmap):
<BR>从Bitmap文件中读出调色板信息,并将此信息交送于IDirectDraw4的对象.<BR>1)参数IDirectDraw4
*是IDirectDraw4的对象指针.<BR>2)参数LPCSTR,是Bitmap文件全名.<BR>3)使用实例:<BR>
g_pDDPal = DDLoadPalette(g_pDD,
"C:\\han\\mybitmap1.bmp");<BR> if
(g_pDDPal)<BR>
g_pDDSPrimary->SetPalette(g_pDDPal);<BR>4)详情请参阅DDEX3-5.CPP</P>
<P>->DDLoadBitmap(IDirectDraw4 *pdd, LPCSTR szBitmap, int dx, int
dy):<BR>创建一块含有指定Bitmap的IDirectDrawSurface4对象,先创建一块足以容纳指定Bitmap的IDirectDrawSurface4<BR>对象.再将Bitmap读入内存.<BR>1)参数IDirectDraw4
*是对象指针.<BR>2)参数LPCSTR,是Bitmap文件全名.<BR>3)dx,
dy表示Bitmap大小.<BR>4)使用实例:<BR> g_pDDSOne = DDLoadBitmap(g_pDD,
"C:\\han\\mybitmap.bmp", 640, 490);<BR>
if(g_pDDSOne == NULL)<BR>
{<BR> //
Abort the program.<BR> }<BR>5)没有实例,多试试.</P>
<P>->DDReLoadBitmap(IDirectDrawSurface4 *pdds, LPCSTR
szBitmap):<BR>把一块Bitmap读入一个指定的IDirectDrawSurface4对象指针.<BR>1)参数IDirectDrawSurface4
*是对象指针,将接收Bitmap.<BR>2)参数LPCSTR,是Bitmap文件全名.<BR>3)使用实例:<BR>
hRet = DDReLoadBitmap(g_pDDSOne, "C:\\han\\mybitmap.bmp");<BR>
if(FAILED(hret))<BR>
{<BR> //
Abort the program.<BR>
}<BR>4)详情请参阅DDEX3-5.CPP<BR>5)我用此函数最多.</P>
<P>->DDCopyBitmap(IDirectDrawSurface4 *pdds, HBITMAP hbm, int x,
int y, int dx, int dy):<BR>You don't need to know.</P>
<P>->DDColorMatch(IDirectDrawSurface4 *pdds, COLORREF
rgb):<BR>You don't need to know.</P>
<P>->DDSetColorKey(IDirectDrawSurface4 *pdds, COLORREF
rgb):<BR>在指定的参数IDirectDrawSurface4的对象指针上设置一transparent
Colorkey.<BR>1)参数IDirectDrawSurface4
*是对象指针,将接收ColorKey.<BR>2)COLORREF, Colorkey的数值.<BR>3)使用实例:<BR>
hRet = DDReLoadBitmap(g_pDDSOne, "C:\\han\\mybitmap.bmp");<BR>
if(FAILED(hret))<BR>
{<BR> //
Abort the program.<BR>
}<BR>4)详情请参阅DDEX3-5.CPP<BR>5)我用此函数也很多.</P>
<P>For more information about those functions, you better observe
the examples Microsoft provided (DDEX1 - DDEX5) for<BR>details.It is
the easy way. All the implementations about those functions is in
DDUTIL.CPP file.</P>
<P>6.BLIT, FLIP, &Color
fill.<BR>这三个应用是DirectDraw的主要应用.其功能为在BackBuffer上画上Bitmap图块,或填上一定的颜色,<BR>再翻到屏幕上.所用函数为:<BR>1>.Blt和BltFast在BackBuffer上画上Bitmap图块.</P>
<P><A href="file://BltFast/">file://BltFast/</A> Example;<BR>RECT
rcRect;</P>
<P>rcRect.left = 0;<BR>rcRect.top = 0;<BR>rcRect.right =
640;<BR>rcRect.bottom = 480; </P>
<P> while(1) { <BR> ddrval =
g_pDDSBack->BltFast(0, 0, g_pDDSOne, &rcRect,
DDBLTFAST_WAIT); <BR> if(ddrval ==
DD_OK) <BR>
{<BR>
break;<BR> }<BR> else if(ddrval
== DDERR_SURFACELOST)<BR>
{<BR> // use
the restore all
function!<BR>
RestoreAll();<BR> }<BR>} </P>
<P>我常用Blt function:</P>
<P><A href="file://Blt/">file://Blt/</A> Example;<BR>RECT srcRect =
{0, 0, 640, 480};<BR>RECT dstRect = {0, 0, 640, 480};</P>
<P>DDBLTFX tempFX; // you will fail if you don't have
this!<BR>tempFX.dwsize = sizeof(DDBLTFX); // you will fail if you
don't have this!</P>
<P> while(1) { <BR> ddrval =
g_pDDSBack->Blt(dstRect, g_pDDSOne, srcRect, DDBLT_WAIT,
&tempFX); <BR> if(ddrval ==
DD_OK) <BR>
{<BR>
break;<BR> }<BR> else if(ddrval
== DDERR_SURFACELOST)<BR>
{<BR> // use
the restore all
function!<BR>
RestoreAll();<BR> }<BR> else
if(ddrval != DDERR_WASSTILLDRAWING)<BR>
{<BR>
break;<BR> }<BR>} </P>
<P>若想使用透明色(COLORKEY),改DDBLTFAST_WAIT(BltFast的最后一个参数)为<BR>DDBLTFAST_WAIT|DDBLTFAST_SRCCOLORKEY. 改DDBLT_WAIT(Blt的倒数第二个参数)为<BR>DDBLT_WAIT
| DDBLT_COLORSRC.</P>
<P>2.>用Blt在BackBuffer上填充颜色,(我从未成功过).</P>
<P>RECT dstRect = {0, 0, 640, 480};<BR>DDBLTFX tempFX; // you will
fail if you don't have this!<BR>tempFX.dwsize = sizeof(DDBLTFX); //
you will fail if you don't have this!<BR>tempFX.dwFillColor = RGB(0,
255, 0); // green.</P>
<P> while(1) { <BR> ddrval =
g_pDDSBack->Blt(dstRect, NULL, NULL, DDBLT_WAIT |
DDBLT_COLORFILL, &tempFX); <BR> if(ddrval ==
DD_OK) <BR>
{<BR>
break;<BR> }<BR> else if(ddrval
== DDERR_SURFACELOST)<BR>
{<BR> // use
the restore all
function!<BR>
RestoreAll();<BR> }<BR> else
if(ddrval != DDERR_WASSTILLDRAWING)<BR>
{<BR>
break;<BR> }<BR>} </P>
<P>这个例码将在dstRect(0, 0, 640,
480)的长方形中填充绿色.长方形的大小和位置以你定义<BR>的RECT对象确定.用Blt和BltFast的几个弱点是:<BR>1)当dstRect(目标长方块)不和srcRect(源长方块)大小一致,Blt和BltFast将十分慢.<BR>2)当dstRect部分超出屏幕,如屏幕大小640X480,你想在长方块{500,
500, 800, 600}中显示<BR>图块,此图块不将处显,因为你定义的图块在屏幕以外!解决方法将在续篇(Advanced
Section)中提出.</P>
<P>3.>使用Flip:<BR>将准备好的BackBuffer翻到屏幕上,原来的Primar
Surface变成BackBuffer.<BR> while(1) { <BR>
ddrval = g_pDDSPrimary->Flip(NULL, DDFLIP_WAIT);
<BR> if(ddrval == DD_OK)
<BR>
{<BR>
break;<BR> }<BR> else if(ddrval
== DDERR_SURFACELOST)<BR>
{<BR> // use
the restore all
function!<BR>
RestoreAll();<BR> }<BR> else
if(ddrval != DDERR_WASSTILLDRAWING)<BR>
{<BR>
break;<BR> }<BR>}</P>
<P>4.总结:<BR>1) 建立暂时的IDirectDraw对象.<BR>2)
用COM中的QueryInterface来建立IDirectDraw4的对象.<BR>3) SetCooperativeLevel
(视窗或全屏).<BR>4) SetDisplayMode(屏幕大小,色度,刷新速度).<BR>5) 建立primary
surface(屏幕显示内存),back buffer(幕后显示内存),和off-screen
sufaces(备用显示内存,用于<BR>存储图块).<BR>6)
使用ddutil文件中的函数来读入Bitmap,设置ColorKey(当你进行Blt操作,这种颜色将不被显示).<BR>7)
用Blt和BltFast将图块打入back buffer,用Flip来将准备好的back buffer翻成primary
surface.原有的<BR>primary surface翻成back buffer,等待下一轮Blt和BltFast的调用.</P>
<P>这些是DirectDraw版本6中的基本操作!我将写一个续篇(Advanced Section).Enjoy
programming!<BR>请大胆提出问题,写信给我或留言于留言板!感谢Doug Klopfenstein!他的Basic
DirectDraw
Programming<BR>(谭翁编译了这一文章!)给我很大帮助.<BR></P><BR></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
<TABLE align=center bgColor=#006699 border=0 cellPadding=0 cellSpacing=0
width=770>
<TBODY>
<TR bgColor=#006699>
<TD align=middle bgColor=#006699 id=white><FONT
color=#ffffff>对该文的评论</FONT></TD>
<TD align=middle>
<SCRIPT
src="CSDN_文档中心_DirectDraw6的初级编程应用 —— 配合实例讲解,让你迅速入门.files/readnum.htm"></SCRIPT>
</TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1
width=770>
<TBODY>
<TR>
<TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16
hspace=1
src="CSDN_文档中心_DirectDraw6的初级编程应用 —— 配合实例讲解,让你迅速入门.files/ico_pencil.gif"
width=16> </SPAN> linuswu <I>(2001-12-17
10:48:35)</I> </TD></TR>
<TR>
<TD bgColor=#ffffff colSpan=3 width=532><BR>是否一定要通过ddutil文件中的函数来读入Bitmap,
如果是直接是一块内存, 如:有一内存 void *
pvFrame用于存放一帧的图象,通过DirectDraw显示,是否也要用CreateDIBSection()
先生成一Bitmap文件,还是可以直接将这一内存读入页面中????? 谢谢,我比较急的, 可以发邮件给我吗?( zxw_cn@sina.com.cn
) 再次谢谢! <BR></TD></TR></TBODY></TABLE><BR>
<DIV align=center>
<TABLE align=center bgColor=#cccccc border=0 cellPadding=2 cellSpacing=1
width=770>
<TBODY>
<TR>
<TH bgColor=#006699 id=white><FONT
color=#ffffff>我要评论</FONT></TH></TR></TBODY></TABLE></DIV>
<DIV align=center>
<TABLE border=0 width=770>
<TBODY>
<TR>
<TD>你没有登陆,无法发表评论。 请先<A
href="http://www.csdn.net/member/login.asp?from=/Develop/read_article.asp?id=3409">登陆</A>
<A
href="http://www.csdn.net/expert/zc.asp">我要注册</A><BR></TD></TR></TBODY></TABLE></DIV><BR>
<HR noShade SIZE=1 width=770>
<TABLE border=0 cellPadding=0 cellSpacing=0 width=500>
<TBODY>
<TR align=middle>
<TD height=10 vAlign=bottom><A
href="http://www.csdn.net/intro/intro.asp?id=2">网站简介</A> - <A
href="http://www.csdn.net/intro/intro.asp?id=5">广告服务</A> - <A
href="http://www.csdn.net/map/map.shtm">网站地图</A> - <A
href="http://www.csdn.net/help/help.asp">帮助信息</A> - <A
href="http://www.csdn.net/intro/intro.asp?id=2">联系方式</A> - <A
href="http://www.csdn.net/english">English</A> </TD>
<TD align=middle rowSpan=3><A
href="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202001032100010"><IMG
border=0 height=48
src="CSDN_文档中心_DirectDraw6的初级编程应用 —— 配合实例讲解,让你迅速入门.files/biaoshi.gif"
width=40></A></TD></TR>
<TR align=middle>
<TD vAlign=top>百联美达美公司 版权所有 京ICP证020026号</TD></TR>
<TR align=middle>
<TD vAlign=top><FONT face=Verdana>Copyright © CSDN.net, Inc. All rights
reserved</FONT></TD></TR>
<TR>
<TD height=15></TD>
<TD></TD></TR></TBODY></TABLE></DIV>
<DIV></DIV><!--内容结束//--><!--结束//--></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -