|
|
发表于 2005-9-7 10:15:00
|
显示全部楼层
Re:DX7下如何实现半透明?
'//* ************************************************************************
'//* * (iWidthZoom)只管缩放宽,(iHeightZoom)只管缩放高) , False, *
'//* * 32,(显示一部分) 64,裁减 X 坐标 ,裁减 Y 坐标, (iWidthZoom)缩放宽, *
'//* * iLeft 相当于 X iTop 相当于 Y *
'//* * 在用放大时 要 把 iExsitWidth - 1,iExsitHeight - 1 *
'//* * iExsitWidth 精灵图显示的宽度,iExsitHeight 精灵图显示的高度 *
'//* * nAngle 为旋转角度 *
'//* * iCutLeft 从左裁减值 ,iCutTop 从上裁减值 *
'//* ************************************************************************
Sub DisplaySurface_2D0(DDSurface As My_Surface, _
Optional ByVal iLeft As Integer, Optional ByVal iTop As Integer, _
Optional ByVal iExsitWidth As Integer, Optional ByVal iExsitHeight As Integer, _
Optional ByVal iCutLeft As Single, Optional ByVal iCutTop As Single, _
Optional ByVal iWidthZoom As Integer, Optional ByVal iHeightZoom As Integer, _
Optional ByVal tABOne As Byte, Optional ByVal nAlpha As Single = 1, _
Optional ByVal nRed As Single = 1, Optional ByVal nGreen As Single = 1, Optional ByVal nBlue As Single = 1, _
Optional ByVal nAngle As Single = 0) 'Angle 角度
'//* nAlpha 取值范围 (0、0.1 至 1) 值 1 和 1000 好相一样,(0.0 和 0.001 一样)
'//* ************************ Revise_0 (修改) 区域修正 *********************
If DDSurface.iWidth + iLeft < gE_ScreenRevise_A.scrLeft Then Exit Sub '//* 大了不调用 (应该是<=0)
If iLeft > gE_ScreenRevise_A.scrRight Then Exit Sub
If iTop > gE_ScreenRevise_A.scrHeight Then Exit Sub
If DDSurface.iHeight + iTop < gE_ScreenRevise_A.scrTop Then Exit Sub '//* (应该是<=0)
On Error GoTo ErrOut20
'//* No scaling info. is given, so assume source and dest. sizes are equal
If iExsitWidth = 0 Then iExsitWidth = DDSurface.iWidth
If iExsitHeight = 0 Then iExsitHeight = DDSurface.iHeight
If iWidthZoom = 0 Then iWidthZoom = iExsitWidth
If iHeightZoom = 0 Then iHeightZoom = iExsitHeight
'//* If this is a D3D surface (These surfaces need to be square, power of 2 sized)
Dim srcRect As RECT
Dim destRect As RECT
Dim TempVerts(3) As D3DTLVERTEX
'//* 建立目的站长方形
' If HeightZoom > SrcHeight Then SrcHeight = SrcHeight - 1
' If WidthZoom > SrcWidth Then SrcWidth = SrcWidth - 1
With srcRect
.Left = iCutLeft
.Top = iCutTop
.Right = iCutLeft + iExsitWidth '
.Bottom = iCutTop + iExsitHeight '//* 原来的
End With
'//* 建立源长方形
With destRect
.Left = iLeft
.Top = iTop
.Bottom = iTop + iHeightZoom '
.Right = iLeft + iWidthZoom '
End With
'//* Set up the TempVerts(3) vertices
SetUpGeom TempVerts, DDSurface, srcRect, destRect, nRed, nGreen, nBlue, nAlpha, nAngle
Dev.SetRenderState D3DRENDERSTATE_ALPHABLENDENABLE, True 'Enable alpha-blending
'//* Enable color-keying (ColorKey is drawn transparent)
Dev.SetRenderState D3DRENDERSTATE_COLORKEYENABLE, True
'//* 不明什么意思
'Dev.SetRenderState D3DRENDERSTATE_COLORKEYBLENDENABLE, True
If tABOne = True Then 'Use Alpha Blend One alpha blending
Dev.SetRenderState D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE
Dev.SetRenderState D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE
Else '//* Alpha blend to a certain fade value (0 - 1)
Dev.SetRenderState D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA
Dev.SetRenderState D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA
Dev.SetRenderState D3DRENDERSTATE_TEXTUREFACTOR, dx.CreateColorRGBA(1, 1, 1, nAlpha)
Dev.SetTextureStageState 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE 'D3DTA_TFACTOR
End If '//* Set the texture on the D3D device
Dev.SetTexture 0, DDSurface.DDSface7
' Dev.SetTextureStageState 0, D3D_TEXTURESTAGE_STATETYPE, 3 '//* D3DTSS_MIPFILTER '//* 基于 DrawPrimitive 的渲染功能
Dev.DrawPrimitive D3DPT_TRIANGLESTRIP, D3DFVF_TLVERTEX, TempVerts(0), 4, D3DDP_DEFAULT Or D3DDP_WAIT
Dev.SetRenderState D3DRENDERSTATE_ALPHABLENDENABLE, False
Dev.SetTexture 0, Nothing
Exit Sub
ErrOut20:
Call Err_Msg_Log.AT_Error_Run("DisplaySurface_2D0 调用错误:" & Err.Number, Err.Number)
Exit Sub
End Sub
'//* ************************************************************************
'//* * (iWidthZoom)只管缩放宽,(iHeightZoom)只管缩放高) , False, *
'//* * 32,(显示一部分) 64,裁减 X 坐标 ,裁减 Y 坐标, (iWidthZoom)缩放宽, *
'//* * iLeft 相当于 X iTop 相当于 Y *
'//* * 在用放大时 要 把 iExsitWidth - 1,iExsitHeight - 1 *
'//* * iExsitWidth 精灵图显示的宽度,iExsitHeight 精灵图显示的高度 *
'//* * nAngle 为旋转角度 *
'//* * iCutLeft 从左裁减值 ,iCutTop 从上裁减值 *
'//* * Revise(修改) 区域修正 (小于 Revise_0 ) *
'//* ************************************************************************
Sub DisplaySurface_2D1(DDSurface As My_Surface, _
Optional ByVal iLeft As Integer, Optional ByVal iTop As Integer, _
Optional ByVal iExsitWidth As Integer, Optional ByVal iExsitHeight As Integer, _
Optional ByVal iCutLeft As Single, Optional ByVal iCutTop As Single, _
Optional ByVal iWidthZoom As Integer, Optional ByVal iHeightZoom As Integer, _
Optional ByVal tABOne As Byte, Optional ByVal nAlpha As Single = 1, _
Optional ByVal nRed As Single = 1, Optional ByVal nGreen As Single = 1, Optional ByVal nBlue As Single = 1, _
Optional ByVal nAngle As Single = 0) 'Angle 角度
'//* nAlpha 取值范围 (0、0.1 至 1) 值 1 和 1000 好相一样,(0.0 和 0.001 一样)
'//* ************************ Revise(修改) 区域修正 *********************
If DDSurface.iWidth + iLeft < gE_ScreenRevise_B.scrLeft Then Exit Sub '//* 大了不调用 (应该是<=30)
If iLeft > gE_ScreenRevise_B.scrRight Then Exit Sub
If iTop > gE_ScreenRevise_B.scrHeight Then Exit Sub
If DDSurface.iHeight + iTop < gE_ScreenRevise_B.scrTop Then Exit Sub '//* (应该是<=30)
On Error GoTo ErrOut21
'//* No scaling info. is given, so assume source and dest. sizes are equal
If iExsitWidth = 0 Then iExsitWidth = DDSurface.iWidth
If iExsitHeight = 0 Then iExsitHeight = DDSurface.iHeight
If iWidthZoom = 0 Then iWidthZoom = iExsitWidth
If iHeightZoom = 0 Then iHeightZoom = iExsitHeight
'//* If this is a D3D surface (These surfaces need to be square, power of 2 sized)
Dim srcRect As RECT
Dim destRect As RECT
Dim TempVerts(3) As D3DTLVERTEX
'//* 建立目的站长方形
' If HeightZoom > SrcHeight Then SrcHeight = SrcHeight - 1
' If WidthZoom > SrcWidth Then SrcWidth = SrcWidth - 1
With srcRect
.Left = iCutLeft
.Top = iCutTop
.Right = iCutLeft + iExsitWidth '
.Bottom = iCutTop + iExsitHeight '//* 原来的
End With
'//* 建立源长方形
With destRect
.Left = iLeft
.Top = iTop
.Bottom = iTop + iHeightZoom '
.Right = iLeft + iWidthZoom '
End With
'//* Set up the TempVerts(3) vertices
SetUpGeom TempVerts, DDSurface, srcRect, destRect, nRed, nGreen, nBlue, nAlpha, nAngle
Dev.SetRenderState D3DRENDERSTATE_ALPHABLENDENABLE, True 'Enable alpha-blending
Dev.SetRenderState D3DRENDERSTATE_COLORKEYENABLE, True
'Dev.SetRenderState D3DRENDERSTATE_COLORKEYBLENDENABLE, True
If tABOne = True Then
Dev.SetRenderState D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE
Dev.SetRenderState D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE
Else '//* Alpha blend to a certain fade value (0 - 1)
Dev.SetRenderState D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA
Dev.SetRenderState D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA
Dev.SetRenderState D3DRENDERSTATE_TEXTUREFACTOR, dx.CreateColorRGBA(1, 1, 1, nAlpha)
Dev.SetTextureStageState 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE 'D3DTA_TFACTOR
End If '//* Set the texture on the D3D device
Dev.SetTexture 0, DDSurface.DDSface7
' Dev.SetTextureStageState 0, D3D_TEXTURESTAGE_STATETYPE, 3 '//* D3DTSS_MIPFILTER '//* 基于 DrawPrimitive 的渲染功能
Dev.DrawPrimitive D3DPT_TRIANGLESTRIP, D3DFVF_TLVERTEX, TempVerts(0), 4, D3DDP_DEFAULT Or D3DDP_WAIT
Dev.SetRenderState D3DRENDERSTATE_ALPHABLENDENABLE, False
Dev.SetTexture 0, Nothing
Exit Sub
ErrOut21:
Call Err_Msg_Log.AT_Error_Run("DisplaySurface_2D1 调用错误:" & Err.Number, Err.Number)
Exit Sub
End Sub |
|