|
|
小弟刚学DirectX编程,想用DirectDraw写个透明的效果
请高人提供一下DirectDraw里实现透明效果一个简单的程序的原代码(最好Win32架构,MFC的也不错),谢谢啦!
大哥门,指点一下,自己胡写的代码有错 吗?
其中lpDDtransparence和lpDDbpic为存有两张图的DirectDrawSurface指针,想将第二张图做背景,把第一张图透明显示
在屏幕(800*600*16模式)上:
#define _RGB16BIT565(r,g,b) ((b%32)+((g%32)<<6)+((r%32)<<11))
DDSURFACEDESC2 ddsd1, ddsd2; //DirectDraw页面描述
memset(&ddsd1,0, sizeof(ddsd1)); //ddsd用前要清空
ddsd1.dwSize = sizeof(ddsd1); //DirectDraw中的对象都要这样
memset(&ddsd2,0,sizeof(ddsd2));
ddsd2.dwSize = sizeof(ddsd2);
lpDDtransparence->Lock(NULL, &ddsd1, DDLOCK_WAIT, NULL);
lpDDbpic->Lock(NULL,&ddsd2, DDLOCK_WAIT, NULL); //Lock!
USHORT *Bitmap = (WORD*)ddsd1.lpSurface;
int lpitch16=(int)(ddsd1.lPitch>>1);
USHORT *Bitmap2 = (WORD*)ddsd2.lpSurface;
int rgmask=0xffe0; //将r,g颜色遮盖掉
int rmask=0xf800; //将r颜色遮盖掉
int pos=0;
for (int y=0;y<600; y++)
{
for (int x=0; x<800; x++)
{
//对第一个DirectDraw页面分色
int b=(int)(Bitmap[pos]&rgmask);
int g=(int)((Bitmap[pos]&rmask)>>5);
int r=(int)(Bitmap[pos]>>11);
//对第二个DirectDraw页面分色
int r2=(int)(Bitmap2[pos]>>11);
int g2=(int)((Bitmap2[pos]&rmask)>>5);
int b2=(int)(Bitmap2[pos]&rgmask);
r =(r-r2)>>1+r; //改B
g=(g-g2>>6)>>1+g; //改G
b=(b-b2)>>1+b; //改R
Bitmap[pos]=_RGB16BIT565(r,g,b);
pos++; //到下一个R处
}
pos+=lpitch16;
}
lpDDtransparence->Unlock(NULL);
lpDDbpic->Unlock(NULL); //Unlock!
请高人提供一下DirectDraw里实现透明效果一个简单的程序的原代码(最好Win32架构,MFC的也不错),谢谢啦 |
|