VB Code:
Dim DX As New DirectX8
Dim D3D As Direct3D8
Dim D3DDevice As Direct3DDevice8
Private Const MyFVF = D3DFVF_XYZ Or D3DFVF_DIFFUSE
Private Type VERTEX
X As Single
Y As Single
Z As Single
Color As Long
End Type
Dim Trekant(0 To 2) As D3DVERTEX 'VERTEX
Dim bStop As Boolean
Private Sub Form_Click()
bStop = True
End Sub
Private Sub Form_Load()
Set DX = New DirectX8
Set D3D = DX.Direct3DCreate
Call Initialize
Call CreateGeometry
Do Until bStop = True
Render
DoEvents
Loop
Unload Me
End
End Sub
Sub Initialize()
Dim DisplayMode As D3DDISPLAYMODE
Dim D3DPP As D3DPRESENT_PARAMETERS
DisplayMode.Format = D3DFMT_R5G6B5
DisplayMode.Width = 640
DisplayMode.Height = 480
D3DPP.SwapEffect = D3DSWAPEFFECT_FLIP
D3DPP.BackBufferCount = 1
D3DPP.BackBufferWidth = 640
D3DPP.BackBufferHeight = 480
D3DPP.BackBufferFormat = DisplayMode.Format
D3DPP.hDeviceWindow = Form1.hWnd
Set D3DDevice = D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Form1.hWnd, _
D3DCREATE_SOFTWARE_VERTEXPROCESSING, D3DPP)
D3DDevice.SetRenderState D3DRS_LIGHTING Or D3DRS_CULLMODE, False Or D3DCULL_NONE
D3DDevice.SetVertexShader MyFVF
End Sub
Sub Render()
D3DDevice.Clear 0, ByVal 0, D3DCLEAR_TARGET, 0, 1#, 0
D3DDevice.BeginScene
D3DDevice.DrawPrimitiveUP D3DPT_TRIANGLELIST, 1, Trekant(0), Len(Trekant(0))
D3DDevice.EndScene
D3DDevice.Present ByVal 0, ByVal 0, 0, ByVal 0
End Sub
Sub CreateGeometry()
Trekant(0) = CrtVertex(10, 10, 0, RGB(255, 0, 0))
Trekant(1) = CrtVertex(10, 200, 0, RGB(255, 0, 0))
Trekant(2) = CrtVertex(200, 10, 0, RGB(255, 0, 0))
End Sub
Private Function CrtVertex(X As Single, Y As Single, Z As Single, Color As Long) As VERTEX
CrtVertex.X = X
CrtVertex.Y = Y
CrtVertex.Z = Z
CrtVertex.Color = Color
End Function