游戏开发论坛

 找回密码
 立即注册
搜索
查看: 4244|回复: 15

[求助, 讨论] 关于透明色

[复制链接]

50

主题

200

帖子

200

积分

中级会员

Rank: 3Rank: 3

积分
200
发表于 2007-3-24 14:51:00 | 显示全部楼层 |阅读模式

基本概念我是知道的. 绝大多数计算机硬件都是支持的.

DX直接帮你写好方程了

问题来了, 加入在一种不支持透明色的硬件上写需要透明色的游戏, 那么就要通过软件手段完成.

我知道的方法就是设置一个 colorkey, 以此来进行逐点判断. 写入dest buffer.

这样做似乎慢了一些.

很久以前我听说过一个什么位运算的方法, 不知道具体实现方法, 在座的各位可否给一些思路?

谢谢!

86

主题

2251

帖子

2386

积分

金牌会员

Rank: 6Rank: 6

积分
2386
QQ
发表于 2007-3-24 17:58:00 | 显示全部楼层

Re:[求助, 讨论] 关于透明色

用RLE压缩掉透明点快

你说的可以看看这篇http://www.microsoft.com/china/MSDN/library/archives/technic/develop/vb/0125a.asp

50

主题

200

帖子

200

积分

中级会员

Rank: 3Rank: 3

积分
200
 楼主| 发表于 2007-3-24 19:43:00 | 显示全部楼层

Re:[求助, 讨论] 关于透明色

谢谢, 但是我不一定看的懂,看不懂可以问你么?

28

主题

433

帖子

433

积分

中级会员

Rank: 3Rank: 3

积分
433
发表于 2007-3-24 20:33:00 | 显示全部楼层

Re:[求助, 讨论] 关于透明色

这个 就 可以了 吧~~
TransparentBlt
The TransparentBlt function performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source device context into a destination device context.

BOOL TransparentBlt(
  HDC hdcDest,        // handle to destination DC
  int nXOriginDest,   // x-coord of destination upper-left corner
  int nYOriginDest,   // y-coord of destination upper-left corner
  int nWidthDest,     // width of destination rectangle
  int hHeightDest,    // height of destination rectangle
  HDC hdcSrc,         // handle to source DC
  int nXOriginSrc,    // x-coord of source upper-left corner
  int nYOriginSrc,    // y-coord of source upper-left corner
  int nWidthSrc,      // width of source rectangle
  int nHeightSrc,     // height of source rectangle
  UINT crTransparent  // color to make transparent
);
Parameters
hdcDest
[in] Handle to the destination device context.
nXOriginDest
[in] Specifies the x-coordinate, in logical units, of the upper-left corner of the destination rectangle.
nYOriginDest
[in] Specifies the y-coordinate, in logical units, of the upper-left corner of the destination rectangle.
nWidthDest
[in] Specifies the width, in logical units, of the destination rectangle.
hHeightDest
[in] Handle to the height, in logical units, of the destination rectangle.
hdcSrc
[in] Handle to the source device context.
nXOriginSrc
[in] Specifies the x-coordinate, in logical units, of the source rectangle.
nYOriginSrc
[in] Specifies the y-coordinate, in logical units, of the source rectangle.
nWidthSrc
[in] Specifies the width, in logical units, of the source rectangle.
nHeightSrc
[in] Specifies the height, in logical units, of the source rectangle.
crTransparent
[in] The RGB color in the source bitmap to treat as transparent.
Return Values
If the function succeeds, the return value is TRUE.

If the function fails, the return value is FALSE.

Windows NT/2000/XP: To get extended error information, call GetLastError.

Remarks
The TransparentBlt function works with compatible bitmaps (DDBs).

The TransparentBlt function supports all formats of source bitmaps. However, for 32 bpp bitmaps, it just copies the alpha value over. Use AlphaBlend to specify 32 bits-per-pixel bitmaps with transparency.

If the source and destination rectangles are not the same size, the source bitmap is stretched to match the destination rectangle. When the SetStretchBltMode function is used, the iStretchMode modes of BLACKONWHITE and WHITEONBLACK are converted to COLORONCOLOR for the TransparentBlt function.

The destination device context specifies the transformation type for the destination coordinates. The source device context specifies the transformation type for the source coordinates.

TransparentBlt does not mirror a bitmap if either the width or height, of either the source or destination, is negative.

Windows 95/98: TransparentBlt contains a memory leak that can exhaust system resources. To draw a transparent bitmap using BitBlt, see Knowledge Base article 79212.

Windows 98/Me, Windows 2000/XP: When used in a multiple monitor system, both hdcSrc and hdcDest must refer to the same device or the function will fail. To transfer data between DCs for different devices, convert the memory bitmap to a DIB by calling GetDIBits. To display the DIB to the second device, call SetDIBits or StretchDIBits.

Requirements
  Windows NT/2000/XP: Included in Windows 2000 and later.
  Windows 95/98/Me: Included in Windows 98 and later.
  Header: Declared in Wingdi.h; include Windows.h.
  Library: Use Msimg32.lib.

3

主题

37

帖子

37

积分

注册会员

Rank: 2

积分
37
发表于 2007-3-28 22:06:00 | 显示全部楼层

Re:[求助, 讨论] 关于透明色

gameres上已经有一篇rle算法的翻译文,在2d图形处理里。

50

主题

200

帖子

200

积分

中级会员

Rank: 3Rank: 3

积分
200
 楼主| 发表于 2007-3-29 08:39:00 | 显示全部楼层

Re:[求助, 讨论] 关于透明色

谢谢楼上

50

主题

200

帖子

200

积分

中级会员

Rank: 3Rank: 3

积分
200
 楼主| 发表于 2007-3-29 08:51:00 | 显示全部楼层

Re:[求助, 讨论] 关于透明色

具体名字叫什么? 我怎么没有找到?

86

主题

2251

帖子

2386

积分

金牌会员

Rank: 6Rank: 6

积分
2386
QQ
发表于 2007-3-29 10:02:00 | 显示全部楼层

Re:[求助, 讨论] 关于透明色

看不懂慢慢看,这样的文不少,用RLE做关键字搜索就能找到很多

3

主题

37

帖子

37

积分

注册会员

Rank: 2

积分
37
发表于 2007-3-29 10:43:00 | 显示全部楼层

Re:[求助, 讨论] 关于透明色

http://dev.gameres.com/Program/Abstract/Thinking/RLE.htm

8

主题

716

帖子

716

积分

高级会员

Rank: 4

积分
716
发表于 2007-3-29 14:57:00 | 显示全部楼层

Re:[求助, 讨论] 关于透明色

LZ可能是想找的是mask实现的方法,所谓的掩模
姑且把它叫做2-pass方法
先将掩模以AND方式BLT上去
再将原图以XOR方式BLT到同一处
即可实现透明效果
www.vckbase.com好象有现成的源码
效果跟WINAPI的TransparentBlt一样
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-4-12 15:56

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表