ochensati
05-30-2002, 03:12 PM
I am putting a wallpaper on a wall and need to be able to block out the
windows and doors and what not. I cannot simply put a texture on the wall as the user is going to be stretching the draw rectangle down the wall.
So my question is how do I use masks with direct draw surfaces? I have all the surfaces initialized, have a back on white image of the wall to use as a mask, I simply cannot find the equivelent of vbSRCCOPY, vbSRCAND...
I tried to use bitblt, but the number of problems that were turning up made it nearly crazy to continue to try that.
AndreRyan
05-31-2002, 04:51 AM
Public Sub CreateSurface()
Dim TransKey as DDCOLORKEY
'DirectDraw Surface Initalization
TransKey.High=vbBlack 'Set the transparency range
TransKey.Low=vbBlack 'Only black is being used here
PictureOffScreenSurface.SetColorKey DDCKEY_SRCBLT, TransKey 'Attach the color key to the surface
End Sub
Public Sub Blt()
'Normal Blt code
Backbuffer.Blt RECT1, PictureOffScreenSurface, RECT2, DDBLT_WAIT Or DDBLT_KEYSRC 'Copy the back to the front and perform make trasparent
End Sub
ochensati
05-31-2002, 08:57 AM
Yes I found that in Lucky's vb gaming site, but I need to do two masks to make it work.
I have
Public Sub TransparentBlt(dest As DirectDrawSurface7, DestRect As RECT, Src As DirectDrawSurface7, SourceRect As RECT, code As Long)
Dim Ckey As DDCOLORKEY
Ckey.high =vbWhite
Ckey.low = vbWhite
Mask1.SetColorKey DDCKEY_SRCBLT, Ckey
Work.Blt DestRect, Src, SourceRect, DDBLT_WAIT
Work.Blt DestRect, Mask1, DestRect, DDBLT_KEYSRC Or DDBLT_WAIT
Ckey.high = vbBlack
Ckey.low = vbBlack
Work.SetColorKey DDCKEY_SRCBLT, Ckey
primary.Blt DestRect, Work, DestRect, DDBLT_KEYSRC Or DDBLT_WAIT
End Sub
The first masks out the area of the wall that I need gone and the second blts the first onto the wall, but the problem is that i cannot get the white to be transparent. Does directx only allow black to be transparent?
ochensati
05-31-2002, 09:12 AM
I have figured out this
Public Sub Transparentblt(dest As DirectDrawSurface7 _
, DestRect As RECT, Src As DirectDrawSurface7, SourceRect As RECT _
, code As Long)
Dim workdc As Long, mask1dc As Long
dim mask2dc As Long, destdc As Long, srcdc As Long
Dim dwidth As Long, dheight As Long
Dim swidth As Long, sheight As Long
With DestRect
dwidth = Abs(.Right - .Left)
dheight = Abs(.top - .Bottom)
End With
With SourceRect
swidth = Abs(.Right - .Left)
sheight = Abs(.top - .Bottom)
End With
workdc = Work.GetDC
mask1dc = Mask1.GetDC
mask2dc = Mask2.GetDC
destdc = dest.GetDC
srcdc = Src.GetDC
StretchBlt workdc, DestRect.Left, DestRect.top, dwidth, dheight, _
srcdc, SourceRect.Left, SourceRect.top, swidth, sheight, vbSrcCopy
BitBlt workdc, DestRect.Left, DestRect.top, dwidth, dheight, _
mask1dc, DestRect.Left, DestRect.top, vbSrcAnd
BitBlt destdc, DestRect.Left, DestRect.top, dwidth, dheight, _
mask2dc, DestRect.Left, DestRect.top, vbSrcAnd
BitBlt destdc, DestRect.Left, DestRect.top, dwidth, dheight, _
workdc, DestRect.Left, DestRect.top, vbSrcPaint
Src.ReleaseDC srcdc
dest.ReleaseDC destdc
Mask2.ReleaseDC mask2dc
Mask1.ReleaseDC mask1dc
Work.ReleaseDC workdc
End Sub
which works, but I still would like to keep it in directdraw since this only requires 3 blts instead of 4.
Please use [/code] instead of [\code] to end your code blocks.