Blue Rose
یک شنبه 22 دی 1387, 14:08 عصر
سلام اين يه برنامه ساده است که قراره به کمک دايرکت ايکس نسخه 8 يه شکل 2 بعدي بسازه
اما توي رندر تصاوير خط سوم آرگومان سوم خطا پيدا کرده
که TLVERTEX رو نميتونه به system.intptr تبديل کنه
البته اين کد بروز شده از وي بي 6 بوده و کار ميکرده و الان دارم توي وي بي 2005 اجراش ميکنم و کار نميکنه
اولاش توي (Structure TLVERTEX) خطا ميداد که درستش کردم
'Add Dx8vb.dll - C:\Windows\System32\dx8vb.dll
Imports DxVBLibA
Public Class Form1
Dim dx As DirectX8
Dim D3D As Direct3D8
Dim D3Dd As Direct3DDevice8
Dim bRun As Boolean
Dim D3Dx As D3DX8
Const FVF = CONST_D3DFVFFLAGS.D3DFVF_XYZRHW Or CONST_D3DFVFFLAGS.D3DFVF_TEX1 Or CONST_D3DFVFFLAGS.D3DFVF_DIFFUSE Or CONST_D3DFVFFLAGS.D3DFVF_SPECULAR
Dim TriStrip(0 To 3) As TLVERTEX
Public Structure TLVERTEX
Dim X As Single
Dim Y As Single
Dim Z As Single
Dim rhw As Single
Dim color As Long
Dim specular As Long
Dim tu As Single
Dim tv As Single
End Structure
Public Function Init() As Boolean
On Error GoTo Err
Dim d3dWin As D3DPRESENT_PARAMETERS
Dim DispMode As D3DDISPLAYMODE
dx = New DirectX8
D3Dx = New D3DX8
D3D = dx.Direct3DCreate
D3D.GetAdapterDisplayMode(CONST_D3DCONST.D3DADAPTE R_DEFAULT, DispMode)
'Show In Window Mode
d3dWin.Windowed = 1
d3dWin.SwapEffect = CONST_D3DSWAPEFFECT.D3DSWAPEFFECT_COPY_VSYNC
d3dWin.BackBufferFormat = DispMode.Format
'Show In FullScreen Mode
'd3dWin.SwapEffect = CONST_D3DSWAPEFFECT.D3DSWAPEFFECT_DISCARD
'd3dWin.BackBufferCount = 1
'd3dWin.BackBufferFormat = DispMode.Format
'd3dWin.BackBufferHeight = DispMode.Height
'd3dWin.BackBufferWidth = DispMode.Width
'd3dWin.hDeviceWindow = Me.Handle
D3Dd = D3D.CreateDevice(CONST_D3DCONST.D3DADAPTER_DEFAULT , CONST_D3DDEVTYPE.D3DDEVTYPE_HAL, Me.Handle, CONST_D3DCREATEFLAGS.D3DCREATE_SOFTWARE_VERTEXPROC ESSING, d3dWin)
D3Dd.SetVertexShader(FVF)
D3Dd.SetRenderState(CONST_D3DRENDERSTATETYPE.D3DRS _LIGHTING, False)
If InitG() = True Then
Init = True
Exit Function
End If
Exit Function
Err:
MsgBox("Init")
Init = False
End Function
Public Function InitG() As Boolean
On Error GoTo Err
TriStrip(0) = CreateTLVertex(100, 100, 0, 1, RGB(255, 255, 255), 0, 0, 0)
TriStrip(1) = CreateTLVertex(300, 100, 0, 1, RGB(255, 0, 0), 0, 0, 0)
TriStrip(2) = CreateTLVertex(100, 300, 0, 1, RGB(0, 255, 0), 0, 0, 0)
TriStrip(3) = CreateTLVertex(300, 300, 0, 1, RGB(0, 0, 255), 0, 0, 0)
InitG = True
Exit Function
Err:
MsgBox("InitG")
InitG = False
End Function
Public Function CreateTLVertex(ByVal x As Single, ByVal y As Single, ByVal z As Single, ByVal rhw As Single, ByVal color As Long, ByVal specular As Long, ByVal tu As Single, ByVal tv As Single) As TLVERTEX
CreateTLVertex.X = x
CreateTLVertex.Y = y
CreateTLVertex.Z = z
CreateTLVertex.tu = tu
CreateTLVertex.tv = tv
CreateTLVertex.specular = specular
CreateTLVertex.rhw = rhw
CreateTLVertex.color = color
End Function
Public Sub Render()
D3Dd.Clear(0, 0, CONST_D3DCLEARFLAGS.D3DCLEAR_TARGET, 0, 1.0#, 0)
D3Dd.BeginScene()
D3Dd.DrawPrimitiveUP(CONST_D3DPRIMITIVETYPE.D3DPT_ TRIANGLESTRIP, 2, TriStrip(0), Len(TriStrip(0)))
D3Dd.EndScene()
D3Dd.Present(0, 0, 0, 0)
End Sub
#Region "Form"
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
e.Cancel = True
bRun = False
End Sub
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
bRun = False
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Show() : Me.Focus()
bRun = Init()
Do Until bRun = False
System.Windows.Forms.Application.DoEvents()
Render()
Loop
dx = Nothing
D3D = Nothing
D3Dd = Nothing
End
End Sub
#End Region
End Class
ممنون که تا اینجاش اومدید و ممنون اگر کمک میکنید
اما توي رندر تصاوير خط سوم آرگومان سوم خطا پيدا کرده
که TLVERTEX رو نميتونه به system.intptr تبديل کنه
البته اين کد بروز شده از وي بي 6 بوده و کار ميکرده و الان دارم توي وي بي 2005 اجراش ميکنم و کار نميکنه
اولاش توي (Structure TLVERTEX) خطا ميداد که درستش کردم
'Add Dx8vb.dll - C:\Windows\System32\dx8vb.dll
Imports DxVBLibA
Public Class Form1
Dim dx As DirectX8
Dim D3D As Direct3D8
Dim D3Dd As Direct3DDevice8
Dim bRun As Boolean
Dim D3Dx As D3DX8
Const FVF = CONST_D3DFVFFLAGS.D3DFVF_XYZRHW Or CONST_D3DFVFFLAGS.D3DFVF_TEX1 Or CONST_D3DFVFFLAGS.D3DFVF_DIFFUSE Or CONST_D3DFVFFLAGS.D3DFVF_SPECULAR
Dim TriStrip(0 To 3) As TLVERTEX
Public Structure TLVERTEX
Dim X As Single
Dim Y As Single
Dim Z As Single
Dim rhw As Single
Dim color As Long
Dim specular As Long
Dim tu As Single
Dim tv As Single
End Structure
Public Function Init() As Boolean
On Error GoTo Err
Dim d3dWin As D3DPRESENT_PARAMETERS
Dim DispMode As D3DDISPLAYMODE
dx = New DirectX8
D3Dx = New D3DX8
D3D = dx.Direct3DCreate
D3D.GetAdapterDisplayMode(CONST_D3DCONST.D3DADAPTE R_DEFAULT, DispMode)
'Show In Window Mode
d3dWin.Windowed = 1
d3dWin.SwapEffect = CONST_D3DSWAPEFFECT.D3DSWAPEFFECT_COPY_VSYNC
d3dWin.BackBufferFormat = DispMode.Format
'Show In FullScreen Mode
'd3dWin.SwapEffect = CONST_D3DSWAPEFFECT.D3DSWAPEFFECT_DISCARD
'd3dWin.BackBufferCount = 1
'd3dWin.BackBufferFormat = DispMode.Format
'd3dWin.BackBufferHeight = DispMode.Height
'd3dWin.BackBufferWidth = DispMode.Width
'd3dWin.hDeviceWindow = Me.Handle
D3Dd = D3D.CreateDevice(CONST_D3DCONST.D3DADAPTER_DEFAULT , CONST_D3DDEVTYPE.D3DDEVTYPE_HAL, Me.Handle, CONST_D3DCREATEFLAGS.D3DCREATE_SOFTWARE_VERTEXPROC ESSING, d3dWin)
D3Dd.SetVertexShader(FVF)
D3Dd.SetRenderState(CONST_D3DRENDERSTATETYPE.D3DRS _LIGHTING, False)
If InitG() = True Then
Init = True
Exit Function
End If
Exit Function
Err:
MsgBox("Init")
Init = False
End Function
Public Function InitG() As Boolean
On Error GoTo Err
TriStrip(0) = CreateTLVertex(100, 100, 0, 1, RGB(255, 255, 255), 0, 0, 0)
TriStrip(1) = CreateTLVertex(300, 100, 0, 1, RGB(255, 0, 0), 0, 0, 0)
TriStrip(2) = CreateTLVertex(100, 300, 0, 1, RGB(0, 255, 0), 0, 0, 0)
TriStrip(3) = CreateTLVertex(300, 300, 0, 1, RGB(0, 0, 255), 0, 0, 0)
InitG = True
Exit Function
Err:
MsgBox("InitG")
InitG = False
End Function
Public Function CreateTLVertex(ByVal x As Single, ByVal y As Single, ByVal z As Single, ByVal rhw As Single, ByVal color As Long, ByVal specular As Long, ByVal tu As Single, ByVal tv As Single) As TLVERTEX
CreateTLVertex.X = x
CreateTLVertex.Y = y
CreateTLVertex.Z = z
CreateTLVertex.tu = tu
CreateTLVertex.tv = tv
CreateTLVertex.specular = specular
CreateTLVertex.rhw = rhw
CreateTLVertex.color = color
End Function
Public Sub Render()
D3Dd.Clear(0, 0, CONST_D3DCLEARFLAGS.D3DCLEAR_TARGET, 0, 1.0#, 0)
D3Dd.BeginScene()
D3Dd.DrawPrimitiveUP(CONST_D3DPRIMITIVETYPE.D3DPT_ TRIANGLESTRIP, 2, TriStrip(0), Len(TriStrip(0)))
D3Dd.EndScene()
D3Dd.Present(0, 0, 0, 0)
End Sub
#Region "Form"
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
e.Cancel = True
bRun = False
End Sub
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
bRun = False
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.Show() : Me.Focus()
bRun = Init()
Do Until bRun = False
System.Windows.Forms.Application.DoEvents()
Render()
Loop
dx = Nothing
D3D = Nothing
D3Dd = Nothing
End
End Sub
#End Region
End Class
ممنون که تا اینجاش اومدید و ممنون اگر کمک میکنید