D3D 中的图片的淡入淡出效果?

cytlyy 2009-03-09 04:19:26
首先说明一下,我是在windows mobile下用Direct3d mobile实现mobile下的3d效果的,现在我想问一下如何实现一幅图片的的淡入淡出效果(图片是先load到surface然后StretchRect到要渲染的TEXTURE上的 ),我知道最好的方法应该是用模板缓存技术。但对这个不太熟悉。希望达人指点,最好有些代码,这样容易理解,方便我一直到windows mobile上。谢谢!
...全文
488 25 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
IONPhantom 2009-03-11
  • 打赏
  • 举报
回复
摘自DXSDK

D3DBLEND
Defines the supported blend mode.

typedef enum D3DBLEND
{
D3DBLEND_ZERO = 1,
D3DBLEND_ONE = 2,
D3DBLEND_SRCCOLOR = 3,
D3DBLEND_INVSRCCOLOR = 4,
D3DBLEND_SRCALPHA = 5,
D3DBLEND_INVSRCALPHA = 6,
D3DBLEND_DESTALPHA = 7,
D3DBLEND_INVDESTALPHA = 8,
D3DBLEND_DESTCOLOR = 9,
D3DBLEND_INVDESTCOLOR = 10,
D3DBLEND_SRCALPHASAT = 11,
D3DBLEND_BOTHSRCALPHA = 12,
D3DBLEND_BOTHINVSRCALPHA = 13,
D3DBLEND_BLENDFACTOR = 14,
D3DBLEND_INVBLENDFACTOR = 15,
D3DBLEND_SRCCOLOR2 = 16,
D3DBLEND_INVSRCCOLOR2 = 17,
D3DBLEND_FORCE_DWORD = 0x7fffffff,
} D3DBLEND, *LPD3DBLEND;
Constants
D3DBLEND_ZERO
Blend factor is (0, 0, 0, 0).
D3DBLEND_ONE
Blend factor is (1, 1, 1, 1).
D3DBLEND_SRCCOLOR
Blend factor is (Rs, Gs, Bs, As).
D3DBLEND_INVSRCCOLOR
Blend factor is (1 - Rs, 1 - Gs, 1 - Bs, 1 - As).
D3DBLEND_SRCALPHA
Blend factor is (As, As, As, As).
D3DBLEND_INVSRCALPHA
Blend factor is ( 1 - As, 1 - As, 1 - As, 1 - As).
D3DBLEND_DESTALPHA
Blend factor is (Ad Ad Ad Ad).
D3DBLEND_INVDESTALPHA
Blend factor is (1 - Ad 1 - Ad 1 - Ad 1 - Ad).
D3DBLEND_DESTCOLOR
Blend factor is (Rd, Gd, Bd, Ad).
D3DBLEND_INVDESTCOLOR
Blend factor is (1 - Rd, 1 - Gd, 1 - Bd, 1 - Ad).
D3DBLEND_SRCALPHASAT
Blend factor is (f, f, f, 1); where f = min(As, 1 - Ad).
D3DBLEND_BOTHSRCALPHA
Obsolete. Starting with DirectX 6, you can achieve the same effect by setting the source and destination blend factors to D3DBLEND_SRCALPHA and D3DBLEND_INVSRCALPHA in separate calls.
D3DBLEND_BOTHINVSRCALPHA
Source blend factor is (1 - As, 1 - As, 1 - As, 1 - As), and destination blend factor is (As, As, As, As); the destination blend selection is overridden. This blend mode is supported only for the D3DRS_SRCBLEND render state.
D3DBLEND_BLENDFACTOR
Constant color blending factor used by the frame-buffer blender. This blend mode is supported only if D3DPBLENDCAPS_BLENDFACTOR is set in the SrcBlendCaps or DestBlendCaps members of D3DCAPS9.
D3DBLEND_INVBLENDFACTOR
Inverted constant color-blending factor used by the frame-buffer blender. This blend mode is supported only if the D3DPBLENDCAPS_BLENDFACTOR bit is set in the SrcBlendCaps or DestBlendCaps members of D3DCAPS9.
D3DBLEND_SRCCOLOR2
Blend factor is (PSOutColor[1]r, PSOutColor[1]g, PSOutColor[1]b, not used). See Render Target Blending. Differences between Direct3D 9 and Direct3D 9Ex:

This flag is available in Direct3D 9Ex only.


D3DBLEND_INVSRCCOLOR2
Blend factor is (1 - PSOutColor[1]r, 1 - PSOutColor[1]g, 1 - PSOutColor[1]b, not used)). See Render Target Blending. Differences between Direct3D 9 and Direct3D 9Ex:

