Windows游戏之Directx装载位图

  • Windows游戏之Directx装载位图已关闭评论
  • 2,193 views
  • A+

Directx初始化后,自动创建了两个Buffer

也就是两个Surface,双缓存技术

记得在windowsGUI绘制绘图

使用了双缓存技术

使用Directx也一样,我们先来创建两个surface

先初始化Direct3d

加入两个全局变量

然后在相应的位置插入代码

在Game_Init函数中创建了Device后

这里先使用GetBackBuffer

获取显示卡的缓存表面

然后用CreateOffscreenPlainSurface创建一个离屏表面

参数

参数

surface的简单使用

随机颜色的RGB值

使用函数ColorFill填充离屏表面

随机窗口内的矩形块

将离屏表面传输到后台缓冲区中

然后显示出来

效果如下

Windows游戏之Directx装载位图

下面开始加载位图

引入Directx扩展库头文件

链接扩展库

在项目目录下放一张3.PNG

修改代码,在创建离屏表面后加

然后修改Game_Run,注释掉Scene中间的代码

直接加入

运行就可以看到图片渲染出来了

参数

  • pDestSurface [in]
  • Type: LPDIRECT3DSURFACE9    ​    ​要加载到表面的指针
  • pDestPalette [in]
  • Type: const PALETTEENTRY*    ​    ​Pointer to a PALETTEENTRY structure, the destination palette of 256 colors or NULL.(什么目的调色板,不知道什么鬼,为NULL)
  • pDestRect [in]
  • Type: const RECT*    ​    指定表面的矩形位置. 设置为 NULL 则为整个表面
  • pSrcFile [in]
  • Type: LPCTSTR    ​    ​文件名
  • pSrcRect [in]
  • Type: const RECT*    ​    指定图片的矩形位置,设为NULL则为整个图片
  • Filter [in]
  • Type: DWORD    ​    ​结合一个或多个 D3DX_FILTER 控制图片怎么样过滤。 指定D3DX_DEFAULT 等同于指定 D3DX_FILTER_TRIANGLE | D3DX_FILTER_DITHER.
  • ColorKey [in]
  • Type: D3DCOLOR    ​    ​D3DCOLOR value to replace with transparent black, or 0 to disable the colorkey. This is always a 32-bit ARGB color, independent of the source image format. Alpha is significant and should usually be set to FF for opaque color keys Thus, for opaque black, the value would be equal to 0xFF000000.
  • pSrcInfo [in, out]
  • Type: D3DXIMAGE_INFO*    ​    ​Pointer to a D3DXIMAGE_INFO structure to be filled with a description of the data in the source image file, or NULL.

    ​    (哦米拖佛,设为NULL吧)