VB Code:
Dim DX As DirectX8
'Dimensioning a new object, how exciting!
Dim D3DX As D3DX8
Dim D3D As Direct3D8
Dim D3DDevice As Direct3DDevice8
Const MyFVF = D3DFVF_XYZRHW Or D3DFVF_DIFFUSE Or D3DFVF_TEX1 Or D3DFVF_SPECULAR
Private Type VERTEX
X As Single
Y As Single
Z As Single
RHW As Single
Color As Long
Specular As Long
TU As Single
TV As Single
End Type
'Dimentioning variables...INCLUDING my new texturevariable!
Dim MTexture As Direct3DTexture8
Dim Square(0 To 3) As VERTEX
Dim Square2(0 To 3) As VERTEX
Dim bStop As Boolean
Private Sub Form_Click()
bStop = True
End Sub
Private Sub Form_Load()
Set DX = New DirectX8
'Here is a whole new object. Guess I need it...
Set D3DX = New D3DX8
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.BackBufferFormat = DisplayMode.Format
D3DPP.BackBufferWidth = 640
D3DPP.BackBufferHeight = 480
D3DPP.hDeviceWindow = Form1.hWnd
Set D3DDevice = D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Form1.hWnd, _
D3DCREATE_SOFTWARE_VERTEXPROCESSING, D3DPP)
D3DDevice.SetRenderState D3DRS_LIGHTING, False
D3DDevice.SetVertexShader MyFVF
'Here is some added code to load the texture
Set MTexture = D3DX.CreateTextureFromFile(D3DDevice, App.Path & "\ExampleTexture.bmp")
End Sub
Sub Render()
D3DDevice.Clear 0, ByVal 0, D3DCLEAR_TARGET, 0, 1#, 0
D3DDevice.BeginScene
'Here is some added code to use the texture
D3DDevice.SetTexture 0, MTexture
D3DDevice.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Square(0), Len(Square(0))
D3DDevice.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, Square2(0), Len(Square2(0))
D3DDevice.EndScene
D3DDevice.Present ByVal 0, ByVal 0, 0, ByVal 0
End Sub
Sub CreateGeometry()
'My nice square that shows up, but without textures
Square(0) = CrtVertex(10, 10, 0, 1, RGB(255, 255, 255), 0, 0, 0)
Square(1) = CrtVertex(210, 10, 0, 1, RGB(255, 255, 255), 0, 1, 0)
Square(2) = CrtVertex(10, 210, 0, 1, RGB(255, 255, 255), 0, 0, 1)
Square(3) = CrtVertex(210, 210, 0, 1, RGB(255, 255, 255), 0, 1, 1)
'Here is another square. It's there, but it's not textured..
Square2(0) = CrtVertex(210, 10, 0, 1, RGB(255, 255, 255), 0, 0, 0)
Square2(1) = CrtVertex(420, 10, 0, 1, RGB(255, 0, 0), 0, 1, 0)
Square2(2) = CrtVertex(210, 210, 0, 1, RGB(255, 0, 255), 0, 0, 1)
Square2(3) = CrtVertex(420, 210, 0, 1, RGB(0, 255, 255), 0, 1, 1)
End Sub
Private Function CrtVertex(X As Single, Y As Single, Z As Single, RHW As Single, Color As Long, _
Specular As Long, TU As Single, TV As Single) As VERTEX
CrtVertex.X = X
CrtVertex.Y = Y
CrtVertex.Z = Z
CrtVertex.Color = Color
CrtVertex.Specular = Specular
CrtVertex.TU = TU
CrtVertex.TV = TV
End Function