This flag is available in Direct3D 9Ex only.


D3DBLEND_FORCE_DWORD
Forces this enumeration to compile to 32 bits in size. Without this value, some compilers would allow this enumeration to compile to a size other than 32 bits. This value is not used.
Remarks
In the preceding member descriptions, the RGBA values of the source and destination are indicated by the s and d subscripts.

The values in this enumerated type are used by the following render states:

D3DRS_DESTBLEND
D3DRS_SRCBLEND
D3DRS_DESTBLENDALPHA
D3DRS_SRCBLENDALPHA
See D3DRENDERSTATETYPE

Render Target Blending
Direct3D 9Ex has improved text rendering capabilities. Rendering clear-type fonts would normally require two passes. To eliminate the second pass, a pixel shader can be used to output two colors, which we can call PSOutColor[0] and PSOutColor[1]. The first color would contain the standard 3 color components (RGB). The second color would contain 3 alpha components (one for each component of the first color).

These new blending modes are only used for text rendering on the first render target.

KevinYuen 2009-03-11
  • 打赏
  • 举报
回复
D3DRS_BLENDFACTOR这个不是D3DBLEND
cytlyy 2009-03-11
  • 打赏
  • 举报
回复
windows mobile 6.0上就支持这么多。
KevinYuen 2009-03-10
  • 打赏
  • 举报
回复
R5G6B5不支持
详细的你可以看DX文档中的Texture Alpha 文章,讲的很详细,吃饭咯
cytlyy 2009-03-10
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 KevinYuen 的回复:]
DWORD color是什么格式的,有无Alpha通道,如果是A8的改变表示Alpha通道的8位即可
[/Quote]
怎么看是什么格式的?不过我用D3DMXCreateTexture( g_pd3dmDevice,
MaterialWidth,MaterialHeight, 0, D3DMUSAGE_RENDERTARGET ,
D3DMFMT_R5G6B5 , texpool, &g_pTexture );
时创建的纹理只能用D3DMFMT_R5G6B5 这个值得参数,不能用D3DMFMT_A8R8G8B8这个值。
KevinYuen 2009-03-10
  • 打赏
  • 举报
回复
DWORD color是什么格式的,有无Alpha通道,如果是A8的改变表示Alpha通道的8位即可
cytlyy 2009-03-10
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 KevinYuen 的回复:]
有没有设置颜色的方法,有就可以.
在渲染之前改变颜色,使用带Alpha通道的颜色格式,将你颜色信息中的a值 递增或者递减~
Windows mobile我没用过,不过原理应该相同的.
如果你使用的颜色格式不支持Alpha那就不能这么实现了~(图片切换?)
[/Quote]
纹理的顶点坐标我是这样定义的:
struct CUSTOMVERTEX
{
FLOAT x, y, z; // The transformed position for the vertex
DWORD color; // The vertex color
FLOAT tu,tv; //texture point
};
顶点颜色在初始化时就已经指定了。
比如 vertices[0].color=0x00000000;
vertices[0].tu= 0.0f;
vertices[0].tv=1.0f;
vertices[0].x=-(xCoordinate/yCoordinate)*2.0f-MoveLeft;
vertices[0].y=-2.5f
vertices[0].z=-0.0f;
KevinYuen 2009-03-10
  • 打赏
  • 举报
回复
有没有设置颜色的方法,有就可以.
在渲染之前改变颜色,使用带Alpha通道的颜色格式,将你颜色信息中的a值 递增或者递减~
Windows mobile我没用过,不过原理应该相同的.
如果你使用的颜色格式不支持Alpha那就不能这么实现了~(图片切换?)
KevinYuen 2009-03-10
  • 打赏
  • 举报
回复
有没有设置颜色的方法,有就可以.
在渲染之前改变颜色,使用带Alpha通道的颜色格式,将你颜色信息中的a值 递增或者递减~
Windows mobile我没用过,不过原理应该相同的.
如果你使用的颜色格式不支持Alpha那就不能这么实现了~(图片切换?)
cytlyy 2009-03-10
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 KevinYuen 的回复:]
举一个DXUT里的例子:

每次渲染调用这个方法,最后一个参数就是当前的渐变颜色:
m_pSprite->Draw( pTextureNode->pTexture, &rcTexture, NULL, &vPos, pElement->TextureColor.Current );

TextureColor.Current可以通过在每次渲染之前进行一定的改变,
SrcClr ----( CurrentClr ) ---- DestClr
[/Quote]
这个ID3DXSprite这个接口在Windows mobile不支持这个接口,所以 没法用m_pSprite->Draw( pTextureNode->pTexture, &rcTexture, NULL, &vPos, pElement->TextureColor.Current );
方法。
KevinYuen 2009-03-10
  • 打赏
  • 举报
