|
|

楼主 |
发表于 2007-12-30 17:56:00
|
显示全部楼层
Re:用DX8如何在画文字时只画文字的一部分
问题解决了:
Public Type POINTAPI
x As Long
y As Long
End Type
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long
Public getpos As POINTAPI
Public DX As DirectX8
Public D3D As Direct3D8
Public D3DDevice As Direct3DDevice8
Public d3dx As D3DX8
Public Sprite As D3DXSprite
Public Running As Boolean
Public Tex As Direct3DTexture8
Public TexSurbf As Direct3DSurface8
Public nColorKey As Long
Public Rect1 As RECT
Public Scal As D3DVECTOR2
Public Rotation As Single
Public Center As D3DVECTOR2
Public Tran As D3DVECTOR2
Public Color As Long
Public DI As DirectInput8
Public DIDEV As DirectInputDevice8
Public DIDEV1 As DirectInputDevice8
Public DIState As DIKEYBOARDSTATE
Public DIMouse As DIMOUSESTATE
Public mousex As Single, mousey As Single
Public DXFont As D3DXFont
Public mlngTimer As Long
Public mlngFrameTimer As Long
Public mintFPS As Long
Public mintFPSCounter As Long
Public TexDesc(1) As D3DXIMAGE_INFO
Public useTexDesc(1) As D3DXIMAGE_INFO
Sub main()
Running = True
Set DX = New DirectX8
Set D3D = DX.Direct3DCreate
Dim Dpp1 As D3DPRESENT_PARAMETERS
Dpp1.SwapEffect = D3DSWAPEFFECT_DISCARD
Dpp1.BackBufferWidth = 800
Dpp1.BackBufferHeight = 600
Dpp1.BackBufferFormat = D3DFMT_A8R8G8B8
Set D3DDevice = D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Form1.hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, Dpp1)
Set d3dx = New D3DX8
Set Sprite = d3dx.CreateSprite(D3DDevice)
Set DI = DX.DirectInputCreate()
Set DIDEV = DI.CreateDevice("GUID_SysKeyboard")
DIDEV.SetCommonDataFormat DIFORMAT_KEYBOARD
DIDEV.SetCooperativeLevel Form1.hWnd, DISCL_BACKGROUND Or DISCL_NONEXCLUSIVE
DIDEV.Acquire
Set DIDEV1 = DI.CreateDevice("GUID_SysMouse")
DIDEV1.SetCommonDataFormat DIFORMAT_MOUSE
DIDEV1.SetCooperativeLevel Form1.hWnd, DISCL_BACKGROUND Or DISCL_NONEXCLUSIVE
DIDEV1.Acquire
Set Tex = d3dx.CreateTexture(D3DDevice, 200, 200, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT)
Set TexSurbf = D3DDevice.GetRenderTarget
Dim m_vbFont As IFont
Dim x As New StdFont
x.Name = "宋体"
x.Bold = False
x.Italic = False
x.Underline = False
x.Size = 20
Set m_vbFont = x
Set DXFont = d3dx.CreateFont(D3DDevice, m_vbFont.hFont)
Do While Running = True
DIDEV.GetDeviceStateKeyboard DIState
If DIState.Key(DIK_ESCAPE) Then End
DIDEV1.GetDeviceStateMouse DIMouse
If DIMouse.Buttons(0) And DIMouse.Buttons(1) Then End
mlngTimer = GetTickCount()
If GetTickCount() - mlngFrameTimer >= 1000 Then
mintFPS = mintFPSCounter + 1
mintFPSCounter = 0
mlngFrameTimer = GetTickCount()
Else
mintFPSCounter = mintFPSCounter + 1
End If
D3DDevice.SetRenderTarget Tex.GetSurfaceLevel(0), Nothing, ByVal 0
D3DDevice.Clear 0, ByVal 0, D3DCLEAR_TARGET, 0, 0, 0
D3DDevice.BeginScene
Rect1.Left = 190
Rect1.Top = 190
Rect1.Right = 300
Rect1.bottom = 300
d3dx.DrawText DXFont, D3DColorRGBA(255, 255, 255, 255), mintFPS, Rect1, 0
D3DDevice.EndScene
D3DDevice.SetRenderTarget TexSurbf, Nothing, ByVal 0
D3DDevice.Clear 0, ByVal 0, D3DCLEAR_TARGET, 0, 0, 0
D3DDevice.BeginScene
Sprite.Begin
Tran.x = 100
Tran.y = 100
Rect1.Left = 0
Rect1.Right = 200
Rect1.Top = 0
Rect1.bottom = 200
Scal.x = 1
Scal.y = 1
Center.x = 0
Center.y = 0
Rotation = 0
Color = D3DColorRGBA(255, 255, 255, 255)
Sprite.Draw Tex, Rect1, Scal, Center, Rotation, Tran, Color
Sprite.End
D3DDevice.EndScene
D3DDevice.Present ByVal 0, ByVal 0, 0, ByVal 0
DoEvents
Loop
End Sub
|
|