回复
举一个DXUT里的例子:

每次渲染调用这个方法,最后一个参数就是当前的渐变颜色:
m_pSprite->Draw( pTextureNode->pTexture, &rcTexture, NULL, &vPos, pElement->TextureColor.Current );

TextureColor.Current可以通过在每次渲染之前进行一定的改变,
SrcClr ----( CurrentClr ) ---- DestClr
cytlyy 2009-03-10
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 KevinYuen 的回复:]
在渲染循环中递增透明度从0到255就可以了~
[/Quote]
如何递增透明度,我没有发现这样的接口或者函数啊?
KevinYuen 2009-03-10
  • 打赏
  • 举报
回复
具体的可以参照DXUT中的控件渐变的Blend辅助函数
KevinYuen 2009-03-10
  • 打赏
  • 举报
回复
在渲染循环中递增透明度从0到255就可以了~
cytlyy 2009-03-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 P_hantom 的回复:]
楼住是要整个图片淡入淡出?
如果是的话可以把图片和一个颜色进行混合,每一桢改变一下混合程度就可以,不要用模板缓冲,用在Mobil上的硬件很可能不支持模板缓冲,如果要用软件模拟就太慢了.
[/Quote]
是整幅图片的淡入淡出,我也用了alpha混合的方法,实现了透明,但是透明度是就是那一种状态,所以我想知道如何不断的更新透明度呢。另外模板缓存是支持的,但是好像没什么效果(估计是我不会用)。
IONPhantom 2009-03-10
  • 打赏
  • 举报
回复
你是哪个版本阿?
我这个是2008 8月的

typedef enum D3DBLEND
{
D3DBLEND_ZERO = 1,
D3DBLEND_ONE = 2,
D3DBLEND_SRCCOLOR = 3,
D3DBLEND_INVSRCCOLOR = 4,
D3DBLEND_SRCALPHA = 5,
D3DBLEND_INVSRCALPHA = 6,
D3DBLEND_DESTALPHA = 7,
D3DBLEND_INVDESTALPHA = 8,
D3DBLEND_DESTCOLOR = 9,
D3DBLEND_INVDESTCOLOR = 10,
D3DBLEND_SRCALPHASAT = 11,
D3DBLEND_BOTHSRCALPHA = 12,
D3DBLEND_BOTHINVSRCALPHA = 13,
D3DBLEND_BLENDFACTOR = 14,
D3DBLEND_INVBLENDFACTOR = 15,
D3DBLEND_SRCCOLOR2 = 16,
D3DBLEND_INVSRCCOLOR2 = 17,
D3DBLEND_FORCE_DWORD = 0x7fffffff,
} D3DBLEND, *LPD3DBLEND;
KevinYuen 2009-03-10
  • 打赏
  • 举报
回复
没说完整 D3DRS_BLENDFACTOR是一种可设置的渲染状态类型

你具体的看看D3DRENDERSTATETYPE 这个枚举
cytlyy 2009-03-10
  • 打赏
  • 举报
回复
[Quote=引用 19 楼 KevinYuen 的回复:]
D3DRENDERSTATETYPE
是一种渲染状态
[/Quote]
什么意思??
KevinYuen 2009-03-10
  • 打赏
  • 举报
回复
D3DRENDERSTATETYPE
是一种渲染状态
cytlyy 2009-03-10
  • 打赏
  • 举报
回复
没有类似于D3DRS_BLENDFACTOR这个参数,所有的D3DMBLEND支持的参数如下所示:
typedef enum _D3DMBLEND {
D3DMBLEND_ZERO = 1,
D3DMBLEND_ONE = 2,
D3DMBLEND_SRCCOLOR = 3,
D3DMBLEND_INVSRCCOLOR = 4,
D3DMBLEND_SRCALPHA = 5,
D3DMBLEND_INVSRCALPHA = 6,
D3DMBLEND_DESTALPHA = 7,
D3DMBLEND_INVDESTALPHA = 8,
D3DMBLEND_DESTCOLOR = 9,
D3DMBLEND_INVDESTCOLOR = 10,
D3DMBLEND_SRCALPHASAT = 11,
D3DMBLEND_FORCE_ULONG = 0x7fffffff, // force 32-bit size enum
} D3DMBLEND;
加载更多回复(3)

8,325

社区成员

发帖
与我相关
我的任务
社区描述
游戏开发相关内容讨论专区
社区管理员
  • 游戏开发
  • 呆呆敲代码的小Y
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